|
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 is the baseclass for all SI Controller Plugin DB classes. |
|
15 * It implements the common database functionalities. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef SICOMMONDB_H |
|
21 #define SICOMMONDB_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <d32dbms.h> |
|
25 #include <e32svr.h> |
|
26 #include <sysutil.h> // Critical Level check |
|
27 #include <f32file.h> |
|
28 #include "s32strm.h" // Streams |
|
29 #include "s32mem.h" // Buffer streams |
|
30 #include "nsssispeechrecognitiondatacommon.h" |
|
31 #include "nsssispeechrecognitiondatadevasr.h" |
|
32 |
|
33 // CONSTANTS |
|
34 const TInt KSDDatabaseDrive = EDriveC; |
|
35 |
|
36 _LIT(KClientUidColumn, "clientUid"); |
|
37 _LIT(KUsedColumn, "used"); |
|
38 _LIT(KCounterColumn, "counter"); |
|
39 |
|
40 _LIT(KOpenParen, " ("); |
|
41 _LIT(KCloseParen, ")"); |
|
42 _LIT(KEqual, " = "); |
|
43 _LIT(KNext, ", "); |
|
44 |
|
45 |
|
46 _LIT(KSIGrammarTable, "siGrammarTable"); |
|
47 _LIT(KBinaryGrammarColumn, "BinaryGrammarId"); |
|
48 _LIT(KBinaryGrammarColumnSize, "BinaryGrammarSize"); |
|
49 _LIT(KGrammarIdTable, "siGrammarIdTable"); |
|
50 _LIT(KGrammarIdColumn, "grammarId"); |
|
51 _LIT(KGrammarIndex, "grammarIndex"); |
|
52 |
|
53 _LIT(KSILexiconTable, "siLexiconTable"); |
|
54 _LIT(KBinaryLexiconColumn, "BinaryLexiconId"); |
|
55 _LIT(KBinaryLexiconColumnSize, "BinaryLexiconSize"); |
|
56 _LIT(KLexiconIdTable, "siLexiconIdTable"); |
|
57 _LIT(KLexiconIdColumn, "lexiconId"); |
|
58 _LIT(KLexiconIndex, "lexiconIndex"); |
|
59 |
|
60 _LIT(KSIModelBankTable, "siModelBankTable"); |
|
61 _LIT(KBinaryModelBankColumn, "BinaryModelBankId"); |
|
62 _LIT(KBinaryModelBankColumnSize, "BinaryModelBankSize"); |
|
63 _LIT(KModelBankIdTable, "siModelBankIdTable"); |
|
64 _LIT(KModelBankTable, "siModelBankTable"); |
|
65 _LIT(KModelBankIdColumn, "modelBankId"); |
|
66 |
|
67 _LIT(KHmmColumn, "hmm"); |
|
68 _LIT(KHmmChecksumColumn, "hmmChecksum"); |
|
69 _LIT(KModelBankIndex, "modelBankIndex"); |
|
70 _LIT(KModelIndex, "modelIndex"); |
|
71 |
|
72 const TInt KNotUsed = 0; |
|
73 const TInt KUsed = 1; |
|
74 const TSIModelID KModelID=1; |
|
75 // CLASS DECLARATION |
|
76 |
|
77 /** |
|
78 * This class is the base class for all SI Controller Plugin DB classes. |
|
79 * It provides the common functionality for the DB classes. |
|
80 * |
|
81 * @lib SIControllerPlugin.lib |
|
82 * @since 2.0 |
|
83 */ |
|
84 class CSICommonDB : public CBase |
|
85 { |
|
86 public: // Constructors and destructor |
|
87 |
|
88 /** |
|
89 * C++ default constructor. |
|
90 */ |
|
91 CSICommonDB( RDbNamedDatabase& aDatabase, RDbs& aDbSession, TInt aDrive ); |
|
92 |
|
93 /** |
|
94 * Destructor. |
|
95 */ |
|
96 virtual ~CSICommonDB(); |
|
97 |
|
98 public: // New functions |
|
99 |
|
100 /** |
|
101 * Checks if the specified ID table exists or not. If it doesn't exist, it creates one. |
|
102 * @since 2.0 |
|
103 * @param aIdTable descriptor containing tabel name |
|
104 * @param aIdColumn descriptor containing ID column name |
|
105 * @param aIndex descriptor containing table index name |
|
106 * @return - |
|
107 */ |
|
108 void CreateIDTableL( const TDesC& aIdTable, const TDesC& aIdColumn, const TDesC& aIndex ); |
|
109 |
|
110 /** |
|
111 * Creates a new ID in the specified table. |
|
112 * @since 2.0 |
|
113 * @param aTableName descriptor containing table name |
|
114 * @param aIdColumn descriptor containing ID column name |
|
115 * @param aClientUid client Uid for data ownership |
|
116 * @return A new ID |
|
117 */ |
|
118 TUint32 CreateNewIDL( const TDesC& aTableName, const TDesC& aIdColumn, TUid aClientUid ); |
|
119 |
|
120 /** |
|
121 * Returns the counter column value after searching for the aKey in the specified table. |
|
122 * @since 2.0 |
|
123 * @param aTableName descriptor containing tabel name |
|
124 * @param aIndex descriptor containing table index name |
|
125 * @param aKey key to search in the table |
|
126 * @return Counter |
|
127 */ |
|
128 TInt CountL( const TDesC& aTableName, const TDesC& aIndex, TUint aKey ); |
|
129 |
|
130 /** |
|
131 * Checks if an unused Id exists in the given table. If found, row is set to |
|
132 * the found row. |
|
133 * @since 2.0 |
|
134 * @param "RDbTable& aDbTable" |
|
135 * @return ETrue if found |
|
136 */ |
|
137 TBool FindUnusedIDL( RDbTable& aDbTable ); |
|
138 |
|
139 /** |
|
140 * Returns all Ids in the specified table that belong to the specified client. |
|
141 * @since 2.0 |
|
142 * @param aTableName descriptor containing table name |
|
143 * @param aIdColumn descriptor containing ID column name |
|
144 * @param aClientUid client's Uid for data ownership |
|
145 * @param aIDs reference where Ids are stored |
|
146 */ |
|
147 void GetAllClientIDsL( const TDesC& aIdTable, const TDesC& aIdColumn, TUid aClientUid, RArray<TUint32>& aIDs ); |
|
148 |
|
149 /** |
|
150 * Returns all Ids in the specified table. |
|
151 * @since 2.0 |
|
152 * @param aTableName descriptor containing table name |
|
153 * @param aIdColumn descriptor containing ID column name |
|
154 * @param aIDs reference where Ids are stored |
|
155 */ |
|
156 void GetAllIDsL( const TDesC& aIdTable, const TDesC& aIdColumn, RArray<TUint32>& aIDs ); |
|
157 |
|
158 /** |
|
159 * Checks if the specified key exists in the specified table. |
|
160 * @since 2.0 |
|
161 * @param aTableName descriptor containing tabel name |
|
162 * @param aIndex descriptor containing table index name |
|
163 * @param aKey key to search in the table |
|
164 * @return ETrue if found. |
|
165 */ |
|
166 TBool IsValidL( const TDesC& aTableName, const TDesC& aIndex, TUint aKey ); |
|
167 |
|
168 /** |
|
169 * Sets the specified ID as unused in the specified table. |
|
170 * @since 2.0 |
|
171 * @param aTableName descriptor containing tabel name |
|
172 * @param aIdColumn descriptor containing ID column name |
|
173 * @param aId ID to be marked as unused |
|
174 */ |
|
175 void ReleaseIdL( const TDesC& aTableName, const TDesC& aIdColumn, TUint32 aId ); |
|
176 |
|
177 /** |
|
178 * Updates the counter value after finding the aKey in the specified table. |
|
179 * @since 2.0 |
|
180 * @param aTableName descriptor containing tabel name |
|
181 * @param aIndex descriptor containing table index name |
|
182 * @param aKey key to search in the table |
|
183 * @param aIncrement Increment if ETrue, decrement otherwise. |
|
184 */ |
|
185 void UpdateCounterL( const TDesC& aTableName, const TDesC& aIndex, TUint aKey, |
|
186 TBool aIncrement ); |
|
187 |
|
188 /** |
|
189 * Checks for data ownership. Leaves with KErrAsrDataRightViolation if not |
|
190 * owned by this client. |
|
191 * @since 2.0 |
|
192 * @param aClientUid client's Uid for data ownership |
|
193 * @param aTableName descriptor containing tabel name |
|
194 * @param aIndex descriptor containing table index name |
|
195 * @param aKey key to search in the table |
|
196 */ |
|
197 void VerifyOwnershipL( TUid aClientUid, const TDesC& aTableName, const TDesC& aIndex, |
|
198 TUint aKey ); |
|
199 |
|
200 public: // Data |
|
201 |
|
202 // Database |
|
203 RDbNamedDatabase& iDb; |
|
204 |
|
205 // DB session |
|
206 RDbs& iDbSession; |
|
207 |
|
208 // drive |
|
209 TInt iDrive; |
|
210 |
|
211 private: // New functions |
|
212 |
|
213 /** |
|
214 * Creates a new ID in the specified table. |
|
215 * @since 2.0 |
|
216 * @param aTableName descriptor containing table name |
|
217 * @param aIdColumn descriptor containing ID column name |
|
218 * @param aClientUid client Uid for data ownership |
|
219 * @return A new ID |
|
220 */ |
|
221 TUint32 DoCreateNewIDL( const TDesC& aTableName, const TDesC& aIdColumn, TUid aClientUid ); |
|
222 |
|
223 /** |
|
224 * Sets the specified ID as unused in the specified table. |
|
225 * @since 2.0 |
|
226 * @param aTableName descriptor containing tabel name |
|
227 * @param aIdColumn descriptor containing ID column name |
|
228 * @param aId ID to be marked as unused |
|
229 */ |
|
230 void DoReleaseIdL( const TDesC& aTableName, const TDesC& aIdColumn, TUint32 aId ); |
|
231 |
|
232 private: // Data |
|
233 |
|
234 // Mutex for DB write lock |
|
235 // Makes sure that only one process gets the DB lock |
|
236 RMutex iMutex; |
|
237 }; |
|
238 |
|
239 #endif // SICOMMONDB_H |
|
240 |
|
241 // End of File |