srsf/sisrscontrollerplugin/src/simodelbankdb.h
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2002 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 user trained models
       
    15 *				 and utterances into a database.  It performs checksum verification
       
    16 *				 for the stored data.  It is also responsible for allocating memory
       
    17 *				 when loading the models into the recognizer.
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 #ifndef CSIMODELBANKDB_H
       
    23 #define CSIMODELBANKDB_H
       
    24 
       
    25 //  INCLUDES
       
    26 #include <nsssispeechrecognitiondatadevasr.h>
       
    27 
       
    28 #include "asrplugindataloader.h"
       
    29 #include "sicommondb.h"
       
    30 
       
    31 // CLASS DECLARATION
       
    32 
       
    33 /**
       
    34 *  This class implements Speaker Independent Model Database.
       
    35 *
       
    36 *  @lib SIControllerPlugin.lib
       
    37 *  @since 2.0
       
    38 */
       
    39 class CSIModelBankDB : public CSICommonDB
       
    40     {
       
    41     public:  // Constructors and destructor
       
    42 
       
    43         /**
       
    44         * Two-phased constructor.
       
    45         */
       
    46         static CSIModelBankDB* NewL( RDbNamedDatabase& aDatabase, 
       
    47                                      RDbs& aDbSession,
       
    48                                      TInt aDrive );
       
    49 
       
    50         /**
       
    51         * Destructor.
       
    52         */
       
    53         virtual ~CSIModelBankDB();
       
    54 
       
    55     public: // New functions
       
    56 
       
    57         /**
       
    58 		* Returns a model bank object containing all speaker independent models of
       
    59 		* the specified model bank.
       
    60 		* @since 2.0
       
    61 		* @param	aModelBankID		model bank Id
       
    62 		* @return	pointer to a bank bank object
       
    63         */
       
    64         const CSIModelBank* AllAcousticModelsL( TSIModelBankID aModelBankID ); //*
       
    65 
       
    66 		/**
       
    67         * Returns the total number of models in the system (all model banks).
       
    68         * @since	2.0
       
    69         * @param	-
       
    70         * @return	Number of models in all model banks.
       
    71         */
       
    72 		TInt AllModelCountL(); 
       
    73 
       
    74         /**
       
    75         * Creates a new model bank ID table in the database.
       
    76         * @since 2.0
       
    77         * @param	-
       
    78         * @return	-
       
    79         */
       
    80         void CreateIDTableL(); 
       
    81 
       
    82         /**
       
    83         * Creates a new model bank in the database.
       
    84         * @since 2.0
       
    85         * @param	aClientUid			client's Uid for data ownership
       
    86         * @return	new model bank Id
       
    87         */
       
    88         TSIModelBankID CreateModelBankL( TUid aClientUid ); 
       
    89 
       
    90         /**
       
    91         * Returns all model bank Ids that belong to the specified client.
       
    92         * @since 2.0
       
    93         * @param	aClientUid			client's Uid for data ownership
       
    94 		* @param	aModelBankIDs		reference where model bank Ids are stored
       
    95         * @return	-
       
    96         */
       
    97 		void GetAllClientModelBankIDsL( TUid aClientUid, RArray<TSIModelBankID>& aModelBankIDs ); //*
       
    98 
       
    99         /**
       
   100         * Returns all model bank Ids in the database.
       
   101         * @since 2.0
       
   102 		* @param	aLexiconIDs			reference where model bank Ids are stored
       
   103         * @return	-
       
   104         */
       
   105 		void GetAllModelBankIDsL( RArray<TSIModelBankID>& aModelBankIDs ); //*
       
   106 
       
   107         /**
       
   108         * Returns all model Ids that exist in the specified model bank.
       
   109         * @since 2.0
       
   110         * @param	aModelBankID		model bank Id
       
   111 		* @param	aModelIDs			reference where model Ids are stored
       
   112         * @return	-
       
   113         */
       
   114         void GetAllModelIDsL( TSIModelBankID aModelBankID, RArray<TSIModelID>& aModelIDs ); //*
       
   115 
       
   116 		/**
       
   117         * Returns the duration of the utterance for the specified model.
       
   118         * @since 2.0
       
   119         * @param	aModelBankID		model bank Id
       
   120 		* @param	aModelID			model Id
       
   121 		* @param	aDuration			reference where the duration of utterance is set
       
   122         * @return	-
       
   123         */
       
   124 		void GetUtteranceDurationL( TSIModelBankID aModelBankID, TSIModelID aModelID,
       
   125 					TTimeIntervalMicroSeconds32& aDuration ); //*
       
   126 
       
   127 		/**
       
   128         * Checks if the model bank is valid or not and also verify ownership.
       
   129 		* Leaves with KErrAsrDataRightViolation if not owned by the client.
       
   130         * @since 2.0
       
   131         * @param	aClientUid			client's Uid for data ownership
       
   132         * @param	aModelBankID		model bank Id
       
   133         * @return	ETrue if the model bank is valid
       
   134         */
       
   135         TBool IsModelBankValidL( TUid aClientUid, TSIModelBankID aModelBankID ); //*
       
   136 
       
   137 		/**
       
   138         * Checks if the model is valid or not.
       
   139         * @since 2.0
       
   140         * @param	aModelBankID		model bank Id
       
   141 		* @param	aModelID			model Id
       
   142         * @return	ETrue if the model is valid
       
   143         */
       
   144 		TBool IsModelValidL( TSIModelBankID aModelBankID, TSIModelID aModelID ); //*
       
   145 
       
   146 		/**
       
   147         * Checks if the model bank is valid and update if necessary.
       
   148         * @since 3.1
       
   149         * @param	aModelBankID		model bank Id
       
   150         */
       
   151         void UpdateModelBankIfInvalidL( TSIModelBankID aModelBankID );
       
   152 		/**
       
   153         * Returns the number of models in the specified model bank.
       
   154         * @since 2.0
       
   155         * @param	aModelBankID		model bank Id
       
   156         * @return	Number of models
       
   157         */
       
   158         TInt ModelCountL( TSIModelBankID aModelBankID ); //*
       
   159 
       
   160 		/**
       
   161         * Removes the specified model bank from the database.
       
   162 		* Removing a model bank will remove all models within the model bank.
       
   163         * @since 2.0
       
   164         * @param	aClientUid			client's Uid for data ownership
       
   165         * @param	aModelBankID		model bank Id
       
   166         * @return	-
       
   167         */
       
   168         void RemoveModelBankL( TUid aClientUid, TSIModelBankID aModelBankID ); //*
       
   169 
       
   170 		/**
       
   171         * Removes the specified model from the database.
       
   172         * @since 2.0
       
   173         * @param	aClientUid			client's Uid for data ownership
       
   174         * @param	aModelBankID		model bank Id
       
   175 		* @param	aModelID			model Id
       
   176         * @return	-
       
   177         */
       
   178         void RemoveModelL( TUid aClientUid, TSIModelBankID aModelBankID, TSIModelID aModelID ); //*
       
   179 
       
   180 		/**
       
   181         * Deallocates the temporary memory allocated during training.
       
   182         * @since 2.0
       
   183         * @param	-
       
   184         * @return	-
       
   185         */
       
   186         void Reset(); //*
       
   187 
       
   188 		/**
       
   189         * Deallocates the temporary memory allocated during recognition.
       
   190         * @since 2.0
       
   191         * @param	-
       
   192         * @return	-
       
   193         */
       
   194 		void ResetAndDestroy(); //*
       
   195 
       
   196 		/**
       
   197         * Saves the trained model in the temporary memory into the database.
       
   198         * @since 2.0
       
   199         * @param	aModelBankID		model bank Id
       
   200         * @return	A new model ID
       
   201         */
       
   202         TSIModelID SaveModelL( TSIModelBankID aModelBankID ); //*
       
   203 
       
   204 		/**
       
   205         * Saves the acoustic model into a temporary memory during training.
       
   206         * @since 2.0
       
   207         * @param	aAcousticModelBuf	buffer containing the acoustic model
       
   208         * @return	-
       
   209         */
       
   210         void SetAcousticModelL( const TPtr8& aAcousticModelBuf ); //*
       
   211 
       
   212 		/**
       
   213         * Saves the utterance duration of a trained model in temporary memory during training.
       
   214         * @since 2.0
       
   215         * @param	aUtteranceDuration	utterace duration in microseconds
       
   216         * @return	-
       
   217         */
       
   218         void SetUtteranceDurationL( TInt aUtteranceDuration ); //*
       
   219 
       
   220 		/**
       
   221         * Returns a reference to a pointer descriptor with the specified length where the
       
   222 		* utterance will be stored.
       
   223         * @since 2.0
       
   224         * @param	aLength				length of the requested descriptor
       
   225         * @return	Reference to a pointer descriptor
       
   226         */
       
   227 		// TPtr8& UtteranceBufferL( TInt aLength ); //*
       
   228 
       
   229 		/**
       
   230         * Returns a reference to a previously trained user utterance of the specified model.
       
   231         * @since 2.0
       
   232         * @param	aModelBankID		model bank Id
       
   233 		* @param	aModelID			model Id
       
   234         * @return	Reference to a user utterance pointer descriptor
       
   235         */
       
   236         // TPtr8& UtteranceL( TSIModelBankID aModelBankID, TSIModelID aModelID ); //*
       
   237 
       
   238   		// test
       
   239 		RPointerArray<CSIModelBank>& ModelBankArray();
       
   240 
       
   241     private:
       
   242 
       
   243         /**
       
   244         * C++ default constructor.
       
   245         */
       
   246         CSIModelBankDB( RDbNamedDatabase& aDatabase, RDbs& aDbSession, TInt aDrive );
       
   247 
       
   248         /**
       
   249         * By default Symbian 2nd phase constructor is private.
       
   250         */
       
   251         void ConstructL();
       
   252 
       
   253         /**
       
   254         * Calculates a checksum value for the given buffer.
       
   255         * @since 2.0
       
   256         * @param	aBuf				reference to a pointer descriptor containing binary data
       
   257         * @return	Checksum value
       
   258         */
       
   259         TInt32 CalculateChecksum( const TPtr8& aBuf );
       
   260 
       
   261         /**
       
   262         * Verifies the checksum value for the given buffer.
       
   263         * @since 2.0
       
   264         * @param	aBuf				reference to a pointer descriptor containing binary data
       
   265 		* @param	aChecksum			checksum value to compare to
       
   266         * @return	ETrue if the checksum of aBuf is equal to aChecksum
       
   267         */
       
   268         TBool VerifyChecksum( const TPtr8& aBuf, TInt32 aChecksum );
       
   269 		const CSIModelBank* GetAllAcousticModelsL( TSIModelBankID aModelBankID );
       
   270 
       
   271     private:    // Data
       
   272 
       
   273 		// Temporary memory where loaded model banks are held during recognition session
       
   274 		RPointerArray<CSIModelBank> iModelBankArray;
       
   275 
       
   276 		// Pointer to acoustic model - used during training
       
   277 		TPtr8 iAcousticModelPtr;
       
   278  		// Pointer to the user utterance
       
   279 	//	TPtr8 iUtterancePtr;
       
   280 		 
       
   281 		CDataLoader* iDataLoader;
       
   282 
       
   283 		// Temporary memory where loaded SI model banks are held during recognition session
       
   284 		//RPointerArray<CSIModelBank> iSIModelBankArray;
       
   285 		HBufC8 *iFileBuffer;
       
   286 		RFs iFs;
       
   287     };
       
   288 
       
   289 #endif      // CSIModelBankDB_H
       
   290 
       
   291 // End of File