|
1 /* |
|
2 * Copyright (c) 2004 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: This file contains definition of the SISpeechRecognitionDataClient structure and API. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include "nsssispeechrecognitiondataclient.h" |
|
22 #include "nsssispeechrecognitiondatadevasr.h" |
|
23 #include "nsssispeechrecognitiondatatest.h" |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt32 KBinaryClientResultSetID = 0xAACF1235; |
|
27 |
|
28 // Does the CSIClientResultSet have an embedded CSIResultSet? |
|
29 const TInt KNoResultSet = 0; |
|
30 const TInt KYesResultSet = 1; |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CSIClientResult::~CSIClientResult |
|
34 // Destructor. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 EXPORT_C CSIClientResult::~CSIClientResult() |
|
38 { |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CSIClientResult::CSIClientResult |
|
43 // C++ default constructor can NOT contain any code, that |
|
44 // might leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CSIClientResult::CSIClientResult() |
|
48 : iGrammarID(0), |
|
49 iRuleID(0) |
|
50 { |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CSIClientResult::CSIClientResult |
|
55 // C++ default constructor can NOT contain any code, that |
|
56 // might leave. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CSIClientResult::CSIClientResult(TSIGrammarID aGrammarID, TSIRuleID aRuleID) |
|
60 : iGrammarID(aGrammarID), |
|
61 iRuleID(aRuleID) |
|
62 { |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSIClientResult::ConstructL |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CSIClientResult::ConstructL() |
|
71 { |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CSIClientResult::NewLC |
|
76 // Two-phased constructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C CSIClientResult* CSIClientResult::NewLC() |
|
80 { |
|
81 CSIClientResult* self = new (ELeave) CSIClientResult(); |
|
82 CleanupStack::PushL(self); |
|
83 self->ConstructL(); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CSIClientResult::NewL |
|
89 // Two-phased constructor. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C CSIClientResult* CSIClientResult::NewL() |
|
93 { |
|
94 CSIClientResult* self = NewLC(); |
|
95 CleanupStack::Pop(); |
|
96 return self; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CSIClientResult::NewLC |
|
101 // Two-phased constructor. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C CSIClientResult* CSIClientResult::NewLC(TSIGrammarID aGrammarID, TSIRuleID aRuleID) |
|
105 { |
|
106 CSIClientResult* self = new (ELeave) CSIClientResult(aGrammarID, aRuleID); |
|
107 CleanupStack::PushL(self); |
|
108 self->ConstructL(); |
|
109 return self; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CSIClientResult::NewL |
|
114 // Two-phased constructor. |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C CSIClientResult* CSIClientResult::NewL(TSIGrammarID aGrammarID, TSIRuleID aRuleID) |
|
118 { |
|
119 CSIClientResult* self = NewLC(aGrammarID, aRuleID); |
|
120 CleanupStack::Pop(); |
|
121 return self; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CSIClientResult::SetGrammarID |
|
126 // (other items were commented in the headers) |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 EXPORT_C void CSIClientResult::SetGrammarID(TSIGrammarID aGrammarID) |
|
130 { |
|
131 iGrammarID = aGrammarID; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CSIClientResult::GrammarID |
|
136 // (other items were commented in the headers) |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 EXPORT_C TSIGrammarID CSIClientResult::GrammarID() const |
|
140 { |
|
141 return iGrammarID; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CSIClientResult::SetRuleID |
|
146 // (other items were commented in the headers) |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C void CSIClientResult::SetRuleID(TSIRuleID aRuleID) |
|
150 { |
|
151 iRuleID = aRuleID; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CSIClientResult::RuleID |
|
156 // (other items were commented in the headers) |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 EXPORT_C TSIRuleID CSIClientResult::RuleID() const |
|
160 { |
|
161 return iRuleID; |
|
162 } |
|
163 |
|
164 /*****************************************************************************/ |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CSIClientResultSet::~CSIClientResultSet |
|
168 // Destructor. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 EXPORT_C CSIClientResultSet::~CSIClientResultSet() |
|
172 { |
|
173 iResultArray.ResetAndDestroy(); |
|
174 iResultArray.Close(); |
|
175 delete iSIResultSet; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CSIClientResultSet::CSIClientResultSet |
|
180 // C++ default constructor can NOT contain any code, that |
|
181 // might leave. |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 CSIClientResultSet::CSIClientResultSet() |
|
185 : iMaxResults(0), |
|
186 iResultCount(0), |
|
187 iResultArray(10), |
|
188 iSIResultSet(NULL) |
|
189 { |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CSIClientResultSet::ConstructL |
|
194 // Symbian 2nd phase constructor can leave. |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CSIClientResultSet::ConstructL() |
|
198 { |
|
199 iSIResultSet = CSIResultSet::NewL(); |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CSIClientResultSet::NewLC |
|
204 // Two-phased constructor. |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 EXPORT_C CSIClientResultSet* CSIClientResultSet::NewLC() |
|
208 { |
|
209 CSIClientResultSet* self = new (ELeave) CSIClientResultSet(); |
|
210 CleanupStack::PushL(self); |
|
211 self->ConstructL(); |
|
212 return self; |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CSIClientResultSet::NewL |
|
217 // Two-phased constructor. |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 EXPORT_C CSIClientResultSet* CSIClientResultSet::NewL() |
|
221 { |
|
222 CSIClientResultSet* self = NewLC(); |
|
223 CleanupStack::Pop(); |
|
224 return self; |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CSIClientResultSet::AddL |
|
229 // Adds a result to the set. |
|
230 // (other items were commented in the headers) |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C void CSIClientResultSet::AddL( const CSIClientResult* aResult) |
|
234 { |
|
235 if ( iResultArray.Count() >= iMaxResults ) |
|
236 { |
|
237 User::Leave( KErrOverflow ); |
|
238 } |
|
239 |
|
240 TInt error = iResultArray.Append(aResult); |
|
241 User::LeaveIfError( error ); |
|
242 } |
|
243 |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CSIClientResultSet::DeleteL |
|
247 // Removes a result from the set. |
|
248 // (other items were commented in the headers) |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 EXPORT_C void CSIClientResultSet::DeleteL(TInt aIndex) |
|
252 { |
|
253 if(aIndex<0 || aIndex >= iResultArray.Count()) |
|
254 User::Leave(KErrArgument); |
|
255 iResultArray.Remove(aIndex); |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CSIClientResultSet::SetMaxResultsL |
|
260 // Sets the maximum number of results, which the client wants get. |
|
261 // Less results may be returned for various reasons. |
|
262 // (other items were commented in the headers) |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 EXPORT_C void CSIClientResultSet::SetMaxResultsL(TInt aMaxResults) |
|
266 { |
|
267 iMaxResults = aMaxResults; |
|
268 |
|
269 while( iResultArray.Count() > iMaxResults ) |
|
270 { |
|
271 delete iResultArray[ iMaxResults ]; |
|
272 iResultArray.Remove( iMaxResults ); |
|
273 } |
|
274 /* |
|
275 for (TInt i = 0; i < aMaxResults; i++) |
|
276 { |
|
277 CSIClientResult* result = CSIClientResult::NewLC(); |
|
278 User::LeaveIfError(iResultArray.Append(result)); |
|
279 CleanupStack::Pop(); |
|
280 } |
|
281 */ |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CSIClientResultSet::MaxResults |
|
286 // Returns the maximum number of results. |
|
287 // (other items were commented in the headers) |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 EXPORT_C TInt CSIClientResultSet::MaxResults() const |
|
291 { |
|
292 return iMaxResults; |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CSIClientResultSet::AtL |
|
297 // Used to get a result. |
|
298 // (other items were commented in the headers) |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 EXPORT_C const CSIClientResult& CSIClientResultSet::AtL(TInt aIndex) const |
|
302 { |
|
303 |
|
304 if(aIndex<0 || aIndex >= iResultArray.Count()) |
|
305 User::Leave(KErrArgument); |
|
306 return *(iResultArray[aIndex]); |
|
307 } |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CSIClientResultSet::SetResultCount |
|
311 // Sets the actual number of results, as opposed to maximum number. |
|
312 // (other items were commented in the headers) |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 EXPORT_C void CSIClientResultSet::SetResultCount(TInt aResultCount) |
|
316 { |
|
317 iResultCount = aResultCount; |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CSIClientResultSet::ResultCount |
|
322 // Gets the actual number of results, which is smaller or equal to maximum number. |
|
323 // (other items were commented in the headers) |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 EXPORT_C TInt CSIClientResultSet::ResultCount() const |
|
327 { |
|
328 return iResultCount; |
|
329 } |
|
330 |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CSIClientResultSet::SIClientResultSet |
|
334 // Returns the nested lower-level result set. |
|
335 // (other items were commented in the headers) |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 EXPORT_C CSIResultSet& CSIClientResultSet::SIResultSet() const |
|
339 { |
|
340 return *iSIResultSet; |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CSIClientResultSet::SetSIResultSet |
|
345 // Sets the nested result set. |
|
346 // (other items were commented in the headers) |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 EXPORT_C void CSIClientResultSet::SetSIResultSet(CSIResultSet* aSIResultSet) |
|
350 { |
|
351 delete iSIResultSet; |
|
352 iSIResultSet = aSIResultSet; |
|
353 } |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CSIClientResultSet::ExternalizeL |
|
357 // Stores the object to the stream. |
|
358 // (other items were commented in the headers) |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 EXPORT_C void CSIClientResultSet::ExternalizeL( RWriteStream& aStream ) const |
|
362 { |
|
363 // Write format ID |
|
364 aStream.WriteInt32L( KBinaryClientResultSetID ); |
|
365 |
|
366 aStream.WriteInt32L( iMaxResults ); |
|
367 aStream.WriteInt32L( iResultCount ); |
|
368 |
|
369 TInt count = iResultArray.Count(); |
|
370 aStream.WriteInt32L( count ); |
|
371 |
|
372 for ( TInt k = 0; k < count; k++ ) |
|
373 { |
|
374 CSIClientResult* result = iResultArray[ k ]; |
|
375 |
|
376 aStream.WriteInt32L( result->GrammarID() ); |
|
377 aStream.WriteInt32L( result->RuleID() ); |
|
378 } |
|
379 |
|
380 if ( iSIResultSet == 0 ) |
|
381 { |
|
382 aStream.WriteInt32L( KNoResultSet ); |
|
383 } |
|
384 else |
|
385 { |
|
386 aStream.WriteInt32L( KYesResultSet ); |
|
387 |
|
388 iSIResultSet->ExternalizeL( aStream ); |
|
389 } |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CSIClientResultSet::InternalizeL |
|
394 // Restores the object from the stream. |
|
395 // (other items were commented in the headers) |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 EXPORT_C void CSIClientResultSet::InternalizeL( RReadStream& aStream ) |
|
399 { |
|
400 if ( aStream.ReadInt32L() != KBinaryClientResultSetID ) |
|
401 { |
|
402 User::Leave( KErrCorrupt ); |
|
403 } |
|
404 |
|
405 iMaxResults = aStream.ReadInt32L(); |
|
406 iResultCount= aStream.ReadInt32L(); |
|
407 |
|
408 TInt count = aStream.ReadInt32L(); |
|
409 |
|
410 for ( TInt k( 0 ); k < count; k++ ) |
|
411 { |
|
412 CSIClientResult* result = CSIClientResult::NewLC(); |
|
413 |
|
414 result->SetGrammarID( (TSIGrammarID)aStream.ReadInt32L() ); |
|
415 result->SetRuleID ( (TSIRuleID) aStream.ReadInt32L() ); |
|
416 |
|
417 AddL( result ); |
|
418 |
|
419 CleanupStack::Pop( result ); |
|
420 } |
|
421 |
|
422 TInt32 hasNestedResultSet = aStream.ReadInt32L(); |
|
423 |
|
424 if ( hasNestedResultSet == KYesResultSet ) |
|
425 { |
|
426 iSIResultSet->InternalizeL( aStream ); |
|
427 } |
|
428 |
|
429 } |
|
430 |
|
431 // End of File |