srsf/nssvasapi/nssvasdb/inc/nssvasrvasdbsession.h
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2002-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:  RVasDbSession is the client-side(proxy) interface through which 
       
    15 *               communication with the vasdb server is channelled.
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef RNSSVASDBSESSION_H
       
    20 #define RNSSVASDBSESSION_H
       
    21 
       
    22 
       
    23 #include "nssvascvasdbsrvdef.h"
       
    24 #include "nssvasdbkonsts.h"
       
    25 #include "nssvascvasdbdataexchanger.h"
       
    26 #include "nssvasccontext.h"
       
    27 #include "nssvasccontext.h"
       
    28 #include "nssvasctag.h"
       
    29 #include "nssvascvasdb.h"
       
    30 
       
    31 // FORWARD DECLARATIONS
       
    32 class CNssVasDb;
       
    33 
       
    34 // CLASS DECLARATION
       
    35 
       
    36 /**
       
    37 *
       
    38 *  The RVasDbSession class definition. 
       
    39 * 
       
    40 *  @lib NssVASApi.lib
       
    41 *  @since 2.0
       
    42 */
       
    43 class RNssVasDbSession
       
    44     {
       
    45 	// Functions
       
    46 public:
       
    47 
       
    48     /**
       
    49     * C++ 1st phase constructor
       
    50     */
       
    51 	RNssVasDbSession();	
       
    52 
       
    53     /**
       
    54     * C++ destructor
       
    55     */
       
    56     ~RNssVasDbSession();
       
    57 	
       
    58     /**
       
    59     * A method to create a new database. The name of the database file
       
    60     * is read from a resource file (NssVasResource.rsc).
       
    61     * @since 2.8
       
    62     * @return KErrNone or a Symbian-wide error code.
       
    63     */
       
    64 	TInt  CreateDatabase();
       
    65 
       
    66     /**
       
    67     * A method to open the database. The name of the database file
       
    68     * is read from a resource file (NssVasResource.rsc).
       
    69     * @since 2.8
       
    70     * @return KErrNone or a Symbian-wide error code.
       
    71     */
       
    72 	TInt  OpenDatabase();	
       
    73 
       
    74     /**
       
    75     * A method to close the database.
       
    76     * @since 2.8
       
    77     * @return KErrNone or a Symbian-wide error code.
       
    78     */
       
    79 	TInt  CloseDatabase ();
       
    80 
       
    81     /**
       
    82     * A method to get the model bank id and lexicon id.
       
    83     * @since 2.8
       
    84     * @param aModelBankId Model Bank ID will be returned here.
       
    85     * @param aLexiconId Lexicon ID will be returned here.
       
    86     * @return ETrue if success, otherwise EFalse.
       
    87     */
       
    88     TBool ModelBankIdLexiconId( TUint32 &iModelBankId, TUint32 &iLexiconId );
       
    89 
       
    90     /**
       
    91     * A method to check whether a context is empty or not.
       
    92     * @since 2.8
       
    93     * @param aContextId Unique identifier of the context.
       
    94     * @return ETrue if there are tags, EFalse if the context is empty.
       
    95     */
       
    96     TBool TagExist( TInt aContextId );
       
    97 
       
    98     /**
       
    99     * Method to return the number of tags in a context.
       
   100     * @since 2.8
       
   101     * @param aContextId Unique identifier of the context.
       
   102     * @return KErrNone or a Symbian-wide error code.
       
   103     */
       
   104     TInt  TagCount( TInt aContextId );
       
   105 	
       
   106     /**
       
   107     * Method to save a context. When a context is saved, a context ID is 
       
   108     * assigned to it. The newly assigned ID is returned
       
   109     * in the reference parameter.
       
   110     * @since 2.8
       
   111     * @param aContext Data of the context.
       
   112     * @param aContextId Reference for returning the newly assigned context ID.
       
   113     * @return KErrNone or a Symbian-wide error code.
       
   114     */
       
   115     //TInt SaveContext( TNssContext& aContext, TInt& aContextId );
       
   116 	TInt SaveContext( CNssContext& aContext, TInt& aContextId );
       
   117     
       
   118     /**
       
   119     * Method to delete a context from the database.
       
   120     * @since 2.8
       
   121     * @param aName Name of the context to be deleted. 
       
   122     * @return KErrNone or a Symbian-wide error code.
       
   123     */
       
   124     TInt DeleteContext( const TDesC& aName );
       
   125 
       
   126     /**
       
   127     * Method to update the data of a context.
       
   128     * @since 2.8
       
   129     * @param aContext the context in serialized form.
       
   130     * @return KErrNone or a Symbian-wide error code.
       
   131     */
       
   132 	//TInt UpdateContext( TNssContext& aContext );
       
   133 	TInt UpdateContext( CNssContext& aContext );
       
   134 
       
   135     /**
       
   136     * Method to update the client data of a context.
       
   137     * @since 2.8
       
   138     * @param aContext the context in serialized form.
       
   139     * @return KErrNone or a Symbian-wide error code.
       
   140     */
       
   141     //TInt UpdateContextClientData( TNssContext& aContext );
       
   142     TInt UpdateContextClientData( CNssContext& aContext );
       
   143 
       
   144     /**
       
   145     * Method to get a context by name.
       
   146     * @since 2.8
       
   147     * @param aName Name of the context
       
   148     * @return Array containing the context, or NULL if it is not found.
       
   149     */
       
   150     //TNssContextListArray* GetContextByName( const TDesC& aName );
       
   151     CArrayPtrFlat<CNssContext>* GetContextByName( const TDesC& aName );
       
   152 
       
   153     /**
       
   154     * Method to list all global contexts.
       
   155     * @since 2.8
       
   156     * @return Array containing all global contexts.
       
   157     */
       
   158     //TNssContextListArray* GetGlobalContexts();
       
   159     CArrayPtrFlat<CNssContext>* GetGlobalContexts();
       
   160 
       
   161     /**
       
   162     * Method to list all contexts.
       
   163     * @since 2.8
       
   164     * @return Array containing all contexts.
       
   165     */
       
   166     //TNssContextListArray* GetAllContexts();
       
   167     CArrayPtrFlat<CNssContext>* GetAllContexts();
       
   168 
       
   169     /**
       
   170     * Method to save a tag. During saving, a Tag ID is assigned for the tag.
       
   171     * This ID is returned in the refrence parameter.
       
   172     * @since 2.8
       
   173     * @param aTag Tag
       
   174     * @param aNewId This variable is used to return the newly asssigned
       
   175     *               Tag ID for the user.
       
   176     * @return KErrNone or a Symbian-wide error code.
       
   177     */
       
   178 	//TInt SaveTag( TNssTag& aTag, TInt& aNewId );
       
   179 	TInt SaveTag( CNssTag& aTag, TInt& aNewId );
       
   180 
       
   181     /**
       
   182     * Method to save a group of tags. During saving, a Tag IDs are assigned
       
   183     * for the tags. These IDs is returned in the aTagIdArray.
       
   184     * @since 2.8
       
   185     * @param aTagArray An array of previously unsaved tags.
       
   186     * @param aTagIdArray Empty array, which will be filled with
       
   187     *                    newly assigned Tag IDs.
       
   188     * @return KErrNone or a Symbian-wide error code.
       
   189     */
       
   190 	//TInt SaveTags( CArrayFixFlat<TNssTag>* aTagArray, RArray<TInt>& aTagIdArray );
       
   191 	TInt SaveTags( CArrayPtrFlat<CNssTag>* aTagArray, RArray<TInt>& aTagIdArray );
       
   192 
       
   193     /**
       
   194     * Method to delete a tag by name
       
   195     * @since 2.8
       
   196     * @param aTagName Trained text of the tag ( MNssSpeechItem::SetTextL() )
       
   197     * @return KErrNone or a Symbian-wide error code.
       
   198     */
       
   199     TInt DeleteTag( const TDesC& aTagName );
       
   200 
       
   201     /**
       
   202     * Method to delete a tag.
       
   203     * @since 2.8
       
   204     * @param aTagId Tag identifier.
       
   205     * @return KErrNone or a Symbian-wide error code.
       
   206     */
       
   207     TInt DeleteTag( TInt aTagId );
       
   208 
       
   209     /**
       
   210     * Method to delete a group of tags.
       
   211     * @since 2.8
       
   212     * @param aTagIdArray Array of tag identifiers.
       
   213     * @return KErrNone or a Symbian-wide error code.
       
   214     */
       
   215 	TInt DeleteTags( const RArray<TUint32>& aTagIdArray );
       
   216 
       
   217     /**
       
   218     * Method to update the information of an existing tag.
       
   219     * @since 2.8
       
   220     * @param aTag New information about the tag
       
   221     * @return KErrNone or a Symbian-wide error code.
       
   222     */
       
   223 	//TInt UpdateTag( const TNssTag& aTag );
       
   224 	TInt UpdateTag( const CNssTag& aTag );
       
   225 
       
   226     /**
       
   227     * Method to get references to all tags in a context.
       
   228     * @since 2.8
       
   229     * @param aContextId Context identifier.
       
   230     * @return Array containing references to all tags.
       
   231     */
       
   232 	TNssTagReferenceListArray* GetTagReferenceList( TInt aContextId );
       
   233 
       
   234     /**
       
   235     * Method to get all tags in a context.
       
   236     * @since 2.8
       
   237     * @param aContext The context
       
   238     * @return Array containing all tags in the context
       
   239     */
       
   240     //TNssTagListArray* GetTag( const TNssContext& aContext );
       
   241     CArrayPtrFlat<CNssTag>* GetTag( const CNssContext& aContext );
       
   242 
       
   243     /**
       
   244     * Method to get a tag by grammar ID and rule ID.
       
   245     * @since 2.8
       
   246     * @param aGrammarIdRuleId Structure containing the Grammar ID (which
       
   247     *                         specifies a context) and Rule ID (which
       
   248     *                         specifies a tag inside a context).
       
   249     * @return Array containing the matching tag or NULL.
       
   250     */
       
   251     //TNssTagListArray* GetTag( TNssGrammarIdRuleId aGrammarIdRuleId );
       
   252     CArrayPtrFlat<CNssTag>* GetTag( TNssGrammarIdRuleId aGrammarIdRuleId );
       
   253     
       
   254     /**
       
   255     * Method to get tags by their grammar ID and rule ID.
       
   256     * @since 2.8
       
   257     * @param aGrammarIdRuleIds Structure containing the Grammar IDs (that
       
   258     *                          specify a context) and Rule IDs (that
       
   259     *                          specify a tag inside a context).
       
   260     * @return Array containing the matching tags or NULL.
       
   261     */
       
   262     //TNssTagListArray* GetTags( TNssGrammarIdRuleIdListArray& aGrammarIdRuleIds );
       
   263     CArrayPtrFlat<CNssTag>* GetTags( TNssGrammarIdRuleIdListArray& aGrammarIdRuleIds );
       
   264 
       
   265     /**
       
   266     * Method to get a tag by name (CNssSpeechItem::SetText).
       
   267     * @since 2.8
       
   268     * @param aName Tag's trained text.
       
   269     * @return Array containing all matching tags.
       
   270     */
       
   271 	//TNssTagListArray* GetTag( const TDesC& aName );
       
   272 	CArrayPtrFlat<CNssTag>* GetTag( const TDesC& aName );
       
   273 
       
   274     /**
       
   275     * Method to get a tag by RRD data, given RRD integer and the position (0-4)
       
   276     * to which the integer is compared.
       
   277     * @since 2.8
       
   278     * @param aContextId ID of the context, to which the tag belongs.
       
   279     * @param aNum Integer, which should match the RRD integer.
       
   280     * @param aPosition RRD integer array position (0-4).
       
   281     * @return Array containing all matching tags.
       
   282     */
       
   283 	//TNssTagListArray* GetTag( TInt aContextId, TInt aNum, TInt aPosition );
       
   284 	CArrayPtrFlat<CNssTag>* GetTag( TInt aContextId, TInt aNum, TInt aPosition );
       
   285 
       
   286     /**
       
   287     * Method to get a tag by RRD data, given RRD text and the position (0-4)
       
   288     * to which the text is compared.
       
   289     * @since 2.8
       
   290     * @param aContextId ID of the context, to which the tag belongs.
       
   291     * @param aText Text, which should match the RRD text.
       
   292     * @param aPosition RRD text array position (0-4).
       
   293     * @return Array containing all matching tags.
       
   294     */
       
   295 	//TNssTagListArray* GetTag( TInt aContextId, TDesC& aText, TInt aPosition );
       
   296 	CArrayPtrFlat<CNssTag>* GetTag( TInt aContextId, 
       
   297 	                                const TDesC& aText, TInt aPosition );
       
   298 
       
   299     /**
       
   300     * Method to get a tag, given the tag ID.
       
   301     * @since 2.8
       
   302     * @param aTagId The ID of the tag.
       
   303     * @return Array containing the tag or NULL.
       
   304     */
       
   305 	//TNssTagListArray* GetTag( TUint32 aTagId );
       
   306 	CArrayPtrFlat<CNssTag>* GetTag( TUint32 aTagId );
       
   307 
       
   308     /**
       
   309     * Method to update the Rule IDs of some tags.
       
   310     * @since 2.8
       
   311     * @param aRetrainedTags Array of tags with changed Rule IDs
       
   312     * @return symbian-wide error code
       
   313     */
       
   314     TInt UpdateTagRuleIDs( const RArray<TNssSpeechItem>& aRetrainedTags );
       
   315 
       
   316     /**
       
   317     * Method to get the default model bank id
       
   318     * @since 2.8
       
   319     * @param aId reference where to put the model bank Id
       
   320     * @return symbian-wide error code
       
   321     */
       
   322     TInt GetDefaultModelBankId( TUint32& aId );
       
   323 
       
   324     /**
       
   325     * Modifies the context table so that all contexts start using
       
   326     * the new id as their model bank id.
       
   327     * @since 2.8
       
   328     * @param aNewId new model bank id
       
   329     * @return symbian-wide error code
       
   330     */
       
   331     TInt ResetModelBank( TUint32 aNewId );
       
   332 
       
   333 private:
       
   334 
       
   335     // Pointer to the object, which makes the actual operations on database.
       
   336     CNssVasDb* iVasDb;
       
   337 
       
   338     // How many VAS instances in this thread have connected.
       
   339     TInt iConnected;
       
   340     };
       
   341 
       
   342 #endif