|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Array of tags and corresponding spoken texts |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef TAGNAMESET_H |
|
21 #define TAGNAMESET_H |
|
22 |
|
23 #include "asyncworker.h" |
|
24 #include <nssvasmtraintexteventhandler.h> |
|
25 #include <nssvasmsavetagclient.h> |
|
26 #include <nssvasmdeletetagclient.h> |
|
27 |
|
28 class MNssTagMgr; |
|
29 class MNssTag; |
|
30 class CNssTrainingParameters; |
|
31 |
|
32 /** |
|
33 * Array of tags and corresponding spoken texts |
|
34 */ |
|
35 class CTagNameSet : public CAsyncWorker, public MNssTrainTextEventHandler, |
|
36 public MNssSaveTagClient, public MNssDeleteTagClient |
|
37 { |
|
38 public: |
|
39 static CTagNameSet* NewLC(); |
|
40 |
|
41 ~CTagNameSet(); |
|
42 |
|
43 /** |
|
44 * Adds a tag-text pair to be trained |
|
45 * @param aTag tag to be trained and saved. This objects takes ownership |
|
46 * on the aTag |
|
47 * @param aTrainingText text to be recognized. This object doesn't |
|
48 * take ownership on aTrainingText, but makes an own copy |
|
49 */ |
|
50 void AppendL( const MNssTag* aTag, const TDesC& aTrainingText = KNullDesC ); |
|
51 |
|
52 /** |
|
53 * Train and save to VAS all the stored tags. It is not specified what happens |
|
54 * to VAS if this method leaves |
|
55 * @param aParams |
|
56 * @param aTagMgr |
|
57 * @param aIgnoreErrors If ETrue, doesn't fail the whole operation if some |
|
58 * individual trainings/savings failed. Trains and saves as much as |
|
59 * possible |
|
60 */ |
|
61 void TrainAndSaveL( const CNssTrainingParameters& aParams, |
|
62 MNssTagMgr& aTagMgr, TBool aIgnoreErrors = EFalse); |
|
63 |
|
64 /** |
|
65 * Remove all the stored tags from VAS. It is not specified what happens |
|
66 * to VAS if this method leaves |
|
67 * @param aTagMgr |
|
68 * @param aIgnoreErrors If ETrue, doesn't fail the whole operation if some |
|
69 * individual removals failed. Removes as many tags as |
|
70 * possible |
|
71 */ |
|
72 void UntrainL( MNssTagMgr& aTagMgr, TBool aIgnoreErrors = EFalse ); |
|
73 |
|
74 /** |
|
75 * @return Number of tag-name pairs stored |
|
76 */ |
|
77 TInt Count() const; |
|
78 |
|
79 /** |
|
80 * @param aIndex must be >= 0 and < Count() |
|
81 * @return Voice tag at the given position |
|
82 * @panic KErrArgument if aIndex is out of bounds |
|
83 */ |
|
84 const MNssTag& TagAt( TInt aIndex ) const; |
|
85 |
|
86 /** |
|
87 * @param aIndex must be >= 0 and < Count() |
|
88 * @return Recognition text at the given position |
|
89 * @panic KErrArgument if aIndex is out of bounds |
|
90 */ |
|
91 const TDesC& TextAt( TInt aIndex ) const; |
|
92 |
|
93 public: |
|
94 |
|
95 // From MNssTrainTextEventHandler |
|
96 |
|
97 /** |
|
98 * Train Complete Event - Voice tag training completed |
|
99 * @param aErrorCode KErrNone if training was successfull |
|
100 */ |
|
101 void HandleTrainComplete( TInt aErrorCode ); |
|
102 |
|
103 public: |
|
104 |
|
105 // From MNssSaveTagClient |
|
106 |
|
107 /** |
|
108 * Callback to indicate that SaveTag sequence has been completed |
|
109 * @param aErrorCode KErrNone if saving of tag was successfull |
|
110 */ |
|
111 void SaveTagCompleted( TInt aErrorCode ); |
|
112 |
|
113 // From MNssDeleteTagClient |
|
114 |
|
115 /** |
|
116 * Callback to indicate a tag was deleted successfully. |
|
117 * @param aErrorCode KErrNone if deletion of tag was successfull |
|
118 */ |
|
119 virtual void DeleteTagCompleted( TInt aErrorCode ); |
|
120 |
|
121 |
|
122 private: |
|
123 |
|
124 /** |
|
125 * Train all the stored tag-name pairs. Synchronous |
|
126 */ |
|
127 void TrainTagsL( const CNssTrainingParameters& aParams ); |
|
128 |
|
129 /** |
|
130 * Trains the voice tag. Asynchronous |
|
131 * @leave VAS error codes |
|
132 */ |
|
133 void TrainTagL( const MNssTag& aTag, |
|
134 const CNssTrainingParameters& aParams, const TDesC& aSpokenText ); |
|
135 |
|
136 /** |
|
137 * Saves to VAS all the stored voice tags. Synchronous |
|
138 * All the voice tags must be previously trained |
|
139 */ |
|
140 void SaveTagsL( MNssTagMgr& aTagManager ); |
|
141 |
|
142 /** |
|
143 * Saves the trained voice tag to VAS. |
|
144 */ |
|
145 void SaveTagL( MNssTagMgr& aTagManager, const MNssTag& aTag ); |
|
146 |
|
147 /** |
|
148 * Deletes the voice tag from VAS. Asynchronous |
|
149 * @leave VAS error codes |
|
150 */ |
|
151 void DeleteTagL( MNssTagMgr& aTagManager, MNssTag& aTag ); |
|
152 |
|
153 /** |
|
154 * Handles the common part of the callback processing |
|
155 * Decrements the number of still expected callbacks and |
|
156 * handles the errors according to aIgnoreErrors from the |
|
157 * public methods |
|
158 */ |
|
159 void ProcessCallback( TInt aErrorCode ); |
|
160 |
|
161 /** |
|
162 * Sets the number of callbacks to expect |
|
163 */ |
|
164 void SetCallbacksExpected ( TUint aCallbacksExpected ); |
|
165 |
|
166 /** |
|
167 * Decreases the number of callbacks to expect by one |
|
168 * @return Number of callbacks expected after decreasing |
|
169 */ |
|
170 TUint DecreaseCallbacksExpected(); |
|
171 |
|
172 /** |
|
173 * Waits until all the expected callbacks are received |
|
174 * If no callbacks are expected returns immediately |
|
175 * @leave @see CAsyncWorker::WaitForAsyncCallbackL |
|
176 */ |
|
177 void WaitUntilOperationsAreCompletedL(); |
|
178 |
|
179 private: |
|
180 RPointerArray<MNssTag> iTags; |
|
181 RPointerArray<HBufC> iTexts; |
|
182 |
|
183 // Counter to count how many |
|
184 // callbacks are still expected |
|
185 TUint iCallbacksExpected; |
|
186 |
|
187 // Ignore individual train/save/remove errors |
|
188 TBool iIgnoreErrors; |
|
189 }; |
|
190 |
|
191 #endif // TAGNAMESET_H |