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