os/security/authorisation/userpromptservice/database/inc/upsdbw.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/database/inc/upsdbw.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,169 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Defines a writable interface for UPS Decision Database
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @internalTechnology
    1.26 + @released
    1.27 +*/
    1.28 + 
    1.29 +#ifndef UPSDBW_H
    1.30 +#define UPSDBW_H
    1.31 +
    1.32 +#include <ups/upsdb.h>
    1.33 +#include <ups/upserr.h>
    1.34 +#include <ups/upsconst.h>
    1.35 +#include "upslog.h"
    1.36 +
    1.37 +namespace UserPromptService
    1.38 +{
    1.39 +
    1.40 +//Database, table and index names
    1.41 +_LIT(KDecisionTable,  "UPSDecisions");
    1.42 +_LIT(KPrimaryIndex,   "UPSPrimaryIndex");
    1.43 +_LIT(KRecordIdIndex,  "UPSRecordIdIndex");
    1.44 +
    1.45 +//Column names of the decision table
    1.46 +_LIT(KColServerSid,    		"ServerSid");
    1.47 +_LIT(KColServiceId,    		"ServiceId");
    1.48 +_LIT(KColClientSid,    		"ClientSid");
    1.49 +_LIT(KColEvaluatorId,  		"EvaluatorId");
    1.50 +_LIT(KColFingerprint,  		"Fingerprint");
    1.51 +_LIT(KColClientEntity, 		"ClientEntity");
    1.52 +_LIT(KColDescription,  		"Description");
    1.53 +_LIT(KColResult, 	   		"Result");
    1.54 +_LIT(KColEvaluatorInfo,		"EvaluatorInfo");
    1.55 +_LIT(KColMajorPolicyVersion,"MajorPolicyVersion");
    1.56 +_LIT(KColRecordId,			"RecordId");
    1.57 +
    1.58 +//Constant lengths
    1.59 +static const TInt KBaseSQLLength   = 33;
    1.60 +static const TInt KMaxIntCondition = 26;    //columnname_length(11) + equal_sign(1) + max_decimal_digit_length(9) + and_length(5)
    1.61 +static const TInt KMaxStringCondition = 52; //columnname_length(12) + equal_sign(1) + max_field_length(32) + two_singlequote(2) + and_length(5)
    1.62 +static const TInt KCompactionTreshold = 50; //a percentage which indicates at least how much of the size of the database must be live data
    1.63 +static const TInt KIndexColumnNumber  = 7;  //The number of columns constructing the decision index
    1.64 +
    1.65 +//Basic SQL statement parts
    1.66 +_LIT(KSQLQueryBase, 			 "SELECT * FROM %S");
    1.67 +_LIT(KSQLQueryString,	 		 "%S");
    1.68 +_LIT(KSQLQueryConditionInt,		 "%u");
    1.69 +_LIT(KSQLQueryConditionString,	 "'%S'");
    1.70 +_LIT(KSQLQueryWhere, 			 " WHERE ");
    1.71 +_LIT(KSQLQueryAnd, 				 " AND ");
    1.72 +_LIT(KSQLQueryNull, 			 " IS NULL");
    1.73 +_LIT(KSQLQueryEqual,			 "=");
    1.74 +_LIT(KSQLQueryNotEqual,			 "<>");
    1.75 +_LIT(KSQLQueryLessThan,			 "<");
    1.76 +_LIT(KSQLQueryGreaterThan,		 ">");
    1.77 +_LIT(KSQLQueryLessThanOrEqual,	 "<=");
    1.78 +_LIT(KSQLQueryGreaterThanOrEqual,">=");
    1.79 +	
    1.80 +//Other classes used in UPS database
    1.81 +class CDecisionFilter;
    1.82 +class CDecisionRecord;
    1.83 +class CDecisionDb;
    1.84 +	
    1.85 +NONSHARABLE_CLASS(CDecisionDbCompactor):public CActive
    1.86 +/**
    1.87 +	Provides an interface to compact the decision database asynchronously. While the
    1.88 +    compaction operation is in progress, the database cannot be used for any other
    1.89 +	operations such as searching records or preparing views.
    1.90 + */
    1.91 +	{
    1.92 +	friend class CDecisionDbW;
    1.93 +	
    1.94 +public:	
    1.95 + 	IMPORT_C void Compact(TRequestStatus& aStatus);	
    1.96 + 	~CDecisionDbCompactor();
    1.97 +
    1.98 +protected:	
    1.99 +	static CDecisionDbCompactor *NewLC();
   1.100 + 	CDecisionDbCompactor();	
   1.101 + 	
   1.102 +	/**
   1.103 +		From CActive. Handles incremental database compaction.
   1.104 +	 */
   1.105 +	void RunL();	
   1.106 +	/**
   1.107 +		From CActive. Cancels current database compaction.
   1.108 +	 */
   1.109 +	void DoCancel();	
   1.110 +	/**
   1.111 +		From CActive. Handles errors.
   1.112 +	 */
   1.113 +	TInt RunError(TInt aError);
   1.114 +
   1.115 +private:
   1.116 +	/**
   1.117 +		Handle to the interface used for performing database compaction in incremental steps
   1.118 +	 */
   1.119 +	RDbIncremental iDbIncremental;
   1.120 +	/**
   1.121 +	 	Contains the current step count for the incremental compaction operation	
   1.122 +	 */
   1.123 +	TPckgBuf<TInt> iStep;
   1.124 +	/**
   1.125 +	   Copy of the status variable of the client which requested the compaction service
   1.126 +	 */
   1.127 +	TRequestStatus* iClientStatus;
   1.128 +	};
   1.129 +
   1.130 +
   1.131 +NONSHARABLE_CLASS(CDecisionDbW):public CDecisionDb
   1.132 +/**
   1.133 +   A writable interface for UPS decision database. Connects to the database during construction.
   1.134 +   Creates the decision database and table, if not exist. Performs querying, insertion and deletion
   1.135 +   operations on the decision database.
   1.136 + */
   1.137 +	{
   1.138 +public:
   1.139 +	IMPORT_C static CDecisionDbW *NewL(const TDesC& aDbName, RFs& aFs);	
   1.140 +	IMPORT_C static CDecisionDbW *NewLC(const TDesC& aDbName, RFs& aFs);
   1.141 +	
   1.142 +	~CDecisionDbW();
   1.143 +
   1.144 +	IMPORT_C void CreateDecisionL(CDecisionRecord& aRecord);	
   1.145 +	IMPORT_C CDecisionRecord *GetDecisionL(CDecisionFilter& aFilter);
   1.146 +	IMPORT_C TBool UpdateDecisionL(CDecisionFilter& aFilter, CDecisionRecord& aNewRecord);
   1.147 +	IMPORT_C void RemoveDecisionsL(CDecisionFilter& aFilter);
   1.148 +	IMPORT_C void DeleteDatabaseL(RFs& aFs);
   1.149 +	IMPORT_C CDecisionDbCompactor *PrepareCompactionLC();
   1.150 +
   1.151 +private:
   1.152 +	CDecisionDbW();
   1.153 +	
   1.154 +	void ConstructL(const TDesC& aDbName, RFs& aFs);	
   1.155 +	void OpenDatabaseL(RFs& aFs);
   1.156 +	void CreateDatabaseL(RFs& aFs);
   1.157 +	void CreateTableL();	
   1.158 +	void CreateIndexL();	
   1.159 +	void DoRemoveDecisionL(CDecisionFilter& aFilter);
   1.160 +	void UpdateCurrentRowL(RDbTable& aTable, CDecisionRecord& aRecord);
   1.161 +	void PrepareForSearchL(RDbTable& aTable, CDecisionFilter& aFilter,TDbSeekMultiKey<KIndexColumnNumber>& aSeekKey);
   1.162 +	
   1.163 +private:
   1.164 +	/**
   1.165 +	 * The fully qualified path of the database
   1.166 +	 */
   1.167 +	HBufC* iDbName;	
   1.168 +	};		
   1.169 +	
   1.170 +}//namespace Ups
   1.171 +
   1.172 +#endif //UPSDBW_H