srsf/nssvasapi/nssvasdb/inc/nssvascvasdatabase.h
changeset 0 bf1d17376201
equal deleted inserted replaced
-1:000000000000 0:bf1d17376201
       
     1 /*
       
     2 * Copyright (c) 2003-2005 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:  CNssVasDatabase is responsible for the issuing of requests  to
       
    15 *               to the VasDb server and returning the results to the VasDb Managers.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CNSSVASDATABASE_H
       
    21 #define CNSSVASDATABASE_H
       
    22 
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <e32cons.h>
       
    26 #include <s32file.h>
       
    27 #include <d32dbms.h>
       
    28 #include "nssvasrvasdbsession.h" 
       
    29 #include "nssvasmgetcontextclient.h"
       
    30 #include "nssvasmgettagclient.h"
       
    31 #include "nssvasccontext.h"
       
    32 #include "nssvasctag.h"
       
    33 #include "nssvascrrd.h"
       
    34 #include "nssvascvasdbdataexchanger.h"
       
    35 #include "nssvasmvasdatabaseclient.h"
       
    36 #include "nssvascspeechitembuilder.h"
       
    37 #include "nssvasccontextbuilder.h"
       
    38 #include "nssvascvasdbeventmonitor.h"
       
    39 #include "nssvasctagreference.h"
       
    40 #include "nssvasmcoresyncrecoveryhandler.h"
       
    41 
       
    42 // CLASS DECLARATIONS
       
    43 /**
       
    44 *
       
    45 *  The CNssVasDatabase class definition. 
       
    46 * 
       
    47 *  @lib NssVASApi.lib
       
    48 *  @since 2.8
       
    49 */
       
    50 class CNssVASDatabase: public CBase 
       
    51     {
       
    52 public:
       
    53 
       
    54      /**
       
    55      * Two-phased constructor.
       
    56     */
       
    57    	static CNssVASDatabase* NewL(TInt aPriority);
       
    58     /**
       
    59     * Two-phased constructor.
       
    60     */
       
    61 	static CNssVASDatabase* NewLC(TInt aPriority);
       
    62 	/**
       
    63 	* Destructor
       
    64 	*/
       
    65 	~CNssVASDatabase();
       
    66 	// VAS Db
       
    67 	/**
       
    68     * Method to create vas database
       
    69     * @since 2.0
       
    70     * @param 
       
    71     * @return TInt a success or failure code.
       
    72     */
       
    73 	TInt CreateDb();
       
    74 	/**
       
    75     * Method to open vas database
       
    76     * @since 2.0
       
    77     * @param 
       
    78     * @return TInt a success or failure code.
       
    79     */
       
    80 	TInt OpenDatabase();
       
    81 	/**
       
    82     * Method to close vas database.
       
    83     * @since 2.0
       
    84     * @param 
       
    85     * @return void
       
    86     */
       
    87     void CloseDatabase();
       
    88 
       
    89     // ContextMgr Requests
       
    90 	/**
       
    91     * Method to determine if modelbank and lexicon ids exist.
       
    92     * @since 2.0
       
    93     * @param aModelBankId- The modelbank id
       
    94 	* @param aLexiconId - The lexicon id
       
    95     * @return TBool ETrue or EFalse.
       
    96     */
       
    97 	TBool ModelBankAndLexiconExist(TUint32 &aModelBankId, TUint32 &aLexiconId);
       
    98 	/**
       
    99     * Method to save context.
       
   100     * @since 2.0
       
   101     * @param aContext - .
       
   102     * @return TInt success or failure code.
       
   103     */
       
   104     TInt SaveContext( CNssContext* aContext, TInt& aNewContextId );
       
   105 
       
   106 	/**
       
   107     * Updates the client data of the context
       
   108     * @since 2.8
       
   109     * @param aContext - .
       
   110     * @return TInt success or failure code.
       
   111     */
       
   112     TInt SaveContextClientData(CNssContext* aContext);
       
   113 
       
   114 	/**
       
   115     * Method to get context by name
       
   116     * @since 2.0
       
   117     * @param aName -  The name of the context.
       
   118     * @return CArrayPtrFlat<CNssContext>* List of contexts.
       
   119     */
       
   120 	CArrayPtrFlat<CNssContext>* GetContext(const TDesC& aName);
       
   121 
       
   122 	/**
       
   123     * Method to get all global contexts.
       
   124     * @since 2.0
       
   125     * @return CArrayPtrFlat<CNssContext>* List of contexts.
       
   126     */
       
   127 	CArrayPtrFlat<CNssContext>* GetGlobalContexts();
       
   128 
       
   129 	/**
       
   130     * Method to get all contexts.
       
   131     * @since 2.0
       
   132     * @return CArrayPtrFlat<CNssContext>* List of contexts.
       
   133     */
       
   134 	CArrayPtrFlat<CNssContext>* GetAllContexts();
       
   135 
       
   136 	/**
       
   137     * Method to transfer context list to client side.
       
   138     * @since 2.0
       
   139     * @param 
       
   140     * @return TInt success or failure code.
       
   141     */
       
   142 	TInt TransferContextList();
       
   143 
       
   144 	/**
       
   145     * Method to delete context by name.
       
   146     * @since 2.0
       
   147     * @param aName- The name of the context to delete.
       
   148     * @return TInt success or failure code.
       
   149     */
       
   150 	TInt DeleteContext( const TDesC& aName );
       
   151 
       
   152     /**
       
   153     * Method to delete context.
       
   154     * @since 2.0
       
   155     * @param aContext-  The context to delete.
       
   156     * @return TInt success or failure code.
       
   157     */
       
   158 	TInt DeleteContext( CNssContext* aContext );
       
   159 
       
   160 	// TagMgr Requests	
       
   161 	/**
       
   162     * Method to save a tag.
       
   163     * @since 2.0
       
   164     * @param aTag The voice tag to save.
       
   165     * @return TInt sucess of failure code.
       
   166     */
       
   167 	TInt SaveTag( CNssTag* aTag, TInt& aNewId );
       
   168 
       
   169     /**
       
   170     * Method to save several tags.
       
   171     * @since 2.8
       
   172     * @param aTagArray The voice tags to save.
       
   173     * @return TInt success or failure code.
       
   174     */
       
   175     TInt SaveTags( RPointerArray<CNssTag>* aTagArray );
       
   176 
       
   177     /**
       
   178     * Method to delete several tags.
       
   179     * @since 2.8
       
   180     * @param aTagArray The voice tags to delete.
       
   181     * @return TInt success or failure code.
       
   182     */
       
   183     TInt DeleteTags( const RArray<TUint32>& aTagIdArray );
       
   184 
       
   185     /**
       
   186     * Method to get a tag by name.
       
   187     * @since 2.0
       
   188     * @param aName- The name of the voice tag.
       
   189     * @return TInt success or failure code.
       
   190     */
       
   191 	MNssTagListArray* GetTag( const TDesC& aName );
       
   192 
       
   193     /**
       
   194     * Initiate the Select Tag event.
       
   195     * @since 2.0
       
   196     * @param aTag The voice tag which was selected.
       
   197     * @return TNssRecognitionResult Return indicating request is valid.
       
   198     */
       
   199 	MNssTagListArray* GetTag( CNssContext* aContext );
       
   200     /**
       
   201     * Method to get tag by grammar id and rule id.
       
   202     * @since 2.0
       
   203     * @param aGrammarId - The grammar id of the voice tag.
       
   204 	* @param aRuleId - The rule id of the voice tag.
       
   205     * @return TInt success or failure code.
       
   206     */	
       
   207 	MNssTagListArray* GetTag( const TInt aGrammarID, const TInt aRuleID );
       
   208 	
       
   209 	/**
       
   210     * Method to tags by theirgrammar id and rule id.
       
   211     * @param aGrammarId - The grammar id of the voice tag.
       
   212 	* @param aRuleId - The rule id of the voice tag.
       
   213     * @return TInt success or failure code.
       
   214     */	
       
   215 	MNssTagListArray* GetTags( TNssGrammarIdRuleIdListArray& aGrammarIdRuleIds);
       
   216 	
       
   217     /**
       
   218     * Method to get a tag by context and name.
       
   219     * @since 2.0
       
   220     * @param aContext - The context of the tag.
       
   221 	* @param aName - The name of the tag.
       
   222     * @return TInt success or failure code.
       
   223     */	
       
   224 	MNssTagListArray* GetTag( CNssContext* aContext, const TDesC& aName );
       
   225 
       
   226     /**
       
   227     * Method to get a tag by tagid.
       
   228     * @since 2.0
       
   229     * @param aTagId - The tagid of the voice tag.
       
   230     * @return TInt success or failure code.
       
   231     */
       
   232 	MNssTagListArray* GetTag( const TUint32 aTagId );
       
   233 
       
   234    	/**
       
   235     * Method to transfer tag list to client side.
       
   236     * @since 2.0
       
   237     * @param 
       
   238     * @return TInt success or failure code.
       
   239     */
       
   240 	TInt TransferTagList();
       
   241 
       
   242     /**
       
   243     * Method to delete tag by name.
       
   244     * @since 2.0
       
   245     * @param aName- The name of the voice tag to delete.
       
   246     * @return TInt success or failure code.
       
   247     */
       
   248 	TInt DeleteTag( const TDesC& aName );
       
   249         /**
       
   250     * Initiate the Select Tag event.
       
   251     * @since 2.0
       
   252     * @param aTag The voice tag which was selected.
       
   253      * @return TInt success or failure code.
       
   254     */
       
   255 	TInt DeleteTag( CNssTag *aTag );
       
   256 	/**
       
   257     * Method to delete a tag by id
       
   258     * @since 2.0
       
   259     * @param aTagId- the tagid.
       
   260     * @return TInt success or failure code.
       
   261     */
       
   262 	TInt DeleteTag( const TUint32 aTagId );
       
   263 
       
   264 	// Event Monitoring methods
       
   265     /**
       
   266     * Method use to start monitoring vas database.
       
   267     * @since 2.0
       
   268     * @param 
       
   269     * @return void
       
   270     */
       
   271 	void StartMonitoringDatabaseL();
       
   272 	/**
       
   273     * Method use to add observers to vas database. 
       
   274     * @since 2.0
       
   275     * @param aObserver- An observer of vas database.
       
   276     * @return none
       
   277     */
       
   278 	void AddObserverL( MNssVASDatabaseObserver* aObserver );
       
   279 	/**
       
   280     * Method used to stop observering vas database.
       
   281     * @since 2.0
       
   282     * @param aObserver- The observer to remove.
       
   283     * @return TInt success or failure code.
       
   284     */
       
   285 	TInt RemoveObserver( MNssVASDatabaseObserver* aObserver );
       
   286 
       
   287 	/**
       
   288 	* Method to determine if tags exist for a context
       
   289 	* @since 2.0
       
   290 	* @param aContext - The context to check tags for.
       
   291 	* @return TBool ETrue or EFalse
       
   292 	*/
       
   293     TBool TagExist( CNssContext* aContext );
       
   294 
       
   295     /**
       
   296 	* Method to get the number of tags for a context
       
   297 	* @since 2.0
       
   298 	* @param aContext - The context to check tags for.
       
   299 	* @return TInt
       
   300 	*/
       
   301     TInt TagCount( CNssContext* aContext );
       
   302 
       
   303     /**
       
   304 	* Method to get tags based on a rrd int value and position
       
   305 	* @since 2.0
       
   306 	* @param aNum - The rrd int value
       
   307 	* @param aPosition - The int value position in the rrd intarray
       
   308 	*/
       
   309 	MNssTagListArray* GetTagList( CNssContext* aContext, TInt aNum, TInt aPosition );
       
   310 
       
   311 	/**
       
   312 	* Method to get tags based on a rrd text value and position
       
   313 	* @since 2.0
       
   314 	* @param aText - The rrd text value
       
   315 	* @param aPosition - The text value position in the rrd textarray
       
   316 	*/
       
   317     MNssTagListArray* GetTagList( CNssContext* aContext, TDesC& aText, TInt aPosition );
       
   318 
       
   319 	CArrayPtrFlat<MNssTagReference>* GetTagReferenceList( CNssContext* aContext );
       
   320 
       
   321 	TInt TransferTagReferenceList();
       
   322 
       
   323     /**
       
   324     * Method to get the default model bank id
       
   325     * @since 2.8
       
   326     * @param aId reference where to put the model bank Id
       
   327     * @return symbian-wide error code
       
   328     */
       
   329     TInt GetDefaultModelBankId( TUint32& aId );
       
   330 
       
   331     /**
       
   332     * Modifies the context table so that all contexts start using
       
   333     * the new id as their model bank id.
       
   334     * @since 2.8
       
   335     * @param aNewId new model bank id
       
   336     * @return symbian-wide error code
       
   337     */
       
   338     TInt ResetModelBank( TUint32 aNewId );
       
   339 
       
   340     /**
       
   341     * Changes the Rule ID of some tags.
       
   342     * When an already trained tag is retrained, the Rule ID changes.
       
   343     * This function updates the change to VAS DB.
       
   344     * @since 2.8
       
   345     * @param aNewId new model bank id
       
   346     * @return symbian-wide error code
       
   347     */
       
   348     TInt UpdateTagRuleIDs( const RArray<TNssSpeechItem>& aRetrainedTags );
       
   349 
       
   350 private:
       
   351 
       
   352 	// C++ constructor
       
   353     CNssVASDatabase(TInt aPriority);
       
   354     // 2nd phase construction.
       
   355     void ConstructL ();
       
   356     
       
   357     void ConvertTNssTagRefToMNssTagRefL( TNssTagReferenceListArray* aTNssTagRef,
       
   358                                          CArrayPtrFlat<MNssTagReference>* aCNssTagRef);
       
   359     MNssVASDatabaseClient::TNssVASDBClientReturnCode  ConvertDBError(TInt aError);
       
   360 
       
   361 
       
   362     // Pointer to the object, which makes the actual operations on database.
       
   363     CNssVasDb* iVasDb;
       
   364 
       
   365     // How many VAS instances in this thread have connected.
       
   366     TInt iConnected;
       
   367 
       
   368     //Current state
       
   369     TInt				         iState;
       
   370     //Grammar and rule data passed to server
       
   371     TNssGrammarIdRuleId          iTNssGrammarIdRuleId;
       
   372     //Package for grammar and rule data
       
   373     TPckgCTNssGrammarIdRuleId*   iGrammarIdRuleIdPackage;
       
   374     //Taglist returned to client
       
   375     CArrayPtrFlat<CNssTag>*      iCNssTagList;
       
   376     //Contextlist returned to client
       
   377     CArrayPtrFlat<CNssContext>*  iCNssContextList;
       
   378     //Tag id
       
   379     TUint32                   iTagId;
       
   380     //Contextbuilder used to create contexts
       
   381     CNssContextBuilder*          iContextBuilder;
       
   382     //SpeechItembuilder used to create speechitems
       
   383     CNssSpeechItemBuilder*       iSpeechItemBuilder;
       
   384     //RRD int array data
       
   385     //TNssRRDIntArray*             iRRDIntArray;
       
   386     //RRD text array data
       
   387     //TNssRRDTextArray*            iRRDTextArray;
       
   388     //EventMonitor for vas db
       
   389     CNssVASDBEventMonitor*		 iVASDBEventMonitor;
       
   390 
       
   391     TNssTagReferenceListArray*       iTNssTagRefList;
       
   392     CArrayPtrFlat<CNssTagReference>* iCNssTagRefList;
       
   393 
       
   394     enum TState  //events
       
   395         {
       
   396         EStateGetContext = 0,
       
   397 	    EStateTransferContext,
       
   398 	    EStateGetTag,
       
   399 	    EStateTransferTag,
       
   400 	    EStateDeleteContext,
       
   401 	    EStateDeleteTag,
       
   402 	    EStateSaveContext,
       
   403 	    EStateSaveTag,
       
   404 	    EStateGetTagReference,
       
   405 	    EStateTransferTagReference
       
   406         };
       
   407 
       
   408     // Flag: Is the database locked
       
   409     TBool iIsLocked;
       
   410     };
       
   411 
       
   412 #endif