|
1 /* |
|
2 * Copyright (c) 2004-2007 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 class handles the storage and access of speaker independent |
|
15 * grammars. It is also responsible for allocating memory when |
|
16 * loading grammars into the recognizer. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef SIGRAMMARDB_H |
|
22 #define SIGRAMMARDB_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <nsssispeechrecognitiondatadevasr.h> |
|
26 #include "sicommondb.h" |
|
27 |
|
28 // CLASS DECLARATION |
|
29 /** |
|
30 * This class implements Speaker Independent Grammar Database. |
|
31 * |
|
32 * @lib SIControllerPlugin.lib |
|
33 * @since 2.0 |
|
34 */ |
|
35 class CSIGrammarDB : public CSICommonDB |
|
36 { |
|
37 public: // Constructors and destructor |
|
38 |
|
39 /** |
|
40 * Two-phased constructor. |
|
41 */ |
|
42 static CSIGrammarDB* NewL( RDbNamedDatabase& aDatabase, |
|
43 RDbs& aDbSession, |
|
44 TInt aDrive ); |
|
45 |
|
46 /** |
|
47 * Destructor. |
|
48 */ |
|
49 virtual ~CSIGrammarDB(); |
|
50 |
|
51 public: // New functions |
|
52 |
|
53 /** |
|
54 * Adds a new rule variant into the specified grammar. |
|
55 * @since 2.0 |
|
56 * @param aClientUid client's Uid for data ownership |
|
57 * @param aGrammarID grammar Id |
|
58 * @param aLexiconID lexicon Id |
|
59 * @param aPronunciationID pronunciation Id |
|
60 * @return - |
|
61 */ |
|
62 void AddRuleVariantL(TUid aClientUid, |
|
63 TSIGrammarID aGrammarID, |
|
64 TSILexiconID aLexiconID, |
|
65 const RArray<TSIPronunciationID>& aPronunciationIDs, |
|
66 TSIRuleID aRuleID, |
|
67 TSIRuleVariantID& aRuleVariantID) ; |
|
68 |
|
69 /** |
|
70 * Returns a grammar object containing all speaker independent rules of the specified grammar. |
|
71 * The grammar is added to iGrammarArray |
|
72 * @since 2.0 |
|
73 * @param aGrammarID grammar Id |
|
74 * @return pointer to a grammar object |
|
75 */ |
|
76 const CSICompiledGrammar* LoadGrammarL(TSIGrammarID aGrammarID ); |
|
77 |
|
78 /** |
|
79 * Creates a new rule in the database. |
|
80 * @since 2.0 |
|
81 * @param aClientUid client's Uid for data ownership |
|
82 * @param aGrammarID grammar Id |
|
83 * @param aRuleID rule Id of the created rule |
|
84 * @return - |
|
85 */ |
|
86 void CreateRuleL(TUid aClientUid,TSIGrammarID aGrammarID, TSIRuleID& aRuleID) ; |
|
87 |
|
88 /** |
|
89 * Creates a new grammar in the database. |
|
90 * @since 2.0 |
|
91 * @param aClientUid client's Uid for data ownership |
|
92 * @return a new grammar Id |
|
93 */ |
|
94 TSIGrammarID CreateGrammarL( TUid aClientUid ); |
|
95 |
|
96 /** |
|
97 * Creates a new grammar ID table in the database. |
|
98 * @since 2.0 |
|
99 * @param - |
|
100 * @return - |
|
101 */ |
|
102 void CreateIDTableL(); |
|
103 |
|
104 /** |
|
105 * Returns all grammar IDs that belong to the specified client. |
|
106 * @since 2.0 |
|
107 * @param aClientUid client's Uid for data ownership |
|
108 * @param aGrammarIDs reference where grammar Ids are stored |
|
109 * @return - |
|
110 */ |
|
111 void GetAllClientGrammarIDsL( |
|
112 TUid aClientUid, |
|
113 RArray<TSIGrammarID>& aGrammarIDs ); |
|
114 /** |
|
115 * Returns all grammar Ids in the database. |
|
116 * @since 2.0 |
|
117 * @param aGrammarIDs reference where grammar Ids are stored |
|
118 * @return - |
|
119 */ |
|
120 void GetAllGrammarIDsL( RArray<TSIGrammarID>& aGrammarIDs ); |
|
121 |
|
122 |
|
123 /** |
|
124 * Returns all rule Ids that exist in the specified grammar. |
|
125 * @since 2.0 |
|
126 * @param aGrammarID grammar Id |
|
127 * @param aRuleIDs reference where rule Ids are stored |
|
128 * @return - |
|
129 */ |
|
130 void GetAllRuleIDsL( TSIGrammarID aGrammarID, RArray<TSIRuleID>& aRuleIDs ); |
|
131 |
|
132 /** |
|
133 * Checks if a valid grammar is loaded. |
|
134 * @since 2.0 |
|
135 * @param - |
|
136 * @return ETrue if a valid grammar is loaded |
|
137 */ |
|
138 TBool IsGrammarLoaded(); |
|
139 |
|
140 /** |
|
141 * Checks if the rule is valid or not. |
|
142 * @since 2.0 |
|
143 * @param aGrammarID grammar Id |
|
144 * @param aRuleID rule Id |
|
145 * @return ETrue if the rule is valid |
|
146 */ |
|
147 TBool IsRuleValidL( TSIGrammarID aGrammarID, TSIRuleID aRuleID ); |
|
148 |
|
149 /** |
|
150 * Removes the specified grammar from the database. |
|
151 * Removing a grammar will remove all rules within the grammar. |
|
152 * @since 2.0 |
|
153 * @param aClientUid client's Uid for data ownership |
|
154 * @param aGrammarID grammar Id |
|
155 * @return - |
|
156 */ |
|
157 void RemoveGrammarL( TUid aClientUid, TSIGrammarID aGrammarID ); |
|
158 |
|
159 /** |
|
160 * Removes the specified rule from the database. |
|
161 * @since 2.0 |
|
162 * @param aClientUid client's Uid for data ownership |
|
163 * @param aGrammarID grammar Id |
|
164 * @param aRuleID rule Id |
|
165 * @return - |
|
166 */ |
|
167 void RemoveRuleL(TUid aClientUid,TSIGrammarID aGrammarID, TSIRuleID aRuleID ); |
|
168 |
|
169 /** |
|
170 * Deallocates the temporary memory containing the grammar object created with AllRulesL. |
|
171 * @since 2.0 |
|
172 * @param - |
|
173 * @return - |
|
174 */ |
|
175 void ResetAndDestroy(); |
|
176 |
|
177 /** |
|
178 * Unloads the specified rule from the specified grammar in temporary memory, previously |
|
179 * loaded with AllRulesL. The rule in the database remains intact. |
|
180 * @since 2.0 |
|
181 * @param aGrammarID grammar Id |
|
182 * @param aRuleID rule Id |
|
183 * @return - |
|
184 */ |
|
185 void UnloadRuleL( TSIGrammarID aGrammarID, TSIRuleID aRuleID ); |
|
186 |
|
187 /** |
|
188 * Unloads the specified grammar from the temporary memory, previously |
|
189 * loaded with AllRulesL. The grammar in the database remains intact. |
|
190 * @since 2.0 |
|
191 * @param aGrammarID grammar Id |
|
192 * @return - |
|
193 */ |
|
194 void UnloadGrammarL( TSIGrammarID aGrammarID); |
|
195 |
|
196 /** |
|
197 * Update the specified grammar in the database |
|
198 * @since 2.0 |
|
199 * @param aClientUid client's Uid for data ownership |
|
200 * @param aSICompiledGrammar pointer to a updated grammar object |
|
201 * @return - |
|
202 */ |
|
203 void UpdateGrammarL(TUid aClientUid,CSICompiledGrammar* aSICompiledGrammar); |
|
204 |
|
205 /** |
|
206 * Returns a grammar object containing all speaker independent rules of the specified grammar. |
|
207 * The pointer to the object is not put in the iGrammarArray |
|
208 * @since 2.0 |
|
209 * @param aGrammarID grammar Id |
|
210 * @param |
|
211 * @return Pointer to a compiled grammar object |
|
212 */ |
|
213 const CSICompiledGrammar* GrammarL(TSIGrammarID aGrammarID ); |
|
214 |
|
215 /** |
|
216 * Find a grammar from loaded grammar array |
|
217 * @since 2.0 |
|
218 * @param aGrammarID grammar Id |
|
219 * @param |
|
220 * @return Pointer to a compiled grammar object |
|
221 */ |
|
222 CSICompiledGrammar* FindGrammarL(TSIGrammarID aGrammarID) ; |
|
223 |
|
224 |
|
225 /** |
|
226 * Get a new uniq ID |
|
227 * @since 2.0 |
|
228 * @param Rule ID array |
|
229 * @param |
|
230 * @return Created ID |
|
231 */ |
|
232 TInt GetNewID( RArray<TSIRuleID>& aMyIds ); |
|
233 |
|
234 /** |
|
235 * Returns the number of rules in the specified grammar. |
|
236 * @since 2.0 |
|
237 * @param aGrammarID grammar Id |
|
238 * @return Number of rules |
|
239 */ |
|
240 TInt RuleCountL( TSIGrammarID aGrammarID ); |
|
241 |
|
242 private: |
|
243 |
|
244 /** |
|
245 * C++ default constructor. |
|
246 */ |
|
247 CSIGrammarDB( RDbNamedDatabase& aDatabase, RDbs& aDbSession, TInt aDrive ); |
|
248 |
|
249 /** |
|
250 * By default Symbian 2nd phase constructor is private. |
|
251 */ |
|
252 void ConstructL(); |
|
253 |
|
254 private: // Data |
|
255 // Temporary memory where loaded grammars are held during recognition session |
|
256 RPointerArray<CSICompiledGrammar> iGrammarArray; |
|
257 }; |
|
258 |
|
259 #endif // SIGRAMMARDB_H |
|
260 |
|
261 // End of File |