epoc32/include/cacheman.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 cacheman.h
     1 // Copyright (c) 1999-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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #if !defined (__CACHEMAN_H__)
       
    17 #define __CACHEMAN_H__
       
    18 
       
    19 #include <mentact.h>
       
    20 #include <msvstd.h>
       
    21 #include <msvapi.h>
       
    22 
       
    23 _LIT(KMiutWildCard, "*.*");
       
    24 
       
    25 class CImFinder : public CMsgActive
       
    26 /**
       
    27 @internalComponent
       
    28 @released
       
    29 */
       
    30 	{
       
    31 public:
       
    32 	IMPORT_C void FindFirstL(TMsvId aRootEntry, TRequestStatus &aStatus);
       
    33 	IMPORT_C ~CImFinder();
       
    34 	IMPORT_C virtual void FindNextL(TRequestStatus &aStatus);
       
    35 	void FindFirstL(const CMsvEntrySelection& aInitialSelection, TRequestStatus &aStatus);
       
    36 
       
    37 	class CImEntryStack : public CBase
       
    38 		{
       
    39 	public:
       
    40 		static CImEntryStack* NewL();
       
    41 		~CImEntryStack();
       
    42 		inline void PushL(TMsvId aId);
       
    43 		inline TMsvId PopL();
       
    44 		inline TBool Empty() const;
       
    45 		inline void Reset();
       
    46 
       
    47 	private:
       
    48 		void ConstructL();
       
    49 
       
    50 		CMsvEntrySelection* iFolders;
       
    51 		};
       
    52 
       
    53 protected:
       
    54 	void ConstructL();
       
    55 	CImFinder(CMsvEntry& aEntry);
       
    56 
       
    57 private:
       
    58 	void DoRunL();
       
    59 
       
    60 	virtual void AddChildEntriesL() = 0;
       
    61 	virtual TBool IsRequiredEntryType(TUid aEntryType) const = 0;
       
    62 
       
    63 protected:
       
    64 	CImEntryStack* iEntryStack;
       
    65 	CMsvEntry& iCurrentEntry;
       
    66 
       
    67 private:
       
    68 	enum TImmfState
       
    69 		{
       
    70 		EImmfEntryFound,
       
    71 		EImmfFindingEntry,
       
    72 		EImmfNothingFound
       
    73 		};
       
    74 
       
    75 	TImmfState iState;
       
    76 	};
       
    77 
       
    78 
       
    79 class CImMessageFinder : public CImFinder
       
    80 /**
       
    81 @internalComponent
       
    82 @released
       
    83 */
       
    84 	{
       
    85 public:
       
    86 	IMPORT_C static CImMessageFinder* NewL(CMsvEntry& aEntry);
       
    87 	IMPORT_C static CImMessageFinder* NewLC(CMsvEntry& aEntry);
       
    88 	
       
    89 protected:
       
    90 	virtual void AddChildEntriesL();
       
    91 	virtual TBool IsRequiredEntryType(TUid aEntryType) const;
       
    92 
       
    93 	CImMessageFinder(CMsvEntry& aEntry);
       
    94 	};
       
    95 
       
    96 
       
    97 class CImEntryFinder : public CImFinder
       
    98 /**
       
    99 @internalComponent
       
   100 @released
       
   101 */
       
   102 	{
       
   103 public:
       
   104 	IMPORT_C static CImEntryFinder* NewL(CMsvEntry& aEntry);
       
   105 	IMPORT_C static CImEntryFinder* NewLC(CMsvEntry& aEntry);
       
   106 	
       
   107 protected:
       
   108 	virtual void AddChildEntriesL();
       
   109 	virtual TBool IsRequiredEntryType(TUid aEntryType) const;
       
   110 
       
   111 	CImEntryFinder(CMsvEntry& aEntry);
       
   112 	};
       
   113 
       
   114 
       
   115 class CImMessageCounter : public CImFinder
       
   116 /**
       
   117 @internalComponent
       
   118 @released
       
   119 */
       
   120 	{
       
   121 public:
       
   122 	IMPORT_C static CImMessageCounter* NewL(CMsvEntry& aEntry);
       
   123 	IMPORT_C static CImMessageCounter* NewLC(CMsvEntry& aEntry);
       
   124 	IMPORT_C TInt Count();
       
   125 	
       
   126 protected:
       
   127 	virtual void AddChildEntriesL();
       
   128 	virtual TBool IsRequiredEntryType(TUid aEntryType) const;
       
   129 
       
   130 	CImMessageCounter(CMsvEntry& aEntry);
       
   131 
       
   132 private:
       
   133 	TInt iCount;
       
   134 	};
       
   135 
       
   136 
       
   137 class CImPruneMessage : public CMsgActive
       
   138 /** Deletes the body text and attachment data from an individually specified message. 
       
   139 
       
   140 Example uses of this class are:
       
   141 
       
   142 1. to cleanup after a populating operation has failed
       
   143 
       
   144 2. to remove body text and attachment data from remote messages, while preserving 
       
   145 the message structure 
       
   146 @publishedPartner 
       
   147 @released
       
   148 */
       
   149 	{
       
   150 public:
       
   151 	IMPORT_C static CImPruneMessage* NewL(CMsvEntry& aEntry, RFs& aFs);
       
   152 	IMPORT_C static CImPruneMessage* NewLC(CMsvEntry& aEntry, RFs& aFs);
       
   153 
       
   154 	IMPORT_C void StartL(TMsvId aMessageEntry, TRequestStatus &aStatus);
       
   155 	~CImPruneMessage();
       
   156 	
       
   157 private:
       
   158 	CImPruneMessage(CMsvEntry& aEntry, RFs& aFs);
       
   159 	void ConstructL();
       
   160 	void DoRunL();
       
   161 	void DoComplete(TInt& );
       
   162 	void DoCancel();
       
   163 	void PruneEntryL();
       
   164 	void ResetStoreL();
       
   165 
       
   166 private:
       
   167 	enum TImPruningState
       
   168 		{
       
   169 		EImPruneUpdatingEntry,
       
   170 		EImPruneUpdatingFirstEntry,
       
   171 		EImPruneFindingEntry,
       
   172 		EImPruneFindFirstEntry,
       
   173 		EImPruneFindNextEntry
       
   174 		};
       
   175 
       
   176 	TImPruningState iState;
       
   177 
       
   178 	CMsvEntry& iCurrentEntry;
       
   179 	RFs& iFs;
       
   180 	CImEntryFinder* iEntryFinder;
       
   181 	CFileMan* iFileManager;
       
   182 	TMsvId iRootEntryId;
       
   183 	CMsvOperation* iChangeOperation;
       
   184 	CMsvStore* iStore;
       
   185 	};
       
   186 
       
   187 struct TImCacheManagerProgress
       
   188 /** Holds progress of a cache management cleanup operation.
       
   189 
       
   190 @see CImCacheManager::ProgressL() 
       
   191 @publishedAll
       
   192 @released
       
   193 */
       
   194 	{
       
   195 public:
       
   196 	/** Total number of messages to process.
       
   197 	
       
   198 	Note that, immediately after a CImCacheManager object is started, the progress 
       
   199 	operation may return 1 for iTotalMessages and 0 for iMessagesProcessed, regardless 
       
   200 	of the total number of messages. This is because the counter for the iTotalMessages 
       
   201 	operates asynchronously and may not have counted all of the messages at that 
       
   202 	time. */
       
   203 	TInt iTotalMessages;
       
   204 	/** Number of messages processed so far. */
       
   205 	TInt iMessagesProcessed;
       
   206 	};
       
   207 
       
   208 class CImCacheManager : public CMsvOperation
       
   209 /** Provides management of the local cache of messages in remote mailboxes.
       
   210 
       
   211 A mailbox that is being used in disconnected mode allows the user access to 
       
   212 message data by opening the message directly from the remote mailbox. If the 
       
   213 required message has been downloaded previously, then it will not necessarily 
       
   214 need to be downloaded again. This functionality is achieved by preserving 
       
   215 the message data locally, under the remote service entry. The preserved message 
       
   216 data acts as a cache to allow the user access to the message without the need 
       
   217 for it to be downloaded every time. 
       
   218 
       
   219 The cache management functionality is required to reduce the amount of memory 
       
   220 that is consumed by the message cache. CImCacheManager provides a mechanism 
       
   221 for asynchronously traversing a message tree and for removing text and attachment 
       
   222 data from messages. Deleting more message data will free up more memory but 
       
   223 there is a higher chance that a user will need to download a message for a 
       
   224 second time. 
       
   225 
       
   226 CImCacheManager is an abstract base class, which can be specialised to implement 
       
   227 a filter (Filter()) that decides if data for a message shoulded be deleted: 
       
   228 for example, deletion could be restricted to 'all read messages over a week 
       
   229 old,' or, 'all read messages, over 20K in size which are also over a day old.' 
       
   230 @publishedAll
       
   231 @released
       
   232 */
       
   233 	{
       
   234 public:
       
   235 	IMPORT_C void StartL(TMsvId aRootEntry, TRequestStatus &aStatus);
       
   236 	IMPORT_C void StartL(const CMsvEntrySelection& aSelection, TRequestStatus &aStatus);
       
   237 	IMPORT_C ~CImCacheManager();
       
   238 	IMPORT_C const TDesC8& ProgressL();
       
   239 	IMPORT_C void DoCancel();
       
   240 
       
   241 protected:
       
   242 	IMPORT_C void ConstructL();
       
   243 	IMPORT_C CImCacheManager(CMsvSession& aSession, TRequestStatus& aObserverRequestStatus);
       
   244 
       
   245 	IMPORT_C void RunL();
       
   246 
       
   247 private:
       
   248 	// Override this function to filter the currently selected message (iCurrentEntry).
       
   249 	// Return TRUE if the current entry is to be pruned.
       
   250 	/** Tests if cache cleanup should be performed on a message entry.
       
   251 	
       
   252 	After StartL() has been called, this is called once for each message entry. 
       
   253 	It should return true if the body text and attachment data belonging to the 
       
   254 	current message, as held in iCurrentEntry, should be deleted, or false if 
       
   255 	the message should be left unchanged.
       
   256 	
       
   257 	This function must be implemented in any classes derived from CImCacheManager.
       
   258 	
       
   259 	@return True to clean the entry, false to leave it unchanged */
       
   260 	virtual TBool Filter() const = 0;
       
   261 
       
   262 	void DoRunL();
       
   263 
       
   264 	// Remove the store from the currently selected entry
       
   265 	inline void PruneMessageL();
       
   266 	
       
   267 protected:
       
   268 	/** Message entry currently being processed. */
       
   269 	CMsvEntry* iCurrentEntry;
       
   270 
       
   271 private:
       
   272 	CMsvSession& iSession;
       
   273 	CImMessageFinder* iMessageFinder;
       
   274 	CImMessageCounter* iMessageCounter;
       
   275 	CMsvOperation* iDeleteOperation;
       
   276 
       
   277 	TImCacheManagerProgress iProgress;
       
   278 	TRequestStatus* iReport;
       
   279 
       
   280 	enum TImcmState
       
   281 		{
       
   282 		EImcmLookingForMessage,
       
   283 		EImcmPruningMessages,
       
   284 		EImcmCountingMessages,
       
   285 		EImcmSkippingPrune
       
   286 		};
       
   287 
       
   288 	TMsvId iRootEntry;
       
   289 	TImcmState iState;
       
   290 	TPckgBuf<TImCacheManagerProgress> iProgressBuf;
       
   291 
       
   292 	CMsvEntrySelection* iMessagesToPrune;
       
   293 	};
       
   294 
       
   295 #endif