applicationmanagement/omascomoadapter/inc/omascomoadapterdb.h
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Implementation of applicationmanagement components
       
    15  *
       
    16 */
       
    17 
       
    18 #ifndef __SCOMOADAPTERDB_H
       
    19 #define __SCOMOADAPTERDB_H
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include <d32dbms.h>
       
    26 #include <f32file.h>
       
    27 #include <SyncMLDef.h>
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // null final result value
       
    32 const TInt KAMNullResult = 0;
       
    33 
       
    34 // Database name & location
       
    35 const TInt KAMAdapterDbDrive = EDriveC;
       
    36 const TUid KAMPolicyUID =
       
    37     {
       
    38     0x20021335
       
    39     };
       
    40 const TInt KAMMaxPkgURLLength( 2048);
       
    41 const TInt KAMMaxPkgNameLength( 80);
       
    42 const TInt KAMMaxPkgVersionLength( 80);
       
    43 
       
    44 _LIT( KDBMSSecureID, "secure[20021335]" );
       
    45 
       
    46 _LIT( KAMAdapterDbName, "c:TARMAppMgmtAdapterDB.db" );
       
    47 
       
    48 // Table and column names
       
    49 _LIT( KTableAMMgmtObject, "AMMgmtObject" );
       
    50 _LIT( KAMMgmtObjectId, "Id" );
       
    51 _LIT( KAMMgmtObjectProfileId, "ProfileId" );
       
    52 _LIT( KAMMgmtObjectServerId, "ServerId" );
       
    53 _LIT( KAMMgmtObjectRetryCount, "RetryCount");
       
    54 
       
    55 // SQL statements
       
    56 _LIT( KCreateAMMgmtObjectTable, "CREATE TABLE AMMgmtObject ( Id \
       
    57 COUNTER NOT NULL,  ProfileId INTEGER, ServerId CHAR(%d), RetryCount INTEGER" );
       
    58 
       
    59 _LIT( KGetAMMgmtObject, "SELECT * FROM AMMgmtObject WHERE Id = %d" );
       
    60 
       
    61 _LIT( KGetUnfinishedAMMgmtObjectByServerId, "SELECT * FROM AMMgmtObject \
       
    62 WHERE Id = %d AND ServerId = '%S'" );
       
    63 
       
    64 _LIT( KDeleteAMMgmtObject,"DELETE FROM AMMgmtObject WHERE Id = %d");
       
    65 
       
    66 // Max. lengths of string fields in AMMgmtObject
       
    67 const TInt KMaxMgmtUriLength = 60;
       
    68 const TInt KMaxServerIdLength = 150;
       
    69 const TInt KMaxCorrelatorLength = 150;
       
    70 
       
    71 // Estimate of url size used in max row size (OOD checks)
       
    72 const TInt KPkgURLLengthEstimate = 350;
       
    73 
       
    74 // space needed for above integers in buffer
       
    75 const TInt KAMMgmtObjectIntLength = 4;
       
    76 
       
    77 // space needed for an integer in buffer
       
    78 const TInt KAMMgmtObjectIntegerLength = 10;
       
    79 
       
    80 // Size of empty AM database in bytes (+ additional treshold)
       
    81 const TInt KAMAdapterEmptyDbSize = 350;
       
    82 
       
    83 // Estimated maximum size of AMMgmtObject table row (+ additional treshold)
       
    84 const TInt KMaxAMMgmtObjectRowSize = KAMMaxPkgNameLength
       
    85         + KAMMaxPkgVersionLength + KPkgURLLengthEstimate + KMaxMgmtUriLength
       
    86         + KMaxServerIdLength + KMaxCorrelatorLength + 115;
       
    87 
       
    88 // TYPEDEFS
       
    89 typedef TInt TDmAMObjectId;
       
    90 typedef RArray<TDmAMObjectId> RDmAMObjectArray;
       
    91 
       
    92 _LIT(NCol1, "Id");
       
    93 _LIT(NCol2, "LUID");
       
    94 _LIT(NCol3, "ProfileId");
       
    95 _LIT(NCol4, "ServerId");
       
    96 _LIT(NCol5, "Correlator");
       
    97 _LIT(NCol6, "SourceURI");
       
    98 _LIT(NCol7, "RetryCount");
       
    99 
       
   100 class CAMDbItem : public CBase
       
   101     {
       
   102 public:
       
   103     static CAMDbItem* NewL();
       
   104     ~CAMDbItem();
       
   105 
       
   106     TInt id;
       
   107     TUint32 iLUID;
       
   108     TInt iProfileId;
       
   109 
       
   110     HBufC8* iServerID;
       
   111     HBufC8* iCorrelator;
       
   112     HBufC8* iSourceURI;
       
   113     TInt iRetryCount;
       
   114 
       
   115     };
       
   116 
       
   117 // CLASS DECLARATION
       
   118 
       
   119 /**
       
   120  *  CSCOMOAdapterDb provides an interface for accessing AM database.
       
   121  *  
       
   122  *  @lib SCOMOAdapter.lib
       
   123  *  
       
   124  */
       
   125 class CSCOMOAdapterDb : public CBase
       
   126     {
       
   127 
       
   128 public:
       
   129 
       
   130     /**
       
   131      * Two-phased constructor.
       
   132      * @return A pointer to the newly created instance.
       
   133      */
       
   134     static CSCOMOAdapterDb* NewL();
       
   135 
       
   136     /**
       
   137      * Two-phased constructor. Pushes the pointer onto the CleanupStack.
       
   138      * @return A pointer to the newly created instance.
       
   139      */
       
   140     static CSCOMOAdapterDb* NewLC();
       
   141 
       
   142     /**
       
   143      * Destructor.
       
   144      */
       
   145     virtual ~CSCOMOAdapterDb();
       
   146 
       
   147     void CreateTableL(RDbDatabase& aDatabase);
       
   148 
       
   149     void CreateandOpenL(TParse& name);
       
   150 
       
   151     TBool DeleteFromDatabaseL(TUint32 aLuid);
       
   152 
       
   153     void SaveToDatabaseL(TInt& aIndex, TUint32 aLuid, TInt aProfileid,
       
   154             TInt aRetryCount, const TDesC8& aSourceURI,
       
   155             const TDesC8& aServerid, const TDesC8& aCorrelator);
       
   156 
       
   157     void ReadItemsL(RPointerArray<CAMDbItem>& aItemArray, TDesC& aSqlQuery);
       
   158 
       
   159     void ReadDbItemsL(RPointerArray<CAMDbItem>& aItemArray);
       
   160 
       
   161     void GetEntryForServerIDL(RPointerArray<CAMDbItem>& aItemArray, TDesC8& aValue);
       
   162     
       
   163     void UpdateRetryCountForLuidL(TInt aLuid, TInt aRetryCount);
       
   164     
       
   165     TInt GetRetryCountForLuidL(TInt aLuid);
       
   166     
       
   167     void BeginDatabaseTransaction();
       
   168 
       
   169     void CommitDatabaseTransaction();
       
   170     
       
   171     void PrepareLuidQuery(TInt aLuid, TDes& aSqlQuery);
       
   172 
       
   173 
       
   174 private:
       
   175 
       
   176     void ConstructL();
       
   177 
       
   178     CSCOMOAdapterDb();
       
   179 
       
   180 private:
       
   181 
       
   182     RDbNamedDatabase iDatabase;
       
   183     RFs iFsSession;
       
   184     RDbs iRdbSession;
       
   185 
       
   186     RDbTable iAMObjectTable;
       
   187     CDbColSet* iColSet;
       
   188     RDbView iView;
       
   189 
       
   190     };
       
   191 
       
   192 #endif // __AMADAPTERDB_H   
       
   193 // End of File