os/mm/mmdevicefw/speechrecogsupport/tsrc/ASR/src/Database/sddatabase.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmdevicefw/speechrecogsupport/tsrc/ASR/src/Database/sddatabase.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,289 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __SDDATABASE_H__
    1.20 +#define __SDDATABASE_H__
    1.21 +
    1.22 +#include <e32base.h>
    1.23 +
    1.24 +class CSecurityDecryptBase;
    1.25 +class CSecurityEncryptBase;
    1.26 +
    1.27 +#include <d32dbms.h>
    1.28 +#include <s32file.h>
    1.29 +#include <mmf/common/speechrecognitiondatacommon.h>
    1.30 +
    1.31 +
    1.32 +class CSDDatabase : public CBase
    1.33 +	{
    1.34 +public:
    1.35 +	class TPronunciationData
    1.36 +		{
    1.37 +	public:
    1.38 +		TPronunciationID iPronunciationID;
    1.39 +		TModelBankID iModelBankID;
    1.40 +		TModelID iModelID;
    1.41 +		};
    1.42 +		
    1.43 +	class TRuleData
    1.44 +		{
    1.45 +	public:
    1.46 +		TRuleID iRuleID;
    1.47 +		TLexiconID iLexiconID;
    1.48 +		TPronunciationID iPronunciationID;
    1.49 +		};
    1.50 +
    1.51 +	class TModelData
    1.52 +		{
    1.53 +	public:
    1.54 +		TModelID iModelID;
    1.55 +		TUint32 iUtteranceDurationMicroSeconds;
    1.56 +		};
    1.57 +
    1.58 +
    1.59 +
    1.60 +	class RSDGrammarTable
    1.61 +		{
    1.62 +	public:
    1.63 +		RSDGrammarTable(CSDDatabase& aDatabase);		
    1.64 +		
    1.65 +		void OpenL(TBool aOwnedByClient = EFalse);
    1.66 +		
    1.67 +		void CreateGrammarL(TGrammarID& aGrammarID);
    1.68 +		void AddGrammarL(TGrammarID aGrammarID);
    1.69 +		void RemoveGrammarL(TGrammarID aGrammarID);
    1.70 +
    1.71 +		TBool FindGrammarL(TGrammarID aGrammarID);
    1.72 +		void GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs);
    1.73 +		void Close();
    1.74 +		
    1.75 +	private:
    1.76 +		CSDDatabase& iDatabase;
    1.77 +		RDbView iView;
    1.78 +		};
    1.79 +		
    1.80 +	class RSDLexiconTable
    1.81 +		{
    1.82 +	public:
    1.83 +		RSDLexiconTable(CSDDatabase& aDatabase);		
    1.84 +		
    1.85 +		void OpenL(TBool aOwnedByClient = EFalse);
    1.86 +		
    1.87 +		void CreateLexiconL(TLexiconID& aLexiconID);
    1.88 +		void AddLexiconL(TLexiconID aLexiconID);
    1.89 +		void RemoveLexiconL(TLexiconID aLexiconID);
    1.90 +
    1.91 +		TBool FindLexiconL(TLexiconID aLexiconID);
    1.92 +		void GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs);
    1.93 +		void Close();
    1.94 +		
    1.95 +	private:
    1.96 +		CSDDatabase& iDatabase;
    1.97 +		RDbView iView;
    1.98 +		};
    1.99 +		
   1.100 +	class RSDModelBankTable
   1.101 +		{
   1.102 +	public:
   1.103 +		RSDModelBankTable(CSDDatabase& aDatabase);		
   1.104 +		
   1.105 +		void OpenL(TBool aOwnedByClient = EFalse);
   1.106 +		
   1.107 +		TModelBankID CreateModelBankL();
   1.108 +		void AddModelBankL(TModelBankID aModelBankID);
   1.109 +		void RemoveModelBankL(TModelBankID aModelBankID);
   1.110 +
   1.111 +		TBool FindModelBankL(TModelBankID aModelBankID);
   1.112 +		void GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs);
   1.113 +		void Close();
   1.114 +		
   1.115 +	private:
   1.116 +		CSDDatabase& iDatabase;
   1.117 +		RDbView iView;
   1.118 +		};
   1.119 +		
   1.120 +	class RSDRuleTable
   1.121 +		{
   1.122 +	public:
   1.123 +		RSDRuleTable(CSDDatabase& aDatabase);		
   1.124 +		
   1.125 +		void OpenL(TGrammarID aGrammarID);
   1.126 +		
   1.127 +		TRuleID CreateRuleL(TRuleData aRuleData);
   1.128 +		void AddRuleL(TRuleData aRuleData);
   1.129 +		void RemoveRuleL(TRuleID aRuleID);
   1.130 +
   1.131 +		void GetRuleDataL(TRuleID aRuleID, TRuleData& aRuleData);
   1.132 +
   1.133 +		TBool FindRuleL(TRuleID aRuleID);
   1.134 +		TBool IsRuleValidL(TRuleID aRuleID);
   1.135 +		void GetAllRuleIDsL(RArray<TRuleID>& aRuleIDs);
   1.136 +		void Close();
   1.137 +		
   1.138 +	private:
   1.139 +		CSDDatabase& iDatabase;
   1.140 +		RDbView iView;
   1.141 +		TGrammarID iGrammarID;
   1.142 +		};
   1.143 +		
   1.144 +	class RSDPronunciationTable
   1.145 +		{
   1.146 +	public:
   1.147 +		RSDPronunciationTable(CSDDatabase& aDatabase);		
   1.148 +		
   1.149 +		void OpenL(TLexiconID aLexiconID);
   1.150 +		
   1.151 +		TPronunciationID CreatePronunciationL(TPronunciationData aPronunciationData);
   1.152 +		void AddPronunciationL(TPronunciationData aPronunciationData);
   1.153 +		void RemovePronunciationL(TPronunciationID aPronunciationID);
   1.154 +		void GetPronunciationDataL(TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData);
   1.155 +
   1.156 +		TBool FindPronunciationL(TPronunciationID aPronunciationID);
   1.157 +		void GetAllPronunciationIDsL(RArray<TPronunciationID>& aPronunciationIDs);
   1.158 +		void Close();
   1.159 +		
   1.160 +	private:
   1.161 +		CSDDatabase& iDatabase;
   1.162 +		RDbView iView;
   1.163 +		TLexiconID iLexiconID;
   1.164 +		};
   1.165 +
   1.166 +
   1.167 +		
   1.168 +		
   1.169 +	class RSDModelTable
   1.170 +		{
   1.171 +	public:
   1.172 +		RSDModelTable(CSDDatabase& aDatabase);		
   1.173 +		
   1.174 +		void OpenL(TModelBankID aModelBankID);
   1.175 +		
   1.176 +		TModelID CreateModelL(TModelData aModelData);
   1.177 +		void AddModelL(TModelData aModelData);
   1.178 +		void RemoveModelL(TModelID aModelID);
   1.179 +
   1.180 +		void GetModelDataL(TModelID aModelID, TModelData& aModelData);
   1.181 +
   1.182 +		TBool FindModelL(TModelID aModelID);
   1.183 +		void GetAllModelIDsL(RArray<TModelID>& aModelIDs);
   1.184 +		void Close();
   1.185 +		
   1.186 +	private:
   1.187 +		CSDDatabase& iDatabase;
   1.188 +		RDbView iView;
   1.189 +		TModelBankID iModelBankID;
   1.190 +		};
   1.191 +
   1.192 +	class RSDSettingsTable
   1.193 +		{
   1.194 +	public:
   1.195 +		RSDSettingsTable(CSDDatabase& aDatabase);		
   1.196 +		
   1.197 +		void OpenL();
   1.198 +
   1.199 +		TUint32 GetValueL(TUint32 aIndex);
   1.200 +		void SetValueL(TUint32 aIndex, TUint32 aValue);
   1.201 +
   1.202 +		void Close();
   1.203 +		
   1.204 +	private:
   1.205 +		CSDDatabase& iDatabase;
   1.206 +		RDbView iView;
   1.207 +		};
   1.208 +
   1.209 +
   1.210 +
   1.211 +
   1.212 +
   1.213 +		
   1.214 +public:		
   1.215 +	static CSDDatabase* NewL(const TDesC& aFileName, TBool aUseExisting=ETrue);
   1.216 +	
   1.217 +	TGrammarID CreateGrammarL();
   1.218 +	void AddGrammarL(TGrammarID aGrammarID);
   1.219 +	void RemoveGrammarL(TGrammarID aGrammarID);
   1.220 +	void GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs, TBool aOwnedByClient=EFalse);
   1.221 +	TBool GrammarExistsL(TGrammarID aGrammarID);
   1.222 +	
   1.223 +	TLexiconID CreateLexiconL();
   1.224 +	void AddLexiconL(TLexiconID aLexiconID);
   1.225 +	void RemoveLexiconL(TLexiconID aLexiconID);
   1.226 +	void GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs, TBool aOwnedByClient=EFalse);
   1.227 +	TBool LexiconExistsL(TLexiconID aLexiconID);
   1.228 +	
   1.229 +	TModelBankID CreateModelBankL();
   1.230 +	void AddModelBankL(TModelBankID aModelBankID);
   1.231 +	void RemoveModelBankL(TModelBankID aModelBankID);
   1.232 +	void GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs, TBool aOwnedByClient=EFalse);
   1.233 +	TBool ModelBankExistsL(TModelBankID aModelBankID);
   1.234 +
   1.235 +
   1.236 +	TRuleID CreateRuleL(TGrammarID aGrammarID, TRuleData aRuleData);
   1.237 +	void AddRuleL(TGrammarID aGrammarID, TRuleData aRuleData);
   1.238 +	void RemoveRuleL(TGrammarID aGrammarID, TRuleID aRuleID);
   1.239 +	void GetAllRuleIDsL(TGrammarID aGrammarID, RArray<TRuleID>& aRuleIDs);
   1.240 +	TBool RuleExistsL(TGrammarID aGrammarID, TRuleID aRuleID);
   1.241 +	
   1.242 +	TPronunciationID CreatePronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData);
   1.243 +	void AddPronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData);
   1.244 +	void RemovePronunciationL(TLexiconID aLexiconID, TPronunciationID aPronunciationID);
   1.245 +	void GetPronunciationDataL(TLexiconID aLexiconID, TPronunciationID aPronunciationID, TPronunciationData& aPronunciation);
   1.246 +	void GetAllPronunciationIDsL(TLexiconID aLexiconID, RArray<TPronunciationID>& aPronunciationID);
   1.247 +	TBool PronunciationExistsL(TLexiconID aLexiconID, TPronunciationID aPronunciationID);
   1.248 +	
   1.249 +	TModelID CreateModelL(TModelBankID aModelBankID, TModelData aModelData);
   1.250 +	void AddModelL(TModelBankID aModelBankID, TModelData aModelData);
   1.251 +	void RemoveModelL(TModelBankID aModelBankID, TModelID aModelID);
   1.252 +	void GetModelDataL(TModelBankID aModelBankID, TModelID aModelID, TModelData& aModelData);
   1.253 +	void GetAllModelIDsL(TModelBankID aModelBankID, RArray<TModelID>& aModelIDs);
   1.254 +	TBool ModelExistsL(TModelBankID aModelBankID, TModelID aModelID);
   1.255 +
   1.256 +	
   1.257 +	TUid ClientUid();
   1.258 +	RDbDatabase& Database();
   1.259 +	
   1.260 +	void StartTransactionL();
   1.261 +	void CommitChangesL();
   1.262 +	
   1.263 +	TUint32 AllocNewIDL();
   1.264 +	void UpdateLastIDL(TUint32 aLastID);
   1.265 +	
   1.266 +	void SetClientUid(TUid aClientUid);
   1.267 +	~CSDDatabase(); 
   1.268 +	
   1.269 +	void CreateTestDatabaseL();
   1.270 +	
   1.271 +private:
   1.272 +	void OpenDatabaseL(const TDesC& aFileName);
   1.273 +	void CreateDatabaseL(const TDesC& aFileName);
   1.274 +	
   1.275 +	void DoCreateTablesL();
   1.276 +	void DoCreateIndexesL();
   1.277 +	
   1.278 +	CSDDatabase();
   1.279 +	
   1.280 +	void ConstructL(const TDesC& aFileName, TBool aUseExisting);
   1.281 +	
   1.282 +
   1.283 +	TUid iClientUid;
   1.284 +	CFileStore* iDbStore;
   1.285 +	RDbStoreDatabase iDatabase;
   1.286 +	TBool iDatabaseOpened;
   1.287 +	
   1.288 +	TUint32 iLastID;
   1.289 +		
   1.290 +	};
   1.291 +	
   1.292 +#endif //__SDDATABASE_H__