fotaapplication/fotaserver/inc/FotaDB.h
branchRCL_3
changeset 25 b183ec05bd8c
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
       
     1 /*
       
     2 * Copyright (c) 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:   Header file for fotadb
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __CFOTADB_H___
       
    22 #define __CFOTADB_H___
       
    23 
       
    24 // INCLUDES
       
    25 #include <d32dbms.h>
       
    26 #include <fotaengine.h>
       
    27 #include "FotaIPCTypes.h"
       
    28 
       
    29 
       
    30 // CONSTANTS
       
    31 // see fotaipctypes.h for field descriptions
       
    32 _LIT(KDatabaseName,"FotaState");
       
    33 
       
    34 _LIT(KSelectAll,"SELECT * FROM State" );
       
    35 _LIT(KSelect_where_packageid,"SELECT * FROM State WHERE PkgID=%d" );
       
    36 _LIT(KCreateTable, "CREATE TABLE State ( Id COUNTER, PkgID INTEGER NOT \
       
    37      NULL, Result INTEGER, State INTEGER NOT NULL, ProfileID INTEGER,\
       
    38 	     PkgURL LONG VARCHAR, PkgName CHAR(255),Version CHAR(255), SmlTryCount INTEGER, \
       
    39          SessionType INTEGER, IapId INTEGER, PkgSize UNSIGNED INTEGER, UpdateLtr BIT)");
       
    40 _LIT(KAlterTable, "ALTER TABLE State ADD (SessionType INTEGER, IapId INTEGER, PkgSize UNSIGNED INTEGER, UpdateLtr BIT)");
       
    41 _LIT(KTblState,     "State");
       
    42 
       
    43 _LIT(KColPkgId,     "PkgID");
       
    44 _LIT(KColResult,    "Result");
       
    45 _LIT(KColState,     "State");
       
    46 _LIT(KColProfileId, "ProfileID");
       
    47 _LIT(KColPkgUrl,    "PkgURL");
       
    48 _LIT(KColPkgName,   "PkgName");
       
    49 _LIT(KColVersion,   "Version");
       
    50 _LIT(KColSmlTryCount, "SmlTryCount");
       
    51 _LIT(KColSessionType, "SessionType");
       
    52 _LIT(KColIapId, "IapId");
       
    53 _LIT(KColPkgSize, "PkgSize");
       
    54 _LIT(KColUpdateLtr, "UpdateLtr");
       
    55 
       
    56 // DATATYPES
       
    57 enum TFDBFields
       
    58 {
       
    59     EFDBResult      = 0x01,
       
    60     EFDBState       = 0x02,
       
    61     EFDBProfileId   = 0x04,
       
    62     EFDBPkgUrl      = 0x08,
       
    63     EFDBPkgName     = 0x10,
       
    64     EFDBVersion     = 0x20,
       
    65     EFDBSmlTryCount = 0x40,
       
    66     EFDBSessionType = 0x80,
       
    67     EFDBIapId 		= 0x100,
       
    68     EFDBPkgSize 	= 0x200,
       
    69     EFDBUpdateLtr 	= 0x400
       
    70 };
       
    71 //Number of attributes in fotastate table
       
    72 const TUint KNoOfDBFields = 13;
       
    73 
       
    74 // FORWARD DECLARATION
       
    75 class CPackageState;
       
    76 
       
    77 
       
    78 /**
       
    79  *  Database class
       
    80  *
       
    81  *  @lib    fotaserver
       
    82  *  @since  S60 v3.1
       
    83  */
       
    84 NONSHARABLE_CLASS(CFotaDB): public CBase
       
    85     {
       
    86     friend class CPackageState;
       
    87 public:
       
    88 	CFotaDB();
       
    89 
       
    90 	virtual ~CFotaDB();
       
    91 
       
    92     static CFotaDB* NewL();
       
    93 
       
    94     /**
       
    95      * Create database
       
    96      *
       
    97      * @since   S60   v3.1
       
    98      * @param   None
       
    99      * @return  none
       
   100      */
       
   101     void CreateDatabaseL();
       
   102     
       
   103 
       
   104     /**
       
   105      * Open database
       
   106      *
       
   107      * @since   S60   v3.1
       
   108      * @param   None
       
   109      * @return  Error code
       
   110      */
       
   111     void OpenDBL();
       
   112 
       
   113     /**
       
   114      * Close database and commit changes
       
   115      *
       
   116      * @since   S60   v3.1
       
   117      * @param   None
       
   118      * @return  none
       
   119      */
       
   120     void CloseAndCommitDB();
       
   121 
       
   122 
       
   123     /**
       
   124      * Checks if DB is open
       
   125      *
       
   126      * @since   S60   v3.1
       
   127      * @param   None
       
   128      * @return  TBool - is database open
       
   129      */
       
   130     TBool IsOpen();
       
   131     
       
   132 
       
   133     /**
       
   134      * Add new package state to database
       
   135      *
       
   136      * @since   S60   v3.1
       
   137      * @param   aState      State
       
   138      * @param   aPkgURL     URL
       
   139      * @return  None
       
   140      */    
       
   141     void AddPackageStateL( const TPackageState& aState
       
   142                                 ,const TDesC8& aPkgURL );
       
   143 
       
   144 
       
   145     /**
       
   146      * Get state from db
       
   147      *
       
   148      * @since   S60   v3.1
       
   149      * @param   aPkgId      Package ID
       
   150      * @return  State object
       
   151      */        
       
   152     TPackageState   GetStateL( const TInt aPkgId, TDes8& aPkgURL );
       
   153 
       
   154 
       
   155     /** Sets state of package specified by packageid. If state doesnt exist,
       
   156      * it is added to db.
       
   157      * @since   S60   v3.1
       
   158      * @param   aState   source data to be set
       
   159      * @param   aPkgURL  URL
       
   160      * @param   aChangedFields  Changed fields. Tells what columns from aState
       
   161      *                          are to be set.
       
   162      * @return  None
       
   163      */
       
   164     void SetStateL( TPackageState& aState
       
   165                         ,const TDesC8& aPkgURL, TUint aChangedFields );
       
   166 
       
   167     /**
       
   168      * Gets all states from database
       
   169      *
       
   170      * @since   S60   v3.1
       
   171      * @param   aStates     On return, all  states
       
   172      * @return  Error code
       
   173      */
       
   174     void GetAllL(RArray<TInt>& aStates);
       
   175 
       
   176 private:
       
   177 
       
   178     void ConstructL();
       
   179 
       
   180 
       
   181     /**
       
   182      * Converts database row to TPackageState
       
   183      *
       
   184      * @since   S60   v3.1
       
   185      * @param  aPkgUrl  URL
       
   186      * @param  aView    Database view. Must be ready&prepared for data 
       
   187      *                  extraction
       
   188      * @return  State
       
   189      */
       
   190 	TPackageState RowToStateL(HBufC8*& aPkgUrl,const RDbView& aView);
       
   191 
       
   192 
       
   193     /**
       
   194      * Inserts TPackageState to database view
       
   195      *
       
   196      * @since   S60   v3.1
       
   197      * @param  aPkg    Source package
       
   198      * @param  aPkgURL Url
       
   199      * @param  aView   Database view. Must be ready&prepared for data writing
       
   200      * @return  None
       
   201      */
       
   202     void StateToRowL (const TPackageState& aPkg, const TDesC8& aPkgURL
       
   203                     ,RDbView& aView);
       
   204     
       
   205     /**
       
   206      * Sets the retry count from the cenrep
       
   207      *
       
   208      * @since   S60   v5.0
       
   209      * @param   package state
       
   210      * @return  None
       
   211      */
       
   212     
       
   213     void SetRetryCount(TPackageState& aState);
       
   214     
       
   215     /**
       
   216      * Determines the char need for db queries
       
   217      *
       
   218      * @since   S60   v5.0
       
   219      * @param   aChangedFields change fields
       
   220      * @param   aState package states
       
   221      * @param   aPkgURL
       
   222      * @return  None
       
   223      */    
       
   224     TInt DetermineCharNeeded(TInt aChangedFields,TPackageState& aState,const TDesC8& aPkgURL);
       
   225 
       
   226 private:
       
   227 
       
   228     /**
       
   229      * File server session
       
   230      */
       
   231     RFs iFSSession;
       
   232 
       
   233     
       
   234     /**
       
   235      * Reference to database
       
   236      */
       
   237     RDbNamedDatabase iStateDB;
       
   238 
       
   239 
       
   240     /**
       
   241      * Columns
       
   242      */
       
   243     CDbColSet* iColSet;
       
   244 
       
   245 
       
   246     /**
       
   247      * Table
       
   248      */
       
   249     RDbTable iTable;
       
   250 
       
   251     /**
       
   252     * Is the db open?
       
   253     */
       
   254     TBool iIsOpen;
       
   255 
       
   256     };
       
   257 
       
   258 #endif // FOTADB_H