applayerpluginsandutils/bookmarksupport/test/cenrepsrv/setting.h
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef SETTING_H
       
    17 #define SETTING_H
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <s32strm.h>
       
    21 
       
    22 #include <centralrepository.h>
       
    23 #include "srvdefs.h"
       
    24 
       
    25 
       
    26 
       
    27 class TSettingsAccessPolicy;
       
    28 
       
    29 class TServerSetting
       
    30 	{
       
    31 	friend class RSettingsArray;
       
    32 public:
       
    33 	enum TType { EInt	  = 0x00000000, 
       
    34 				 EReal	  = 0x10000000, 
       
    35 				 EString  = 0x20000000, 
       
    36 				 EDeleted = 0x30000000 };
       
    37 
       
    38 	inline TServerSetting();
       
    39 	inline TServerSetting(TUint32 aKey);
       
    40 
       
    41 	inline TInt ReplaceTypeAndValue(const TServerSetting& source);
       
    42 	inline TInt Replace(const TServerSetting& source);
       
    43 	inline TInt Transfer(TServerSetting& source);
       
    44 
       
    45 	inline TUint32 Key() const;
       
    46 	inline void SetKey(TUint32 aKey);
       
    47 	inline TUint32 Meta() const;
       
    48 	inline void SetMeta(const TUint32 aMeta);
       
    49 	inline TBool IsClean(){return(iMeta & KMetaDefaultValue);};
       
    50 	inline void SetClean(){iMeta |= KMetaDefaultValue;};
       
    51 	inline TUint32 Type() const;
       
    52 	inline void SetType(const TUint32 aType);
       
    53 
       
    54 	inline TInt GetIntValue() const;
       
    55 	inline const TReal& GetRealValue() const;
       
    56 	inline const HBufC8* GetStrValue() const;
       
    57 
       
    58 	inline void SetIntValue(TInt aVal);
       
    59 	inline void SetRealValue(const TReal* aVal);
       
    60 	inline void SetStrValue(const HBufC8* aVal);
       
    61 
       
    62 	inline void SetDeleted();
       
    63 
       
    64 	inline void CopyValueL(TInt aVal);
       
    65 	inline void CopyValueL(const TReal& aVal);
       
    66 	inline void CopyValueL(const TDesC8& aVal);
       
    67 
       
    68 	inline TInt AssignValueTo(TInt& aVal) const;
       
    69 	inline TInt AssignValueTo(TReal& aVal) const;
       
    70 	inline TInt AssignValueTo(TDes8& aVal) const;
       
    71 
       
    72 	inline TInt AssignValueFromL(TInt aVal);
       
    73 	inline TInt AssignValueFromL(const TReal& aVal);
       
    74 	inline TInt AssignValueFromL(const TDesC8& aVal);
       
    75 
       
    76 	inline void PushL() const;
       
    77 	inline void Pop() const;
       
    78 
       
    79 	inline void Reset();
       
    80 	inline void ResetValue();
       
    81 
       
    82 	inline TInt operator==(const TServerSetting& aSetting) const;
       
    83 	inline TInt operator==(TInt aVal) const;
       
    84 	inline TInt operator==(const TReal& aVal) const;
       
    85 	inline TInt operator==(const TDesC8& aVal) const;
       
    86 
       
    87 	template <class T>
       
    88 	inline TInt operator!=(const T& aVal) const
       
    89 		{
       
    90 		return !operator==(aVal);
       
    91 		}
       
    92 
       
    93 	inline TSettingsAccessPolicy* AccessPolicy() const;
       
    94 	inline void SetAccessPolicy(TSettingsAccessPolicy* aPolicy);
       
    95 	inline const TSecurityPolicy* GetReadAccessPolicy() const;
       
    96 	inline const TSecurityPolicy* GetWriteAccessPolicy() const;
       
    97 	inline TBool HasAccessPolicy() const;
       
    98 	
       
    99 	inline void ExternalizeL(RWriteStream& aStream) const;
       
   100 	inline void InternalizeL(RReadStream& aStream);
       
   101 	inline void ExternalizeMetaL(RWriteStream& aStream) const;
       
   102 	inline void InternalizeMetaL(RReadStream& aStream);
       
   103 	
       
   104 	inline TBool IsType(const TInt&) const;
       
   105 	inline TBool IsType(const TReal&) const;
       
   106 	inline TBool IsType(const TDesC8&) const;
       
   107 	inline TBool IsType(const TDesC16&) const;
       
   108 	
       
   109 	inline TBool IsInt() const;
       
   110 	inline TBool IsReal() const;
       
   111 	inline TBool IsStr() const;
       
   112 	inline TBool IsDeleted() const;
       
   113 	
       
   114 private:
       
   115 	TUint32 iKey;
       
   116 	TUint32 iMeta;
       
   117 	union TValue { TInt i; TReal* r; HBufC8* s; } iValue;
       
   118 
       
   119 	// A bit of dilemma how to store TSecurePolicy for read/write access...
       
   120 	// If we were implementing a list of policies per an entry then RArray would be an obvious choice,
       
   121 	// but even then when no policy is specified each entry would have RArray (in compressed state 24B)
       
   122 	// Or we could have two instances of TSecurePolicy (6B each)
       
   123 	// so lets go for a link to a separate array of policies allocated only when needed
       
   124 
       
   125 	TSettingsAccessPolicy* iAccessPolicy;
       
   126 	};
       
   127 
       
   128 
       
   129 class TSettingsAccessPolicy
       
   130 	{
       
   131 	friend class CSharedRepository;
       
   132 	friend class CIniFileOut;
       
   133 
       
   134 public:
       
   135 	// Single entry type is maintained in a separate array
       
   136 	// then the range type... to avoid duplicities
       
   137 	enum {ESingleSettingPolicy,ERangeSettingsPolicy};
       
   138 
       
   139 	inline TSettingsAccessPolicy(TSecurityPolicy& aReadPolicy,TSecurityPolicy& aWritePolicy,
       
   140 								TUint32 aLowKey, TUint32 aHighKey, TUint32 aKeyMask=0);
       
   141 	inline TSettingsAccessPolicy(TSecurityPolicy& aReadPolicy,TSecurityPolicy& aWritePolicy,
       
   142 								TUint32 aKey);
       
   143 
       
   144 	
       
   145 	inline TBool IsInRange(TUint32 aKey) const;							
       
   146 	inline const TSecurityPolicy* GetReadAccessPolicy() const;
       
   147 	inline const TSecurityPolicy* GetWriteAccessPolicy() const;
       
   148 	
       
   149 	inline void ExternalizeL(RWriteStream& aStream) const;
       
   150 	inline void InternalizeL(RReadStream& aStream) ;
       
   151 	inline TSettingsAccessPolicy();
       
   152 	inline TUint32 LowKey() const;
       
   153 	inline TUint32 HighKey() const;
       
   154 	inline TUint32 KeyMask() const;
       
   155 		
       
   156 private:
       
   157 	inline TSettingsAccessPolicy(TUint32 key);
       
   158 private:
       
   159 	// we can have 'duplicites' where a single policy would have the same key
       
   160 	// as 'range' policy with the low key... 
       
   161 	TUint32 iLowKey; // used as a key for single policy as well
       
   162 	TUint32 iHighKey; // only used for Range
       
   163 	TUint32 iKeyMask; // only used for Range
       
   164 
       
   165 	
       
   166 	TSecurityPolicy iReadAccessPolicy;
       
   167 	TSecurityPolicy iWriteAccessPolicy;
       
   168 
       
   169 	};
       
   170 	
       
   171 class TSettingsDefaultMeta
       
   172 	{
       
   173 	friend class CSharedRepository;
       
   174 public:
       
   175 	inline TSettingsDefaultMeta(TUint32 aValue, TUint32 aLowKey,
       
   176 								TUint32 aHighKey, TUint32 aKeyMask=0);
       
   177 
       
   178 	inline TBool IsInRange(TUint32 aKey) const;	
       
   179 	inline TSettingsDefaultMeta();
       
   180 						
       
   181 	inline TUint32 GetDefaultMetadata() const 
       
   182 	{
       
   183 		return iDefaultMetaData ;
       
   184 	};
       
   185 
       
   186 	inline void ExternalizeL(RWriteStream& aStream) const;
       
   187 	inline void InternalizeL(RReadStream& aStream) ;	
       
   188 
       
   189 	inline TUint32 LowKey() const;
       
   190 	inline TUint32 HighKey() const;
       
   191 	inline TUint32 KeyMask() const;
       
   192 
       
   193 private:
       
   194 	TUint32 iLowKey;
       
   195 	TUint32 iHighKey;
       
   196 	TUint32 iKeyMask;
       
   197 	TUint32 iDefaultMetaData;
       
   198 	};
       
   199 
       
   200 #include "setting.inl"
       
   201 
       
   202 #endif // SETTING_H