1 /* |
|
2 * Copyright (c) 2004-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: CNssContext class does all context processing. It implements |
|
15 * MNssContext interface. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "nssvasccontext.h" |
|
22 #include "rubydebug.h" |
|
23 |
|
24 |
|
25 // ================= MEMBER FUNCTIONS ======================= |
|
26 |
|
27 // --------------------------------------------------------- |
|
28 // CNssContext::CNssContext |
|
29 // C++ default constructor can NOT contain any code that |
|
30 // might leave. |
|
31 // --------------------------------------------------------- |
|
32 // |
|
33 CNssContext::CNssContext( CNssContextSrsPortal* aContextSrsPortal ) |
|
34 { |
|
35 // These take forever in strain test |
|
36 RUBY_DEBUG0( "CNssContext::CNssContext" ); |
|
37 |
|
38 iContextSrsPortal = aContextSrsPortal; |
|
39 iGlobal = EFalse; |
|
40 iContextId = KNssVASDbDefaultValue; |
|
41 iContextSrsPortal->Register(); |
|
42 iRecognitionMode = ENSSSdSiMode; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------- |
|
46 // CNssContext::~CNssContext |
|
47 // Destructor |
|
48 // --------------------------------------------------------- |
|
49 // |
|
50 CNssContext::~CNssContext() |
|
51 { |
|
52 // These take forever in strain test: |
|
53 // RUBY_DEBUG0( "CNssContext::~CNssContext" ); |
|
54 |
|
55 if ( iContextSrsPortal ) |
|
56 { |
|
57 iContextSrsPortal->Deregister(); |
|
58 } |
|
59 if ( iName ) |
|
60 { |
|
61 delete iName; |
|
62 } |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------- |
|
66 // CNssContext::ContextName |
|
67 // returns the name of the context as a reference |
|
68 // --------------------------------------------------------- |
|
69 // |
|
70 TDesC& CNssContext::ContextName() |
|
71 { |
|
72 return *iName; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // CNssContext::IsGlobal |
|
77 // returns the global flag |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 TBool CNssContext::IsGlobal() |
|
81 { |
|
82 return iGlobal; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // CNssContext::SetNameL |
|
87 // sets the name of the context to aName, |
|
88 // old name, if any is deleted. |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 void CNssContext::SetNameL( const TDesC& aName ) |
|
92 { |
|
93 if ( iName ) |
|
94 { |
|
95 delete iName; |
|
96 iName = NULL; |
|
97 } |
|
98 iName = aName.AllocL(); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------- |
|
102 // CNssContext::SetGlobal |
|
103 // sets the global flag to ETrue or EFalse |
|
104 // --------------------------------------------------------- |
|
105 // |
|
106 void CNssContext::SetGlobal( TBool aGlobal ) |
|
107 { |
|
108 iGlobal = aGlobal; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------- |
|
112 // CNssContext::ContextId |
|
113 // return the context id |
|
114 // for internal use |
|
115 // --------------------------------------------------------- |
|
116 // |
|
117 TInt CNssContext::ContextId() const |
|
118 { |
|
119 return iContextId; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------- |
|
123 // CNssContext::GrammarId |
|
124 // returns the grammar id |
|
125 // for internal use |
|
126 // --------------------------------------------------------- |
|
127 // |
|
128 TUint32 CNssContext::GrammarId() const |
|
129 { |
|
130 return iGrammarId; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------- |
|
134 // CNssContext::LexiconId |
|
135 // returns the lexicon id |
|
136 // for internal use |
|
137 // --------------------------------------------------------- |
|
138 // |
|
139 TUint32 CNssContext::LexiconId() const |
|
140 { |
|
141 return iLexiconId; |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CNssContext::ModelBankId |
|
146 // returns the model bank id |
|
147 // for internal use |
|
148 // --------------------------------------------------------- |
|
149 // |
|
150 TUint32 CNssContext::ModelBankId() const |
|
151 { |
|
152 return iModelBankId; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------- |
|
156 // CNssContext::RecognitionMode |
|
157 // returns the recognition technology |
|
158 // for internal use |
|
159 // --------------------------------------------------------- |
|
160 // |
|
161 TNSSRecognitionMode CNssContext::RecognitionMode() const |
|
162 { |
|
163 return iRecognitionMode; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------- |
|
167 // CNssContext::SetContextId |
|
168 // sets the context id to the given value |
|
169 // for internal use |
|
170 // --------------------------------------------------------- |
|
171 // |
|
172 void CNssContext::SetContextId( TInt aContextId ) |
|
173 { |
|
174 iContextId = aContextId; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------- |
|
178 // CNssContext::SetGrammarId |
|
179 // sets the grammar id to the given value |
|
180 // for internal use |
|
181 // --------------------------------------------------------- |
|
182 // |
|
183 void CNssContext::SetGrammarId( TUint32 aGrammarId ) |
|
184 { |
|
185 iGrammarId = aGrammarId; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // CNssContext::SetLexiconId |
|
190 // sets the lexicon id to the given value |
|
191 // for internal use |
|
192 // --------------------------------------------------------- |
|
193 // |
|
194 void CNssContext::SetLexiconId( TUint32 aLexiconId ) |
|
195 { |
|
196 iLexiconId = aLexiconId; |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------- |
|
200 // CNssContext::SetModelBankId |
|
201 // sets the model bank id to the given value |
|
202 // for internal use |
|
203 // --------------------------------------------------------- |
|
204 // |
|
205 void CNssContext::SetModelBankId( TUint32 aModelBankId ) |
|
206 { |
|
207 iModelBankId = aModelBankId; |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------- |
|
211 // CNssContext::SetRecognitionMode |
|
212 // sets the model bank id to the given value |
|
213 // for internal use |
|
214 // --------------------------------------------------------- |
|
215 // |
|
216 void CNssContext::SetRecognitionMode( TNSSRecognitionMode aRecogMode ) |
|
217 { |
|
218 iRecognitionMode = aRecogMode; |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------- |
|
222 // CNssContext::SaveToSrsL |
|
223 // for internal use |
|
224 // This method is used to save the context to the SRS. |
|
225 // This creates the model bank, |
|
226 // lexicon, and grammar for a context. Model bank, and lexicon |
|
227 // are created only for the first time, and are thus, fixed. |
|
228 // For every context, there is one grammar id. After, model bank, |
|
229 // lexicon, and grammar are created, the corresponding Ids are |
|
230 // set in the context object. |
|
231 // --------------------------------------------------------- |
|
232 // |
|
233 void CNssContext::BeginSaveToSrsL( MNssCoreSrsDBEventHandler* aSrsDBEventHandler ) |
|
234 { |
|
235 iContextSrsPortal->BeginSaveContextL( this, aSrsDBEventHandler ); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------- |
|
239 // CNssContext::DeleteFromSrsL |
|
240 // for internal use |
|
241 // This method is used to delete a context from the SRS. |
|
242 // This deletes the grammar from the SRS. |
|
243 // --------------------------------------------------------- |
|
244 // |
|
245 void CNssContext::BeginDeleteFromSrsL( MNssCoreSrsDBEventHandler* aSrsDBEventHandler ) |
|
246 { |
|
247 iContextSrsPortal->BeginDeleteContextL( this, aSrsDBEventHandler ); |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------- |
|
251 // CNssContext::CommitSrsChanges |
|
252 // for internal use |
|
253 // This method is used to commit a context change from the SRS. |
|
254 // --------------------------------------------------------- |
|
255 // |
|
256 TInt CNssContext::CommitSrsChanges() |
|
257 { |
|
258 return iContextSrsPortal->CommitSaveContext(); |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------- |
|
262 // CNssContext::RollbackSrsChanges |
|
263 // for internal use |
|
264 // This method is used to commit a context change from the SRS. |
|
265 // --------------------------------------------------------- |
|
266 // |
|
267 TInt CNssContext::RollbackSrsChanges() |
|
268 { |
|
269 return iContextSrsPortal->RollbackSaveContext(); |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------- |
|
273 // CNssContext::SetModelBankAndLexiconExist |
|
274 // for internal use |
|
275 // sets the iModelBankAndLexiconExist flag to ETrue or EFalse |
|
276 // --------------------------------------------------------- |
|
277 // |
|
278 void CNssContext::SetModelBankAndLexiconExist( TBool aVal ) |
|
279 { |
|
280 iModelBankAndLexiconExist = aVal; |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------- |
|
284 // CNssContext::ModelBankAndLexiconExist |
|
285 // for internal use |
|
286 // gets the value of the iModelBankAndLexiconExist flag |
|
287 // --------------------------------------------------------- |
|
288 // |
|
289 TBool CNssContext::ModelBankAndLexiconExist() |
|
290 { |
|
291 return iModelBankAndLexiconExist; |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------- |
|
295 // CNssContext::operator= |
|
296 // for internal use |
|
297 // overloaded assignment operator |
|
298 // --------------------------------------------------------- |
|
299 // |
|
300 CNssContext& CNssContext::operator=( const CNssContext& aContext ) |
|
301 { |
|
302 RUBY_DEBUG0( "CNssContext::operator=" ); |
|
303 |
|
304 if ( this != &aContext ) |
|
305 { |
|
306 if ( iName ) |
|
307 { |
|
308 delete iName; |
|
309 } |
|
310 iName = (aContext.iName)->Alloc(); |
|
311 iContextId = aContext.iContextId; |
|
312 iGlobal = aContext.iGlobal; |
|
313 iGrammarId = aContext.iGrammarId; |
|
314 iLexiconId = aContext.iLexiconId; |
|
315 iModelBankId = aContext.iModelBankId; |
|
316 iContextSrsPortal = aContext.iContextSrsPortal; |
|
317 iModelBankAndLexiconExist = aContext.iModelBankAndLexiconExist; |
|
318 iRecognitionMode = aContext.iRecognitionMode; |
|
319 } |
|
320 return *this; |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------- |
|
324 // CNssContext::CopyL |
|
325 // for internal use |
|
326 // creates a copy of this context |
|
327 // --------------------------------------------------------- |
|
328 // |
|
329 CNssContext* CNssContext::CopyL() |
|
330 { |
|
331 // Takes ages in strain test |
|
332 RUBY_DEBUG0( "CNssContext::CopyL" ); |
|
333 |
|
334 CNssContext* copy = new (ELeave) CNssContext( iContextSrsPortal ); |
|
335 copy->iName = iName->Alloc(); |
|
336 copy->iContextId = iContextId; |
|
337 copy->iGlobal = iGlobal; |
|
338 copy->iGrammarId = iGrammarId; |
|
339 copy->iLexiconId = iLexiconId; |
|
340 copy->iModelBankId = iModelBankId; |
|
341 copy->iContextSrsPortal = iContextSrsPortal; |
|
342 copy->iModelBankAndLexiconExist = iModelBankAndLexiconExist; |
|
343 copy->iClientData.Copy( iClientData ); |
|
344 |
|
345 return copy; |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------- |
|
349 // CNssContext::SetClientData |
|
350 // Sets/Resets the client data. The data must be saved |
|
351 // to VAS DBwith CNssContextMgr::SaveClientData. |
|
352 // --------------------------------------------------------- |
|
353 // |
|
354 void CNssContext::SetClientData(const TDesC8& aData) |
|
355 { |
|
356 iClientData.Copy( aData ); |
|
357 } |
|
358 |
|
359 // --------------------------------------------------------- |
|
360 // CNssContext::ClientData |
|
361 // Gets the client data. |
|
362 // --------------------------------------------------------- |
|
363 // |
|
364 const TDesC8& CNssContext::ClientData(void) |
|
365 { |
|
366 return iClientData; |
|
367 } |
|
368 |
|
369 // End of File |
|