wmdrm/wmdrmengine/wmdrmserver/server/inc/wmdrmdb.h
changeset 0 95b198f216e5
child 22 ad2863178d17
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2008 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:  WMDRM database access interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_WMDRMDB_H
       
    20 #define C_WMDRMDB_H
       
    21 
       
    22 #include <sqldb.h>
       
    23 #include "wmdrmserver.h"
       
    24 /**
       
    25  *  Interface class to wmdrm database
       
    26  *
       
    27  *  @since S60 v3.2
       
    28  */
       
    29 class CWmDrmDb : public CTimer
       
    30     {
       
    31 public:
       
    32 
       
    33     /** table type */
       
    34     enum TWmDrmTableType
       
    35         {
       
    36         EWmDrmLicenseTable,
       
    37         EWmDrmSecureTable,
       
    38         EWmDrmSyncTable,
       
    39         EWmDrmMeteringTable
       
    40         };
       
    41         
       
    42     static CWmDrmDb* NewL( CWmDrmServer* aServer );
       
    43     static CWmDrmDb* NewLC( CWmDrmServer* aServer );
       
    44 
       
    45     virtual ~CWmDrmDb();
       
    46 
       
    47     void InitStoreL( 
       
    48         const TDesC8& aStore,
       
    49         TBool aCreateIfMissing );
       
    50     
       
    51     void InitNameSpaceL( 
       
    52         const TDesC8& aStore,
       
    53         const TDesC8& aNamespace,
       
    54         TBool aCreateIfMissing );
       
    55 
       
    56     void RemoveStoreL( const TDesC8& aStore );
       
    57 
       
    58     void RemoveNameSpaceL( 
       
    59         const TDesC8& aStore,
       
    60         const TDesC8& aNamespace );
       
    61     
       
    62     void DeleteLicenseStoreL();
       
    63 
       
    64     void CreateRecordL(  
       
    65         const TDesC8& aStore,
       
    66         const TDesC8& aNamespace,
       
    67         const TDesC8& aHashKey,
       
    68         const TDesC8& aUniqueKey,
       
    69         const TInt&   aSize );
       
    70 
       
    71     void ReadRecordL( 
       
    72         const TDesC8& aStore,
       
    73         const TDesC8& aNamespace,
       
    74         const TDesC8& aHashKey,
       
    75         const TDesC8& aUniqueKey );
       
    76 
       
    77     void GetDataSizeL( TInt& aDataSize );
       
    78 
       
    79     void DeleteData();
       
    80 
       
    81     void DeleteRecordL(  
       
    82         const TDesC8& aStore,
       
    83         const TDesC8& aNamespace,
       
    84         const TDesC8& aHashKey,
       
    85         const TDesC8& aUniqueKey );
       
    86 
       
    87     void ReadDataL( TDes8& aData );
       
    88 
       
    89     void WriteDataL(  
       
    90         const TDesC8& aStore,
       
    91         const TDesC8& aNamespace,
       
    92         const TDesC8& aHashKey,
       
    93         const TDesC8& aUniqueKey, 
       
    94         TDesC8& aData );
       
    95     
       
    96     void EnumerateDataL(  
       
    97         const TDesC8& aStore,
       
    98         const TDesC8& aNamespace,
       
    99         const TDesC8& aHashKey,
       
   100         RPointerArray<HBufC8>& aUniqueKeyEntries );
       
   101     
       
   102     void EnumerateNameSpaceStartL(  
       
   103         const TDesC8& aStore,
       
   104         const TDesC8& aNamespace );
       
   105     
       
   106     void EnumerateNameSpaceNextL(  
       
   107         TBuf8<KWmDrmIdSize>& aHashKey,
       
   108         TBuf8<KWmDrmIdSize>& aUniqueKey );
       
   109 
       
   110     TInt DataBaseSize( TBool aConfiguredDrive );
       
   111 
       
   112 
       
   113 protected: // from base class CActive
       
   114     void RunL();
       
   115     TInt RunError( TInt aError );
       
   116 
       
   117 private: // from base class CActive
       
   118 
       
   119 private:
       
   120     CWmDrmDb( CWmDrmServer* aServer );
       
   121     void ConstructL();
       
   122     
       
   123     void CreateDatabaseL( TFileName& aFileNamePath, RSqlDatabase& aDatabase, TBool aConfiguredDrive );
       
   124     void CreateTableL( TWmDrmTableType aTableType, RSqlDatabase& aDatabase );
       
   125     void DeleteTableL( TWmDrmTableType aTableType );
       
   126     void SelectNRecordsWithRowIdL( TWmDrmTableType aTableType, TInt aNumber, RArray<TInt64>& aArray );
       
   127     void DeleteRecordsWithRowIdsL( TWmDrmTableType aTableType, RArray<TInt64>& aArray );
       
   128     void DropTableL( TWmDrmTableType aTableType );
       
   129     TWmDrmTableType TableTypeL( const TDesC8& aNamespace );
       
   130     void OpenDatabaseL( TFileName& aFileNamePath, RSqlDatabase& aDatabase, TBool aConfiguredDrive );
       
   131     
       
   132     void ConvertOldLicenseStoreL();
       
   133     
       
   134     // Checks how many SQL statements are prepared (buffered) currently and if either the maximum 
       
   135     // amount of buffered statements is exceeded or an enforced commit is needed, COMMITs the 
       
   136     // statements. The method also starts a new BEGIN statement after the commit operation to 
       
   137     // start a new buffering round of SQL statements. This method also controls a timer for 
       
   138     // triggering enforced commit after a predefined idle period without any prepared SQL statements. 
       
   139     void CheckDatabaseCommitL( TBool aEnforcedCommit );
       
   140     void Activate();
       
   141 
       
   142 private: // data
       
   143 
       
   144     // Not owned
       
   145     CWmDrmServer* iServer;
       
   146     
       
   147     // Located in the system drive
       
   148     RSqlDatabase    iDatabase;
       
   149     // Located in the configured drive (internal mass drive)
       
   150     RSqlDatabase    iDatabase2;
       
   151 
       
   152     HBufC8* iData;
       
   153     
       
   154     RSqlStatement iEnumerateNamespaceStmt;
       
   155     TInt iEnumerateNamespaceHashKeyColumnIndex;
       
   156     TInt iEnumerateNamespaceUniqueKeyColumnIndex;
       
   157     TBool iEnumerateNamespaceStarted;
       
   158     
       
   159     // Path in the system drive for the data base
       
   160     TFileName iDatabasePath;
       
   161     // Path in the internal mass drive (configured drive)
       
   162     TFileName iDatabasePath2;
       
   163     
       
   164     // Whether WM DRM rights storing location is found to be
       
   165     // configured to the internal mass drive or not
       
   166     TBool iWmDrmRightsConfigFound;
       
   167     
       
   168     // Amount of cached database import, update or delete operations that will be committed
       
   169     // to the database when certain conditions are met.
       
   170     TInt iAmountOperationsWithoutCommit;
       
   171     
       
   172     // When the flag is on, an SQL BEGIN statement has been issued, but not committed 
       
   173     // with COMMIT statement. The first one is for the database on the system drive and the 
       
   174     // second one is for the database on the configured drive. 
       
   175     TBool iSqlTransactionOngoing;
       
   176     TBool iSqlTransactionOngoing2;
       
   177     
       
   178     };
       
   179 
       
   180 #endif // ? C_CLASSNAME_H