os/mm/mmdevicefw/speechrecogsupport/tsrc/ASR/src/Database/sddatabase.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __SDDATABASE_H__
    17 #define __SDDATABASE_H__
    18 
    19 #include <e32base.h>
    20 
    21 class CSecurityDecryptBase;
    22 class CSecurityEncryptBase;
    23 
    24 #include <d32dbms.h>
    25 #include <s32file.h>
    26 #include <mmf/common/speechrecognitiondatacommon.h>
    27 
    28 
    29 class CSDDatabase : public CBase
    30 	{
    31 public:
    32 	class TPronunciationData
    33 		{
    34 	public:
    35 		TPronunciationID iPronunciationID;
    36 		TModelBankID iModelBankID;
    37 		TModelID iModelID;
    38 		};
    39 		
    40 	class TRuleData
    41 		{
    42 	public:
    43 		TRuleID iRuleID;
    44 		TLexiconID iLexiconID;
    45 		TPronunciationID iPronunciationID;
    46 		};
    47 
    48 	class TModelData
    49 		{
    50 	public:
    51 		TModelID iModelID;
    52 		TUint32 iUtteranceDurationMicroSeconds;
    53 		};
    54 
    55 
    56 
    57 	class RSDGrammarTable
    58 		{
    59 	public:
    60 		RSDGrammarTable(CSDDatabase& aDatabase);		
    61 		
    62 		void OpenL(TBool aOwnedByClient = EFalse);
    63 		
    64 		void CreateGrammarL(TGrammarID& aGrammarID);
    65 		void AddGrammarL(TGrammarID aGrammarID);
    66 		void RemoveGrammarL(TGrammarID aGrammarID);
    67 
    68 		TBool FindGrammarL(TGrammarID aGrammarID);
    69 		void GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs);
    70 		void Close();
    71 		
    72 	private:
    73 		CSDDatabase& iDatabase;
    74 		RDbView iView;
    75 		};
    76 		
    77 	class RSDLexiconTable
    78 		{
    79 	public:
    80 		RSDLexiconTable(CSDDatabase& aDatabase);		
    81 		
    82 		void OpenL(TBool aOwnedByClient = EFalse);
    83 		
    84 		void CreateLexiconL(TLexiconID& aLexiconID);
    85 		void AddLexiconL(TLexiconID aLexiconID);
    86 		void RemoveLexiconL(TLexiconID aLexiconID);
    87 
    88 		TBool FindLexiconL(TLexiconID aLexiconID);
    89 		void GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs);
    90 		void Close();
    91 		
    92 	private:
    93 		CSDDatabase& iDatabase;
    94 		RDbView iView;
    95 		};
    96 		
    97 	class RSDModelBankTable
    98 		{
    99 	public:
   100 		RSDModelBankTable(CSDDatabase& aDatabase);		
   101 		
   102 		void OpenL(TBool aOwnedByClient = EFalse);
   103 		
   104 		TModelBankID CreateModelBankL();
   105 		void AddModelBankL(TModelBankID aModelBankID);
   106 		void RemoveModelBankL(TModelBankID aModelBankID);
   107 
   108 		TBool FindModelBankL(TModelBankID aModelBankID);
   109 		void GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs);
   110 		void Close();
   111 		
   112 	private:
   113 		CSDDatabase& iDatabase;
   114 		RDbView iView;
   115 		};
   116 		
   117 	class RSDRuleTable
   118 		{
   119 	public:
   120 		RSDRuleTable(CSDDatabase& aDatabase);		
   121 		
   122 		void OpenL(TGrammarID aGrammarID);
   123 		
   124 		TRuleID CreateRuleL(TRuleData aRuleData);
   125 		void AddRuleL(TRuleData aRuleData);
   126 		void RemoveRuleL(TRuleID aRuleID);
   127 
   128 		void GetRuleDataL(TRuleID aRuleID, TRuleData& aRuleData);
   129 
   130 		TBool FindRuleL(TRuleID aRuleID);
   131 		TBool IsRuleValidL(TRuleID aRuleID);
   132 		void GetAllRuleIDsL(RArray<TRuleID>& aRuleIDs);
   133 		void Close();
   134 		
   135 	private:
   136 		CSDDatabase& iDatabase;
   137 		RDbView iView;
   138 		TGrammarID iGrammarID;
   139 		};
   140 		
   141 	class RSDPronunciationTable
   142 		{
   143 	public:
   144 		RSDPronunciationTable(CSDDatabase& aDatabase);		
   145 		
   146 		void OpenL(TLexiconID aLexiconID);
   147 		
   148 		TPronunciationID CreatePronunciationL(TPronunciationData aPronunciationData);
   149 		void AddPronunciationL(TPronunciationData aPronunciationData);
   150 		void RemovePronunciationL(TPronunciationID aPronunciationID);
   151 		void GetPronunciationDataL(TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData);
   152 
   153 		TBool FindPronunciationL(TPronunciationID aPronunciationID);
   154 		void GetAllPronunciationIDsL(RArray<TPronunciationID>& aPronunciationIDs);
   155 		void Close();
   156 		
   157 	private:
   158 		CSDDatabase& iDatabase;
   159 		RDbView iView;
   160 		TLexiconID iLexiconID;
   161 		};
   162 
   163 
   164 		
   165 		
   166 	class RSDModelTable
   167 		{
   168 	public:
   169 		RSDModelTable(CSDDatabase& aDatabase);		
   170 		
   171 		void OpenL(TModelBankID aModelBankID);
   172 		
   173 		TModelID CreateModelL(TModelData aModelData);
   174 		void AddModelL(TModelData aModelData);
   175 		void RemoveModelL(TModelID aModelID);
   176 
   177 		void GetModelDataL(TModelID aModelID, TModelData& aModelData);
   178 
   179 		TBool FindModelL(TModelID aModelID);
   180 		void GetAllModelIDsL(RArray<TModelID>& aModelIDs);
   181 		void Close();
   182 		
   183 	private:
   184 		CSDDatabase& iDatabase;
   185 		RDbView iView;
   186 		TModelBankID iModelBankID;
   187 		};
   188 
   189 	class RSDSettingsTable
   190 		{
   191 	public:
   192 		RSDSettingsTable(CSDDatabase& aDatabase);		
   193 		
   194 		void OpenL();
   195 
   196 		TUint32 GetValueL(TUint32 aIndex);
   197 		void SetValueL(TUint32 aIndex, TUint32 aValue);
   198 
   199 		void Close();
   200 		
   201 	private:
   202 		CSDDatabase& iDatabase;
   203 		RDbView iView;
   204 		};
   205 
   206 
   207 
   208 
   209 
   210 		
   211 public:		
   212 	static CSDDatabase* NewL(const TDesC& aFileName, TBool aUseExisting=ETrue);
   213 	
   214 	TGrammarID CreateGrammarL();
   215 	void AddGrammarL(TGrammarID aGrammarID);
   216 	void RemoveGrammarL(TGrammarID aGrammarID);
   217 	void GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs, TBool aOwnedByClient=EFalse);
   218 	TBool GrammarExistsL(TGrammarID aGrammarID);
   219 	
   220 	TLexiconID CreateLexiconL();
   221 	void AddLexiconL(TLexiconID aLexiconID);
   222 	void RemoveLexiconL(TLexiconID aLexiconID);
   223 	void GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs, TBool aOwnedByClient=EFalse);
   224 	TBool LexiconExistsL(TLexiconID aLexiconID);
   225 	
   226 	TModelBankID CreateModelBankL();
   227 	void AddModelBankL(TModelBankID aModelBankID);
   228 	void RemoveModelBankL(TModelBankID aModelBankID);
   229 	void GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs, TBool aOwnedByClient=EFalse);
   230 	TBool ModelBankExistsL(TModelBankID aModelBankID);
   231 
   232 
   233 	TRuleID CreateRuleL(TGrammarID aGrammarID, TRuleData aRuleData);
   234 	void AddRuleL(TGrammarID aGrammarID, TRuleData aRuleData);
   235 	void RemoveRuleL(TGrammarID aGrammarID, TRuleID aRuleID);
   236 	void GetAllRuleIDsL(TGrammarID aGrammarID, RArray<TRuleID>& aRuleIDs);
   237 	TBool RuleExistsL(TGrammarID aGrammarID, TRuleID aRuleID);
   238 	
   239 	TPronunciationID CreatePronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData);
   240 	void AddPronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData);
   241 	void RemovePronunciationL(TLexiconID aLexiconID, TPronunciationID aPronunciationID);
   242 	void GetPronunciationDataL(TLexiconID aLexiconID, TPronunciationID aPronunciationID, TPronunciationData& aPronunciation);
   243 	void GetAllPronunciationIDsL(TLexiconID aLexiconID, RArray<TPronunciationID>& aPronunciationID);
   244 	TBool PronunciationExistsL(TLexiconID aLexiconID, TPronunciationID aPronunciationID);
   245 	
   246 	TModelID CreateModelL(TModelBankID aModelBankID, TModelData aModelData);
   247 	void AddModelL(TModelBankID aModelBankID, TModelData aModelData);
   248 	void RemoveModelL(TModelBankID aModelBankID, TModelID aModelID);
   249 	void GetModelDataL(TModelBankID aModelBankID, TModelID aModelID, TModelData& aModelData);
   250 	void GetAllModelIDsL(TModelBankID aModelBankID, RArray<TModelID>& aModelIDs);
   251 	TBool ModelExistsL(TModelBankID aModelBankID, TModelID aModelID);
   252 
   253 	
   254 	TUid ClientUid();
   255 	RDbDatabase& Database();
   256 	
   257 	void StartTransactionL();
   258 	void CommitChangesL();
   259 	
   260 	TUint32 AllocNewIDL();
   261 	void UpdateLastIDL(TUint32 aLastID);
   262 	
   263 	void SetClientUid(TUid aClientUid);
   264 	~CSDDatabase(); 
   265 	
   266 	void CreateTestDatabaseL();
   267 	
   268 private:
   269 	void OpenDatabaseL(const TDesC& aFileName);
   270 	void CreateDatabaseL(const TDesC& aFileName);
   271 	
   272 	void DoCreateTablesL();
   273 	void DoCreateIndexesL();
   274 	
   275 	CSDDatabase();
   276 	
   277 	void ConstructL(const TDesC& aFileName, TBool aUseExisting);
   278 	
   279 
   280 	TUid iClientUid;
   281 	CFileStore* iDbStore;
   282 	RDbStoreDatabase iDatabase;
   283 	TBool iDatabaseOpened;
   284 	
   285 	TUint32 iLastID;
   286 		
   287 	};
   288 	
   289 #endif //__SDDATABASE_H__