genericservices/taskscheduler/SCHSVR/SCHSTORE.H
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1998-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 // SCHSTORE
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __SCHSTORE_H__
       
    19 #define __SCHSTORE_H__
       
    20 
       
    21 // System includes
       
    22 #include <s32file.h>
       
    23 
       
    24 // Classes referenced
       
    25 class CSchScheduleIndex;
       
    26 class CSchClientIndex;
       
    27 class CClientProxy;
       
    28 class CSchLogManager;
       
    29 class CSchedule;
       
    30 
       
    31 
       
    32 /**
       
    33 @internalComponent
       
    34 */
       
    35 class SchBackupManagerUtils
       
    36 	{
       
    37 public:
       
    38 	enum TSchStorePanic
       
    39 		{
       
    40 		ESchBackupManagerScheduleStreamToReplaceNotFound,
       
    41 		ESchBackupManagerScheduleStreamToDeleteNotFound,
       
    42 		//
       
    43 		ESchBackupManagerLast
       
    44 		};
       
    45 
       
    46 public:
       
    47 	static void Panic(TSchStorePanic aPanic);
       
    48 	};
       
    49 
       
    50 
       
    51 /**
       
    52 Schedule server backup file name.
       
    53 @internalComponent
       
    54 */
       
    55 _LIT(KSchsvrBackupFileName, "_:\\Private\\10005399\\SchedulesBackup.dat");
       
    56 /**
       
    57 Buffer descriptor to hold complete backup file name.
       
    58 @internalComponent
       
    59 */
       
    60 typedef TBuf<40> TBackupFileName;
       
    61 
       
    62 
       
    63 
       
    64 /**
       
    65 @internalComponent
       
    66 */
       
    67 NONSHARABLE_CLASS(CSchBackupManager) : public CActive
       
    68 	{
       
    69 public:
       
    70 	enum TSchBackupOperation
       
    71 		{
       
    72 		ESchBackupOperationAdd,
       
    73 		ESchBackupOperationEdit,
       
    74 		ESchBackupOperationDelete
       
    75 		};
       
    76 
       
    77 public:
       
    78 	CSchBackupManager(RFs& aFsSession);
       
    79 	~CSchBackupManager();
       
    80 	void ConstructL();
       
    81 
       
    82 public:
       
    83 	void RestoreL(TPriQue<CClientProxy>& aClients, 
       
    84 				TSglQue<CSchedule>& aTimeSchedules,
       
    85 				CSchLogManager& aSchLogManager,TBool aBUR=EFalse);
       
    86 	void CreateEmptyBackupL();
       
    87 	//
       
    88 	void PerformStoreOperationL(TSchBackupOperation aAction, const CSchedule& aSchedule);
       
    89 	void PerformStoreOperationL(TSchBackupOperation aAction, const CClientProxy& aClient);
       
    90 
       
    91 private:
       
    92 	// The backup manager need to compact the store every now and then. It does
       
    93 	// this as an idle operation and therefore needs to be CActive-based.
       
    94 	void RunL();
       
    95 	void DoCancel();
       
    96 	void DoCreateEmptyBackupL();
       
    97 
       
    98 private:
       
    99 	void StoreChangedL();
       
   100 	inline TInt RecordStoreChange() { return ++iStoreChangeCount; }
       
   101 	inline void ResetStoreChanges() { iStoreChangeCount = 0; }
       
   102 
       
   103 private:
       
   104 	CPermanentFileStore* OpenBackupStoreLC();
       
   105 	CPermanentFileStore* OpenOrCreateBackupStoreLC();
       
   106 	//
       
   107 	void CleanupRevertPushLC(CStreamStore& aStore);
       
   108 	static void RevertStore(TAny* aStore);
       
   109 	//
       
   110 	void WriteRootStreamL(CStreamStore& aStore);
       
   111 
       
   112 private:
       
   113 
       
   114 	RFs& iFsSession;
       
   115 	
       
   116 	// The number of times the store has changed since it was last
       
   117 	// compacted.
       
   118 	TInt iStoreChangeCount;
       
   119 
       
   120 	// Used to compact the store.
       
   121 	RStoreReclaim iStoreReclaimer;
       
   122 
       
   123 	// Used internally by the reclaimer to judge how much work is left to do.
       
   124 	TPckgBuf<TInt> iStoreReclaimerCount;
       
   125 
       
   126 	// A pointer to the store that has been opened for compaction purposes.
       
   127 	// During normal operation of the backup manager, this pointer will
       
   128 	// be NULL. However, when performing compaction, the store must be
       
   129 	// open at all times and since processing is carried out as a series of
       
   130 	// active object steps, we need to anchor it to the class.
       
   131 	CStreamStore* iStoreOpenForCompaction;
       
   132 
       
   133 	// The index to the schedule stream
       
   134 	TStreamId iIndexStreamSchedules;
       
   135 
       
   136 	// The index to the client stream
       
   137 	TStreamId iIndexStreamClients;
       
   138 	
       
   139 	// The two pseudo-dictionary classes that manage mappings between
       
   140 	// (clients and streams) and (schedules and streams).
       
   141 	CSchClientIndex* iClientIndex;
       
   142 	CSchScheduleIndex* iScheduleIndex;
       
   143 	
       
   144 	// backup file name
       
   145 	TBackupFileName iBackupFileName;
       
   146 	};
       
   147 
       
   148 
       
   149 
       
   150 
       
   151 /**
       
   152 @internalComponent
       
   153 */
       
   154 class CSchScheduleIndex : public CBase
       
   155 	{
       
   156 public:
       
   157 	static CSchScheduleIndex* NewL();
       
   158 
       
   159 private:
       
   160 	CSchScheduleIndex();
       
   161 
       
   162 public:
       
   163 	void RestoreSchedulesL(TSglQue<CSchedule>& aTimeSchedules, 
       
   164 						CStreamStore& aStore, 
       
   165 						TStreamId aDictionaryStreamId);
       
   166 	TStreamId CreateEmptyIndexL(CStreamStore& aStore) const;
       
   167 	//
       
   168 	void AddL(TStreamId aIndexStream, CStreamStore& aStore, const CSchedule& aSchedule);
       
   169 	void EditL(TStreamId aIndexStream, CStreamStore& aStore, const CSchedule& aSchedule);
       
   170 	void DeleteL(TStreamId aIndexStream, CStreamStore& aStore, const CSchedule& aSchedule);
       
   171 
       
   172 public:
       
   173 	class TSchScheduleMapplet
       
   174 		{
       
   175 	public:
       
   176 		inline TSchScheduleMapplet() { }
       
   177 		inline TSchScheduleMapplet(TInt aKey, TStreamId aStream) : iKey(aKey), iStream(aStream) { }
       
   178 
       
   179 	public:
       
   180 		void InternalizeL(RReadStream& aStream) { iKey = aStream.ReadInt32L(); aStream >> iStream; }
       
   181 		void ExternalizeL(RWriteStream& aStream) const { aStream.WriteInt32L(iKey); aStream << iStream; }
       
   182 
       
   183 	public:
       
   184 		inline void SetStream(TStreamId aStream) { iStream = aStream; }
       
   185 		inline TStreamId Stream() const { return iStream; }
       
   186 
       
   187 	public:
       
   188 		inline static TInt KeyOffset() { return _FOFF(TSchScheduleMapplet, iKey); }
       
   189 
       
   190 	private:
       
   191 		TInt iKey;
       
   192 		TStreamId iStream;
       
   193 		};
       
   194 	
       
   195 private:
       
   196 
       
   197 	NONSHARABLE_CLASS(CSchScheduleDictionary) : public CBase
       
   198 		{
       
   199 	public:
       
   200 		static CSchScheduleDictionary* NewLC();
       
   201 		~CSchScheduleDictionary();
       
   202 
       
   203 	private:
       
   204 		CSchScheduleDictionary();
       
   205 		void ConstructL();
       
   206 
       
   207 	public:
       
   208 		void AssignL(TInt aKey, TStreamId aId);
       
   209 		void Remove(TInt aKey);
       
   210 		TInt Count() const;
       
   211 		//
       
   212 		TStreamId At(TInt aKey) const;
       
   213 		TStreamId AtIndex(TInt aIndex) const;
       
   214 		//
       
   215 		void InternalizeL(RReadStream& aStream);
       
   216 		void ExternalizeL(RWriteStream& aStream) const;
       
   217 
       
   218 	private:
       
   219 		CArrayFix<TSchScheduleMapplet>* iMappings;
       
   220 		};
       
   221 
       
   222 private:
       
   223 	CSchScheduleDictionary* DictionaryLC(CStreamStore& aStore, TStreamId aIndexStream);
       
   224 	void StoreDictionaryL(CStreamStore& aStore, const CSchScheduleDictionary& aDictionary, TStreamId aStreamToReplace);
       
   225 	};
       
   226 
       
   227 
       
   228 /**
       
   229 @internalComponent
       
   230 */
       
   231 class CSchClientIndex : public CBase
       
   232 	{
       
   233 public:
       
   234 	static CSchClientIndex* NewL(RFs& aFsSession);
       
   235 	
       
   236 private:
       
   237 	CSchClientIndex(RFs& aFsSession);
       
   238 
       
   239 public:
       
   240 	void RestoreClientsL(TPriQue<CClientProxy>& aClients, 
       
   241 							CStreamStore& aStore, 
       
   242 							TStreamId aIndexStream,
       
   243 							CSchLogManager& aSchLogManager,TBool aBUR=EFalse);
       
   244 	TStreamId CreateEmptyIndexL(CStreamStore& aStore) const;
       
   245 	void AppendClientToListL(TPriQue<CClientProxy>& aClients, CClientProxy* aClient);
       
   246 public:
       
   247 	void AddL(TStreamId aIndexStream, CStreamStore& aStore, const CClientProxy& aClient);
       
   248 	void EditL(TStreamId aIndexStream, CStreamStore& aStore, const CClientProxy& aClient);
       
   249 	void DeleteL(TStreamId aIndexStream, CStreamStore& aStore, const CClientProxy& aClient);
       
   250 
       
   251 public:
       
   252 	NONSHARABLE_CLASS(CSchClientMapplet) : public CBase
       
   253 		{
       
   254 	public:
       
   255 		static CSchClientMapplet* NewLC(RReadStream& aStream);
       
   256 		static CSchClientMapplet* NewLC(const TDesC& aKey, TStreamId aStream);
       
   257 		~CSchClientMapplet();
       
   258 
       
   259 	public:
       
   260 		void InternalizeL(RReadStream& aStream);
       
   261 		void ExternalizeL(RWriteStream& aStream) const;
       
   262 
       
   263 	public:
       
   264 		inline const TDesC& Key() const { return *iKey; }
       
   265 		inline TStreamId Stream() const { return iStream; }
       
   266 		//
       
   267 		inline void SetStream(TStreamId aStream) { iStream = aStream; }
       
   268 		//
       
   269 		inline static TInt KeyOffset() { return _FOFF(CSchClientMapplet, iStream); }
       
   270 
       
   271 	private:
       
   272 		HBufC* iKey;
       
   273 		TStreamId iStream;
       
   274 		};
       
   275 
       
   276 private:
       
   277 	NONSHARABLE_CLASS(CSchClientDictionary) : public CBase
       
   278 		{
       
   279 	public:
       
   280 		static CSchClientDictionary* NewLC();
       
   281 		~CSchClientDictionary();
       
   282 
       
   283 	private:
       
   284 		CSchClientDictionary();
       
   285 		void ConstructL();
       
   286 
       
   287 	public:
       
   288 		void AssignL(const TDesC& aKey, TStreamId aId);
       
   289 		void RemoveL(const TDesC& aKey);
       
   290 		TInt Count() const;
       
   291 		TStreamId AtL(const TDesC& aKey) const;
       
   292 		TStreamId AtIndex(TInt aIndex) const;
       
   293 
       
   294 	public:
       
   295 		void InternalizeL(RReadStream& aStream);
       
   296 		void ExternalizeL(RWriteStream& aStream) const;
       
   297 
       
   298 	private:
       
   299 		CArrayPtr<CSchClientMapplet>* iMappings;
       
   300 		};
       
   301 
       
   302 private:
       
   303 	CSchClientDictionary* DictionaryLC(CStreamStore& aStore, TStreamId aIndexStream);
       
   304 	void StoreDictionaryL(CStreamStore& aStore, const CSchClientDictionary& aDictionary, TStreamId aStreamToReplace);
       
   305 
       
   306 private:
       
   307 	RFs& iFsSession;
       
   308 	};
       
   309 
       
   310 
       
   311 #endif