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