1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/SCHSVR/SCHSTORE.H Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,311 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// SCHSTORE
1.18 +//
1.19 +//
1.20 +
1.21 +#ifndef __SCHSTORE_H__
1.22 +#define __SCHSTORE_H__
1.23 +
1.24 +// System includes
1.25 +#include <s32file.h>
1.26 +
1.27 +// Classes referenced
1.28 +class CSchScheduleIndex;
1.29 +class CSchClientIndex;
1.30 +class CClientProxy;
1.31 +class CSchLogManager;
1.32 +class CSchedule;
1.33 +
1.34 +
1.35 +/**
1.36 +@internalComponent
1.37 +*/
1.38 +class SchBackupManagerUtils
1.39 + {
1.40 +public:
1.41 + enum TSchStorePanic
1.42 + {
1.43 + ESchBackupManagerScheduleStreamToReplaceNotFound,
1.44 + ESchBackupManagerScheduleStreamToDeleteNotFound,
1.45 + //
1.46 + ESchBackupManagerLast
1.47 + };
1.48 +
1.49 +public:
1.50 + static void Panic(TSchStorePanic aPanic);
1.51 + };
1.52 +
1.53 +
1.54 +/**
1.55 +Schedule server backup file name.
1.56 +@internalComponent
1.57 +*/
1.58 +_LIT(KSchsvrBackupFileName, "_:\\Private\\10005399\\SchedulesBackup.dat");
1.59 +/**
1.60 +Buffer descriptor to hold complete backup file name.
1.61 +@internalComponent
1.62 +*/
1.63 +typedef TBuf<40> TBackupFileName;
1.64 +
1.65 +
1.66 +
1.67 +/**
1.68 +@internalComponent
1.69 +*/
1.70 +NONSHARABLE_CLASS(CSchBackupManager) : public CActive
1.71 + {
1.72 +public:
1.73 + enum TSchBackupOperation
1.74 + {
1.75 + ESchBackupOperationAdd,
1.76 + ESchBackupOperationEdit,
1.77 + ESchBackupOperationDelete
1.78 + };
1.79 +
1.80 +public:
1.81 + CSchBackupManager(RFs& aFsSession);
1.82 + ~CSchBackupManager();
1.83 + void ConstructL();
1.84 +
1.85 +public:
1.86 + void RestoreL(TPriQue<CClientProxy>& aClients,
1.87 + TSglQue<CSchedule>& aTimeSchedules,
1.88 + CSchLogManager& aSchLogManager,TBool aBUR=EFalse);
1.89 + void CreateEmptyBackupL();
1.90 + //
1.91 + void PerformStoreOperationL(TSchBackupOperation aAction, const CSchedule& aSchedule);
1.92 + void PerformStoreOperationL(TSchBackupOperation aAction, const CClientProxy& aClient);
1.93 +
1.94 +private:
1.95 + // The backup manager need to compact the store every now and then. It does
1.96 + // this as an idle operation and therefore needs to be CActive-based.
1.97 + void RunL();
1.98 + void DoCancel();
1.99 + void DoCreateEmptyBackupL();
1.100 +
1.101 +private:
1.102 + void StoreChangedL();
1.103 + inline TInt RecordStoreChange() { return ++iStoreChangeCount; }
1.104 + inline void ResetStoreChanges() { iStoreChangeCount = 0; }
1.105 +
1.106 +private:
1.107 + CPermanentFileStore* OpenBackupStoreLC();
1.108 + CPermanentFileStore* OpenOrCreateBackupStoreLC();
1.109 + //
1.110 + void CleanupRevertPushLC(CStreamStore& aStore);
1.111 + static void RevertStore(TAny* aStore);
1.112 + //
1.113 + void WriteRootStreamL(CStreamStore& aStore);
1.114 +
1.115 +private:
1.116 +
1.117 + RFs& iFsSession;
1.118 +
1.119 + // The number of times the store has changed since it was last
1.120 + // compacted.
1.121 + TInt iStoreChangeCount;
1.122 +
1.123 + // Used to compact the store.
1.124 + RStoreReclaim iStoreReclaimer;
1.125 +
1.126 + // Used internally by the reclaimer to judge how much work is left to do.
1.127 + TPckgBuf<TInt> iStoreReclaimerCount;
1.128 +
1.129 + // A pointer to the store that has been opened for compaction purposes.
1.130 + // During normal operation of the backup manager, this pointer will
1.131 + // be NULL. However, when performing compaction, the store must be
1.132 + // open at all times and since processing is carried out as a series of
1.133 + // active object steps, we need to anchor it to the class.
1.134 + CStreamStore* iStoreOpenForCompaction;
1.135 +
1.136 + // The index to the schedule stream
1.137 + TStreamId iIndexStreamSchedules;
1.138 +
1.139 + // The index to the client stream
1.140 + TStreamId iIndexStreamClients;
1.141 +
1.142 + // The two pseudo-dictionary classes that manage mappings between
1.143 + // (clients and streams) and (schedules and streams).
1.144 + CSchClientIndex* iClientIndex;
1.145 + CSchScheduleIndex* iScheduleIndex;
1.146 +
1.147 + // backup file name
1.148 + TBackupFileName iBackupFileName;
1.149 + };
1.150 +
1.151 +
1.152 +
1.153 +
1.154 +/**
1.155 +@internalComponent
1.156 +*/
1.157 +class CSchScheduleIndex : public CBase
1.158 + {
1.159 +public:
1.160 + static CSchScheduleIndex* NewL();
1.161 +
1.162 +private:
1.163 + CSchScheduleIndex();
1.164 +
1.165 +public:
1.166 + void RestoreSchedulesL(TSglQue<CSchedule>& aTimeSchedules,
1.167 + CStreamStore& aStore,
1.168 + TStreamId aDictionaryStreamId);
1.169 + TStreamId CreateEmptyIndexL(CStreamStore& aStore) const;
1.170 + //
1.171 + void AddL(TStreamId aIndexStream, CStreamStore& aStore, const CSchedule& aSchedule);
1.172 + void EditL(TStreamId aIndexStream, CStreamStore& aStore, const CSchedule& aSchedule);
1.173 + void DeleteL(TStreamId aIndexStream, CStreamStore& aStore, const CSchedule& aSchedule);
1.174 +
1.175 +public:
1.176 + class TSchScheduleMapplet
1.177 + {
1.178 + public:
1.179 + inline TSchScheduleMapplet() { }
1.180 + inline TSchScheduleMapplet(TInt aKey, TStreamId aStream) : iKey(aKey), iStream(aStream) { }
1.181 +
1.182 + public:
1.183 + void InternalizeL(RReadStream& aStream) { iKey = aStream.ReadInt32L(); aStream >> iStream; }
1.184 + void ExternalizeL(RWriteStream& aStream) const { aStream.WriteInt32L(iKey); aStream << iStream; }
1.185 +
1.186 + public:
1.187 + inline void SetStream(TStreamId aStream) { iStream = aStream; }
1.188 + inline TStreamId Stream() const { return iStream; }
1.189 +
1.190 + public:
1.191 + inline static TInt KeyOffset() { return _FOFF(TSchScheduleMapplet, iKey); }
1.192 +
1.193 + private:
1.194 + TInt iKey;
1.195 + TStreamId iStream;
1.196 + };
1.197 +
1.198 +private:
1.199 +
1.200 + NONSHARABLE_CLASS(CSchScheduleDictionary) : public CBase
1.201 + {
1.202 + public:
1.203 + static CSchScheduleDictionary* NewLC();
1.204 + ~CSchScheduleDictionary();
1.205 +
1.206 + private:
1.207 + CSchScheduleDictionary();
1.208 + void ConstructL();
1.209 +
1.210 + public:
1.211 + void AssignL(TInt aKey, TStreamId aId);
1.212 + void Remove(TInt aKey);
1.213 + TInt Count() const;
1.214 + //
1.215 + TStreamId At(TInt aKey) const;
1.216 + TStreamId AtIndex(TInt aIndex) const;
1.217 + //
1.218 + void InternalizeL(RReadStream& aStream);
1.219 + void ExternalizeL(RWriteStream& aStream) const;
1.220 +
1.221 + private:
1.222 + CArrayFix<TSchScheduleMapplet>* iMappings;
1.223 + };
1.224 +
1.225 +private:
1.226 + CSchScheduleDictionary* DictionaryLC(CStreamStore& aStore, TStreamId aIndexStream);
1.227 + void StoreDictionaryL(CStreamStore& aStore, const CSchScheduleDictionary& aDictionary, TStreamId aStreamToReplace);
1.228 + };
1.229 +
1.230 +
1.231 +/**
1.232 +@internalComponent
1.233 +*/
1.234 +class CSchClientIndex : public CBase
1.235 + {
1.236 +public:
1.237 + static CSchClientIndex* NewL(RFs& aFsSession);
1.238 +
1.239 +private:
1.240 + CSchClientIndex(RFs& aFsSession);
1.241 +
1.242 +public:
1.243 + void RestoreClientsL(TPriQue<CClientProxy>& aClients,
1.244 + CStreamStore& aStore,
1.245 + TStreamId aIndexStream,
1.246 + CSchLogManager& aSchLogManager,TBool aBUR=EFalse);
1.247 + TStreamId CreateEmptyIndexL(CStreamStore& aStore) const;
1.248 + void AppendClientToListL(TPriQue<CClientProxy>& aClients, CClientProxy* aClient);
1.249 +public:
1.250 + void AddL(TStreamId aIndexStream, CStreamStore& aStore, const CClientProxy& aClient);
1.251 + void EditL(TStreamId aIndexStream, CStreamStore& aStore, const CClientProxy& aClient);
1.252 + void DeleteL(TStreamId aIndexStream, CStreamStore& aStore, const CClientProxy& aClient);
1.253 +
1.254 +public:
1.255 + NONSHARABLE_CLASS(CSchClientMapplet) : public CBase
1.256 + {
1.257 + public:
1.258 + static CSchClientMapplet* NewLC(RReadStream& aStream);
1.259 + static CSchClientMapplet* NewLC(const TDesC& aKey, TStreamId aStream);
1.260 + ~CSchClientMapplet();
1.261 +
1.262 + public:
1.263 + void InternalizeL(RReadStream& aStream);
1.264 + void ExternalizeL(RWriteStream& aStream) const;
1.265 +
1.266 + public:
1.267 + inline const TDesC& Key() const { return *iKey; }
1.268 + inline TStreamId Stream() const { return iStream; }
1.269 + //
1.270 + inline void SetStream(TStreamId aStream) { iStream = aStream; }
1.271 + //
1.272 + inline static TInt KeyOffset() { return _FOFF(CSchClientMapplet, iStream); }
1.273 +
1.274 + private:
1.275 + HBufC* iKey;
1.276 + TStreamId iStream;
1.277 + };
1.278 +
1.279 +private:
1.280 + NONSHARABLE_CLASS(CSchClientDictionary) : public CBase
1.281 + {
1.282 + public:
1.283 + static CSchClientDictionary* NewLC();
1.284 + ~CSchClientDictionary();
1.285 +
1.286 + private:
1.287 + CSchClientDictionary();
1.288 + void ConstructL();
1.289 +
1.290 + public:
1.291 + void AssignL(const TDesC& aKey, TStreamId aId);
1.292 + void RemoveL(const TDesC& aKey);
1.293 + TInt Count() const;
1.294 + TStreamId AtL(const TDesC& aKey) const;
1.295 + TStreamId AtIndex(TInt aIndex) const;
1.296 +
1.297 + public:
1.298 + void InternalizeL(RReadStream& aStream);
1.299 + void ExternalizeL(RWriteStream& aStream) const;
1.300 +
1.301 + private:
1.302 + CArrayPtr<CSchClientMapplet>* iMappings;
1.303 + };
1.304 +
1.305 +private:
1.306 + CSchClientDictionary* DictionaryLC(CStreamStore& aStore, TStreamId aIndexStream);
1.307 + void StoreDictionaryL(CStreamStore& aStore, const CSchClientDictionary& aDictionary, TStreamId aStreamToReplace);
1.308 +
1.309 +private:
1.310 + RFs& iFsSession;
1.311 + };
1.312 +
1.313 +
1.314 +#endif