os/security/authorisation/userpromptservice/database/inc/upsdbw.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Defines a writable interface for UPS Decision Database
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
 @internalTechnology
sl@0
    23
 @released
sl@0
    24
*/
sl@0
    25
 
sl@0
    26
#ifndef UPSDBW_H
sl@0
    27
#define UPSDBW_H
sl@0
    28
sl@0
    29
#include <ups/upsdb.h>
sl@0
    30
#include <ups/upserr.h>
sl@0
    31
#include <ups/upsconst.h>
sl@0
    32
#include "upslog.h"
sl@0
    33
sl@0
    34
namespace UserPromptService
sl@0
    35
{
sl@0
    36
sl@0
    37
//Database, table and index names
sl@0
    38
_LIT(KDecisionTable,  "UPSDecisions");
sl@0
    39
_LIT(KPrimaryIndex,   "UPSPrimaryIndex");
sl@0
    40
_LIT(KRecordIdIndex,  "UPSRecordIdIndex");
sl@0
    41
sl@0
    42
//Column names of the decision table
sl@0
    43
_LIT(KColServerSid,    		"ServerSid");
sl@0
    44
_LIT(KColServiceId,    		"ServiceId");
sl@0
    45
_LIT(KColClientSid,    		"ClientSid");
sl@0
    46
_LIT(KColEvaluatorId,  		"EvaluatorId");
sl@0
    47
_LIT(KColFingerprint,  		"Fingerprint");
sl@0
    48
_LIT(KColClientEntity, 		"ClientEntity");
sl@0
    49
_LIT(KColDescription,  		"Description");
sl@0
    50
_LIT(KColResult, 	   		"Result");
sl@0
    51
_LIT(KColEvaluatorInfo,		"EvaluatorInfo");
sl@0
    52
_LIT(KColMajorPolicyVersion,"MajorPolicyVersion");
sl@0
    53
_LIT(KColRecordId,			"RecordId");
sl@0
    54
sl@0
    55
//Constant lengths
sl@0
    56
static const TInt KBaseSQLLength   = 33;
sl@0
    57
static const TInt KMaxIntCondition = 26;    //columnname_length(11) + equal_sign(1) + max_decimal_digit_length(9) + and_length(5)
sl@0
    58
static const TInt KMaxStringCondition = 52; //columnname_length(12) + equal_sign(1) + max_field_length(32) + two_singlequote(2) + and_length(5)
sl@0
    59
static const TInt KCompactionTreshold = 50; //a percentage which indicates at least how much of the size of the database must be live data
sl@0
    60
static const TInt KIndexColumnNumber  = 7;  //The number of columns constructing the decision index
sl@0
    61
sl@0
    62
//Basic SQL statement parts
sl@0
    63
_LIT(KSQLQueryBase, 			 "SELECT * FROM %S");
sl@0
    64
_LIT(KSQLQueryString,	 		 "%S");
sl@0
    65
_LIT(KSQLQueryConditionInt,		 "%u");
sl@0
    66
_LIT(KSQLQueryConditionString,	 "'%S'");
sl@0
    67
_LIT(KSQLQueryWhere, 			 " WHERE ");
sl@0
    68
_LIT(KSQLQueryAnd, 				 " AND ");
sl@0
    69
_LIT(KSQLQueryNull, 			 " IS NULL");
sl@0
    70
_LIT(KSQLQueryEqual,			 "=");
sl@0
    71
_LIT(KSQLQueryNotEqual,			 "<>");
sl@0
    72
_LIT(KSQLQueryLessThan,			 "<");
sl@0
    73
_LIT(KSQLQueryGreaterThan,		 ">");
sl@0
    74
_LIT(KSQLQueryLessThanOrEqual,	 "<=");
sl@0
    75
_LIT(KSQLQueryGreaterThanOrEqual,">=");
sl@0
    76
	
sl@0
    77
//Other classes used in UPS database
sl@0
    78
class CDecisionFilter;
sl@0
    79
class CDecisionRecord;
sl@0
    80
class CDecisionDb;
sl@0
    81
	
sl@0
    82
NONSHARABLE_CLASS(CDecisionDbCompactor):public CActive
sl@0
    83
/**
sl@0
    84
	Provides an interface to compact the decision database asynchronously. While the
sl@0
    85
    compaction operation is in progress, the database cannot be used for any other
sl@0
    86
	operations such as searching records or preparing views.
sl@0
    87
 */
sl@0
    88
	{
sl@0
    89
	friend class CDecisionDbW;
sl@0
    90
	
sl@0
    91
public:	
sl@0
    92
 	IMPORT_C void Compact(TRequestStatus& aStatus);	
sl@0
    93
 	~CDecisionDbCompactor();
sl@0
    94
sl@0
    95
protected:	
sl@0
    96
	static CDecisionDbCompactor *NewLC();
sl@0
    97
 	CDecisionDbCompactor();	
sl@0
    98
 	
sl@0
    99
	/**
sl@0
   100
		From CActive. Handles incremental database compaction.
sl@0
   101
	 */
sl@0
   102
	void RunL();	
sl@0
   103
	/**
sl@0
   104
		From CActive. Cancels current database compaction.
sl@0
   105
	 */
sl@0
   106
	void DoCancel();	
sl@0
   107
	/**
sl@0
   108
		From CActive. Handles errors.
sl@0
   109
	 */
sl@0
   110
	TInt RunError(TInt aError);
sl@0
   111
sl@0
   112
private:
sl@0
   113
	/**
sl@0
   114
		Handle to the interface used for performing database compaction in incremental steps
sl@0
   115
	 */
sl@0
   116
	RDbIncremental iDbIncremental;
sl@0
   117
	/**
sl@0
   118
	 	Contains the current step count for the incremental compaction operation	
sl@0
   119
	 */
sl@0
   120
	TPckgBuf<TInt> iStep;
sl@0
   121
	/**
sl@0
   122
	   Copy of the status variable of the client which requested the compaction service
sl@0
   123
	 */
sl@0
   124
	TRequestStatus* iClientStatus;
sl@0
   125
	};
sl@0
   126
sl@0
   127
sl@0
   128
NONSHARABLE_CLASS(CDecisionDbW):public CDecisionDb
sl@0
   129
/**
sl@0
   130
   A writable interface for UPS decision database. Connects to the database during construction.
sl@0
   131
   Creates the decision database and table, if not exist. Performs querying, insertion and deletion
sl@0
   132
   operations on the decision database.
sl@0
   133
 */
sl@0
   134
	{
sl@0
   135
public:
sl@0
   136
	IMPORT_C static CDecisionDbW *NewL(const TDesC& aDbName, RFs& aFs);	
sl@0
   137
	IMPORT_C static CDecisionDbW *NewLC(const TDesC& aDbName, RFs& aFs);
sl@0
   138
	
sl@0
   139
	~CDecisionDbW();
sl@0
   140
sl@0
   141
	IMPORT_C void CreateDecisionL(CDecisionRecord& aRecord);	
sl@0
   142
	IMPORT_C CDecisionRecord *GetDecisionL(CDecisionFilter& aFilter);
sl@0
   143
	IMPORT_C TBool UpdateDecisionL(CDecisionFilter& aFilter, CDecisionRecord& aNewRecord);
sl@0
   144
	IMPORT_C void RemoveDecisionsL(CDecisionFilter& aFilter);
sl@0
   145
	IMPORT_C void DeleteDatabaseL(RFs& aFs);
sl@0
   146
	IMPORT_C CDecisionDbCompactor *PrepareCompactionLC();
sl@0
   147
sl@0
   148
private:
sl@0
   149
	CDecisionDbW();
sl@0
   150
	
sl@0
   151
	void ConstructL(const TDesC& aDbName, RFs& aFs);	
sl@0
   152
	void OpenDatabaseL(RFs& aFs);
sl@0
   153
	void CreateDatabaseL(RFs& aFs);
sl@0
   154
	void CreateTableL();	
sl@0
   155
	void CreateIndexL();	
sl@0
   156
	void DoRemoveDecisionL(CDecisionFilter& aFilter);
sl@0
   157
	void UpdateCurrentRowL(RDbTable& aTable, CDecisionRecord& aRecord);
sl@0
   158
	void PrepareForSearchL(RDbTable& aTable, CDecisionFilter& aFilter,TDbSeekMultiKey<KIndexColumnNumber>& aSeekKey);
sl@0
   159
	
sl@0
   160
private:
sl@0
   161
	/**
sl@0
   162
	 * The fully qualified path of the database
sl@0
   163
	 */
sl@0
   164
	HBufC* iDbName;	
sl@0
   165
	};		
sl@0
   166
	
sl@0
   167
}//namespace Ups
sl@0
   168
sl@0
   169
#endif //UPSDBW_H