fotaapplication/fotaserver/FotaServer/inc/FotaDB.h
changeset 50 a36219ae6585
parent 49 689a71addb96
child 51 2e64dc50f295
equal deleted inserted replaced
49:689a71addb96 50:a36219ae6585
     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 );
       
   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     /**
       
   169      * Deletes state from database 
       
   170      *
       
   171      * @since   S60   v3.1
       
   172      * @param   aPkgId      Package ID
       
   173      * @return  Error code
       
   174      */
       
   175     TInt DeleteStateL( const TInt aPkgId);
       
   176 
       
   177 
       
   178     /**
       
   179      * Gets all states from database
       
   180      *
       
   181      * @since   S60   v3.1
       
   182      * @param   aStates     On return, all  states
       
   183      * @return  Error code
       
   184      */
       
   185     void GetAllL(RArray<TInt>& aStates);
       
   186 
       
   187 private:
       
   188 
       
   189     void ConstructL();
       
   190 
       
   191 
       
   192     /**
       
   193      * Converts database row to TPackageState
       
   194      *
       
   195      * @since   S60   v3.1
       
   196      * @param  aPkgUrl  URL
       
   197      * @param  aView    Database view. Must be ready&prepared for data 
       
   198      *                  extraction
       
   199      * @return  State
       
   200      */
       
   201 	TPackageState RowToStateL(HBufC8*& aPkgUrl,const RDbView& aView);
       
   202 
       
   203 
       
   204     /**
       
   205      * Inserts TPackageState to database view
       
   206      *
       
   207      * @since   S60   v3.1
       
   208      * @param  aPkg    Source package
       
   209      * @param  aPkgURL Url
       
   210      * @param  aView   Database view. Must be ready&prepared for data writing
       
   211      * @return  None
       
   212      */
       
   213     void StateToRowL (const TPackageState& aPkg, const TDesC8& aPkgURL
       
   214                     ,RDbView& aView);
       
   215     
       
   216     /**
       
   217      * Adds new attributes to fota table for enabling suspend and resume of download. They include - 
       
   218      * DM session type, IAP used during download, total Package size and Update-after-download information.
       
   219      * 
       
   220      * @since   S60   v3.2
       
   221      * @return  None
       
   222      */
       
   223     void AlterTableIfRequiredL();
       
   224     
       
   225     /**
       
   226      * Sets the retry count from the cenrep
       
   227      *
       
   228      * @since   S60   v5.0
       
   229      * @param   package state
       
   230      * @return  None
       
   231      */
       
   232     
       
   233     void SetRetryCount(TPackageState& aState);
       
   234     
       
   235     /**
       
   236      * Determines the char need for db queries
       
   237      *
       
   238      * @since   S60   v5.0
       
   239      * @param   aChangedFields change fields
       
   240      * @param   aState package states
       
   241      * @param   aPkgURL
       
   242      * @return  None
       
   243      */    
       
   244     TInt DetermineCharNeeded(TInt aChangedFields,TPackageState& aState,const TDesC8& aPkgURL);
       
   245 
       
   246 private:
       
   247 
       
   248     /**
       
   249      * File server session
       
   250      */
       
   251     RFs iFSSession;
       
   252 
       
   253     
       
   254     /**
       
   255      * Reference to database
       
   256      */
       
   257     RDbNamedDatabase iStateDB;
       
   258 
       
   259 
       
   260     /**
       
   261      * Columns
       
   262      */
       
   263     CDbColSet* iColSet;
       
   264 
       
   265 
       
   266     /**
       
   267      * Table
       
   268      */
       
   269     RDbTable iTable;
       
   270 
       
   271     /**
       
   272     * Is the db open?
       
   273     */
       
   274     TBool iIsOpen;
       
   275 
       
   276     /**
       
   277      * Is fota table alter done?
       
   278      */
       
   279     TBool iTableAltercheck;
       
   280     };
       
   281 
       
   282 #endif // FOTADB_H