|
1 /* |
|
2 * Copyright (c) 2010 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 "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: This file implements utilities like CPluginData. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef EMAILAPIUTILS_H |
|
19 #define EMAILAPIUTILS_H |
|
20 |
|
21 #include <e32base.h> |
|
22 #include "cfsmailcommon.h" |
|
23 #include <emailapidefs.h> |
|
24 |
|
25 //using namespace EmailInterface; |
|
26 |
|
27 class CFSMailPlugin; |
|
28 |
|
29 enum TDataOwner |
|
30 { |
|
31 EClientOwns, |
|
32 EAPIOwns |
|
33 }; |
|
34 |
|
35 |
|
36 /** |
|
37 * Helper container class for storing plugin pointer and implementation UID |
|
38 * @since S60 v5.2 |
|
39 */ |
|
40 NONSHARABLE_CLASS( TPluginData ) |
|
41 { |
|
42 public: |
|
43 |
|
44 inline TPluginData( TUid aUid ) : iPlugin( NULL ), iUid( TUid::Uid( aUid.iUid ) ) {} |
|
45 |
|
46 CFSMailPlugin* iPlugin; |
|
47 |
|
48 const TUid iUid; |
|
49 }; |
|
50 |
|
51 /** |
|
52 * Plugin data is a utility for protocol plugin creation and book |
|
53 * keeping. Objects using the plugin should access it via this |
|
54 * class for optimised reference counting. |
|
55 */ |
|
56 NONSHARABLE_CLASS( CPluginData ) : public CBase |
|
57 { |
|
58 public: |
|
59 /** |
|
60 * returns plugin instance or null if failed to instantiate. |
|
61 * LoadResult() will return error code in instantiation |
|
62 */ |
|
63 CFSMailPlugin* ClaimInstance(); |
|
64 |
|
65 /** |
|
66 * returns plugin instance or leaves if failed to instantiate. |
|
67 */ |
|
68 CFSMailPlugin* ClaimInstanceL(); |
|
69 |
|
70 /** |
|
71 * Decreases access count of the plugin and deletes if reaches zero. |
|
72 * Note! this should be called only aftre succesful ClaimInstance or |
|
73 * ClaimInstanceL. |
|
74 */ |
|
75 void ReleaseInstance(); |
|
76 |
|
77 /** |
|
78 * Adds cleanup operation calling ReleaseInstance to cleanup stack |
|
79 */ |
|
80 void ReleasePushL(); |
|
81 /** |
|
82 * Cleanup operation for CleanupReleasePluginPushL |
|
83 */ |
|
84 static void CleanupOperation( TAny* aAny ); |
|
85 |
|
86 TUid Uid() const; |
|
87 |
|
88 TInt LoadResult() const; |
|
89 |
|
90 private: |
|
91 /* only CEmailClientApi owns instances of this, it should make sure that |
|
92 * no duplicates exist, otherwise reference counting of plugins fail |
|
93 * (this is not singleton class) |
|
94 */ |
|
95 friend class CEmailClientApi; |
|
96 friend class CEmailMailboxCache; |
|
97 |
|
98 CPluginData( TUid aUid ); |
|
99 ~CPluginData(); |
|
100 |
|
101 private: |
|
102 // plugin pointer and uid |
|
103 TPluginData iData; |
|
104 |
|
105 TInt iPluginLoadError; |
|
106 |
|
107 // >0 when iPlugin is instantiated |
|
108 TUint iRefCount; |
|
109 |
|
110 // EFalse if shared from Email Framework (CFSMailClient). If true, |
|
111 // ReleaseInstance() doesn't delete plugin |
|
112 TBool iOwned; |
|
113 }; |
|
114 |
|
115 /** |
|
116 * Constructs internal message id type from plugin data and mailbox/folder/message id |
|
117 */ |
|
118 TFSMailMsgId FsMsgId( const CPluginData& aPluginData, const EmailInterface::TBaseId& aId ); |
|
119 |
|
120 /** |
|
121 * Cleanup support for pointer arrays |
|
122 */ |
|
123 template<class T> |
|
124 class CleanupResetAndDestroy |
|
125 { |
|
126 public: |
|
127 inline static void PushL( T& aItem ); |
|
128 |
|
129 private: |
|
130 inline static void ResetAndDestroy( TAny *aPtr ); |
|
131 } ; |
|
132 |
|
133 template <class T> |
|
134 inline void CleanupResetAndDestroyPushL( T& aRef ) |
|
135 { |
|
136 CleanupResetAndDestroy<T>::PushL( aRef ); |
|
137 } |
|
138 |
|
139 /** |
|
140 * Cleanup support for email interface objects. |
|
141 */ |
|
142 class CleanupReleasePush |
|
143 { |
|
144 public: |
|
145 static void PushL( EmailInterface::MEmailInterface& aItem ); |
|
146 |
|
147 private: |
|
148 static void Release( TAny *aPtr ); |
|
149 } ; |
|
150 |
|
151 |
|
152 #include "emailapiutils.inl" |
|
153 |
|
154 |
|
155 #endif // EMAILAPIUTILS_H |
|
156 |
|
157 // End of file |