srsf/sisrscontrollerplugin/src/sidatabase.h
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2004-2007 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 implements the SI Controller Plugin database.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef SIDATABASE_H
       
    21 #define SIDATABASE_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <d32dbms.h>
       
    25 #include <e32svr.h>
       
    26 #include <sysutil.h> // Critical Level check
       
    27 #include <f32file.h>
       
    28 
       
    29 
       
    30 class CNssBackupObserver;
       
    31 
       
    32 // CLASS DECLARATION
       
    33 
       
    34 /**
       
    35 *  This class is the base class for all SI Controller Plugin DB classes.
       
    36 *  It provides the common functionality for the DB classes.
       
    37 *
       
    38 *  @lib SIControllerPlugin.lib
       
    39 *  @since 2.8
       
    40 */
       
    41 class CSIDatabase : public CBase
       
    42     {
       
    43     public:  // Constructors and destructor
       
    44 
       
    45         /**
       
    46         * Two-phased constructor.
       
    47         */
       
    48         static CSIDatabase* NewL(TFileName aDatabaseFileName);
       
    49 
       
    50  		/**
       
    51         * Destructor.
       
    52         */
       
    53         virtual ~CSIDatabase();
       
    54 
       
    55     public: // New functions
       
    56 
       
    57         /**
       
    58         * Begins a database transaction if not already.
       
    59         * @since 2.8
       
    60         * @return	Reference to the database.
       
    61         */
       
    62 		void BeginTransactionL();
       
    63 
       
    64         /**
       
    65         * Commits all changes to the database.
       
    66         * @since 2.8
       
    67         */
       
    68 		void CommitChangesL( TBool aCompact );
       
    69 
       
    70         /**
       
    71         * Rollback all changes to the database.
       
    72         * @since 2.8
       
    73         */
       
    74 		void Rollback();
       
    75 
       
    76         /**
       
    77         * Checks to see if ID tables exist.
       
    78         * @since 2.8
       
    79         * @return	ETrue if ID tables exist; EFalse otherwise.
       
    80         */
       
    81 		TBool DoIDTablesExistL();
       
    82 
       
    83         /**
       
    84         * @todo Add comments
       
    85         */
       
    86         TBool DoesLockTableExistL();
       
    87 
       
    88         /**
       
    89         * @todo Add comments
       
    90         */
       
    91         TBool DoesModelBankTableExistL();
       
    92 
       
    93         /**
       
    94         * @todo Add comments
       
    95         */
       
    96         TBool DoesLexiconTableExistL();
       
    97 
       
    98         /**
       
    99         * @todo Add comments
       
   100         */
       
   101         TBool DoesGrammarTableExistL();
       
   102 
       
   103 
       
   104         /**
       
   105         * Returns a reference to the database.
       
   106         * @since 2.8
       
   107         * @return	Reference to the database.
       
   108         */
       
   109 		RDbNamedDatabase& SIDatabase();
       
   110 
       
   111         /**
       
   112         * Returns a reference to DB session.
       
   113         * @since 2.8
       
   114         * @return	Reference to the database.
       
   115         */
       
   116 		RDbs& DbSession();
       
   117 
       
   118         /**
       
   119         * Returns a drive for DB file.
       
   120         * @since 2.8
       
   121         * @return	Reference to the session.
       
   122         */
       
   123 		TInt DbDrive();
       
   124 
       
   125         /**
       
   126         * Creates a small table to the database. Writing of this table is tried
       
   127         * when acquiring for a write lock.
       
   128         */
       
   129         void CreateLockTableL();
       
   130 
       
   131 		/**
       
   132 		* Permit transactions. Used when e.g. backup or restore begins 
       
   133 		* @since 3.1
       
   134 		*/
       
   135 		void LockTransactionsL();
       
   136 
       
   137 		/**
       
   138 		* Allow transactions. Used when e.g. backup or restore ends 
       
   139 		* @since 3.1
       
   140 		*/
       
   141 		void UnlockTransactionsL();
       
   142 		
       
   143         /**
       
   144         * Opens a database session.  If database file doesn't exist, it creates one.
       
   145         * @since 2.8
       
   146         */
       
   147         void OpenDatabaseL();
       
   148         
       
   149         /**
       
   150 	    * Close database.
       
   151 	    * @since 3.1
       
   152 	    * @return Symbian-wide error codes
       
   153 	    */
       
   154 		TInt  CloseDatabase();
       
   155 		
       
   156      private:
       
   157 
       
   158         /**
       
   159         * C++ default constructor.
       
   160         */
       
   161         CSIDatabase(TFileName aDbFileName);
       
   162 
       
   163         /**
       
   164         * By default Symbian 2nd phase constructor is private.
       
   165         */
       
   166         void ConstructL();
       
   167 
       
   168         /**
       
   169         * Creates a new database file.
       
   170         * @since 2.8
       
   171         */
       
   172 		void CreateDatabaseL();
       
   173 
       
   174 
       
   175 
       
   176 
       
   177     public:    // Data
       
   178 
       
   179 		// Database session
       
   180 		RDbs iDbSession;
       
   181 
       
   182 		// Database
       
   183         RDbNamedDatabase iDb;
       
   184 
       
   185 		// Indication for outstanding transaction by this client
       
   186 		TBool iOpenTransaction;
       
   187 
       
   188 		// Name of the database file	
       
   189 		TFileName iDatabaseFileName;
       
   190 
       
   191         // drive for the database file
       
   192         TInt iDatabaseDrive;
       
   193 
       
   194         // Indication if database connection is open
       
   195         TBool iDatabaseOpen;
       
   196 
       
   197         // Mutex for DB write lock
       
   198         // Makes sure that only one process gets the DB lock
       
   199         RMutex iMutex; 
       
   200         
       
   201         // Critical section is used in locking transactions inside one object
       
   202         RCriticalSection iCriticalSection;
       
   203         
       
   204         // backup and restore observer
       
   205         CNssBackupObserver* iBackupObserver;
       
   206         
       
   207     };
       
   208 
       
   209 #endif // SIDATABASE_H
       
   210 
       
   211 // End of File