|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef WRITERPLUGINLOADER_H |
|
20 #define WRITERPLUGINLOADER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <ecom/implementationinformation.h> |
|
25 #include <piprofiler/ProfilerConfig.h> |
|
26 #include <piprofiler/WriterPluginInterface.h> |
|
27 #include <piprofiler/ProfilerTraces.h> |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 // Value for a to b comparison result when logically a == b. |
|
32 const TInt KWriterComparisonEqual = 0; |
|
33 |
|
34 // Value for a to b comparison result when logically a < b. |
|
35 const TInt KWriterComparisonBefore = -1; |
|
36 |
|
37 // Value for a to b comparison result when logically a > b. |
|
38 const TInt KWriterComparisonAfter = 1; |
|
39 |
|
40 // CLASS DEFINITIONS |
|
41 class CWriterPluginInterface; |
|
42 class MWriterPluginLoadObserver; |
|
43 class REComSession; |
|
44 |
|
45 /** |
|
46 * CWriterPluginLoader. Mechanism used to load plugins asynchronously. Uses |
|
47 * MWriterPluginLoadObserver as a callback. |
|
48 * |
|
49 * @lib ProfilerEngine.exe/.lib??????????? |
|
50 * @since Series60_30.1 |
|
51 */ |
|
52 class CWriterPluginLoader : public CActive |
|
53 { |
|
54 public: // Constructor and destructor |
|
55 |
|
56 /** |
|
57 * Two-phased constructor. |
|
58 * |
|
59 * @param aAppUi Pointer to application UI. Does not take ownership. |
|
60 */ |
|
61 static CWriterPluginLoader* NewL(); |
|
62 |
|
63 /** |
|
64 * Destructor |
|
65 */ |
|
66 ~CWriterPluginLoader(); |
|
67 |
|
68 private: // Internal construction |
|
69 |
|
70 /** |
|
71 * Default C++ contructor |
|
72 */ |
|
73 CWriterPluginLoader(); |
|
74 |
|
75 /** |
|
76 * Symbian OS default constructor |
|
77 * @return void |
|
78 */ |
|
79 void ConstructL(); |
|
80 |
|
81 public: // API |
|
82 |
|
83 /** |
|
84 * Starts loading GS plug-ins asynchronously. Will call |
|
85 * MWriterPluginLoadObserver::HandlePluginLoaded() each time a plug-in is |
|
86 * loaded and when all plugins are loaded. |
|
87 * |
|
88 * CWriterPluginLoader transfers the ownership of each loaded plugin view to |
|
89 * CAknViewAppUi. It is client's responsibility to remove the views from |
|
90 * CAknViewAppUi and delete the plugins if necessary. |
|
91 * |
|
92 * @param aInterfaceUid Uid ofthe interfaces to be loaded. |
|
93 * @param aParentUid Uid of the parent. Only children of this parent |
|
94 * will be loaded. |
|
95 * @param aPluginArray An array for the loaded GS plug-ins. |
|
96 * CWriterPluginLoader does not take the ownership of this array. |
|
97 */ |
|
98 void LoadAsyncL( CArrayPtrFlat<CWriterPluginInterface>* aPluginArray ); |
|
99 |
|
100 /** |
|
101 * Load a specific plugin instance synchronously. |
|
102 * |
|
103 * @param aInterfaceUid Uid ofthe interfaces to be loaded. |
|
104 * @param aImplementationUid Uid of the implementation to load |
|
105 */ |
|
106 CWriterPluginInterface& LoadSyncL( TUid aImplementationUid ); |
|
107 |
|
108 /** |
|
109 * Sets observer for this loader. Only one observer per loader in one |
|
110 * time is possible. |
|
111 */ |
|
112 void SetObserver(MWriterPluginLoadObserver* aObserver); |
|
113 |
|
114 /** |
|
115 * Aborts asynchronous loading of the GS plug-ins. |
|
116 */ |
|
117 void AbortAsyncLoad(); |
|
118 |
|
119 /** |
|
120 * Sorts the plugin array. |
|
121 * |
|
122 * Sorting criterias: |
|
123 * |
|
124 * 1. Order number if provider category is Internal. |
|
125 * 2. Provider category. Precedence as follows: |
|
126 * 3. Alphabetical |
|
127 * |
|
128 * @param aPlugins The array which will be sorted. |
|
129 */ |
|
130 void SortPluginsL( CArrayPtrFlat<CWriterPluginInterface>* aPlugins ); |
|
131 |
|
132 private: // Internal methods |
|
133 |
|
134 /** |
|
135 * Starts loading next plugin. |
|
136 */ |
|
137 void LoadNextPluginL(); |
|
138 |
|
139 /** |
|
140 * Creates a plugin instance from given UID. Ownership is transferred. |
|
141 */ |
|
142 CWriterPluginInterface& CreatePluginInstanceL( |
|
143 const CImplementationInformation& aImpInfo ); |
|
144 |
|
145 /** |
|
146 * Notifies MGSPluginLoadObserver. |
|
147 */ |
|
148 void NotifyProgress(); |
|
149 |
|
150 /** |
|
151 * Notifies MGSPluginLoadObserver. |
|
152 */ |
|
153 void NotifyFinished(); |
|
154 |
|
155 /** |
|
156 * Wait for the next round of CActive execution. |
|
157 */ |
|
158 void CompleteOwnRequest(); |
|
159 |
|
160 // Insertion function used by sorting: |
|
161 |
|
162 /** |
|
163 * Inserts plugin in the correct position in the array using sorting |
|
164 * criterias. Assumes aPlugins is ordered. |
|
165 * |
|
166 * @param aPlugin The plugin to be inserted. |
|
167 * @param aPlugins Array in which the plugin is inserted into the |
|
168 * corresponding location. |
|
169 */ |
|
170 void InsertPluginInOrderL( |
|
171 CWriterPluginInterface* aPlugin, |
|
172 CArrayPtrFlat<CWriterPluginInterface>* aPlugins ); |
|
173 |
|
174 // Comparison functions: |
|
175 |
|
176 /** |
|
177 * Compares plugins according to comparison criterias. |
|
178 * |
|
179 * Note: GS internal comparison constants such as KGSComparisonEqual are |
|
180 * different from the ones outputted by this function. This is because |
|
181 * this function is also usable by RArray sort -functionality but BC |
|
182 * cannot be broken in GS. |
|
183 * |
|
184 * @return Negative value: If aFirst before aSecond. |
|
185 * 0: If equal. |
|
186 * Positive value: If aSecond before aFirst. |
|
187 */ |
|
188 static TInt Compare( const CWriterPluginInterface& aFirst, |
|
189 const CWriterPluginInterface& aSecond ); |
|
190 |
|
191 /** |
|
192 * |
|
193 * @return KGSComparisonEqual = equal indexes |
|
194 * KGSComparisonBefore = aFirst is before aSecond |
|
195 * KGSComparisonAfter = aFirst is after aSecond |
|
196 */ |
|
197 |
|
198 static TInt CompareIndex( |
|
199 const CWriterPluginInterface& aFirst, |
|
200 const CWriterPluginInterface& aSecond ); |
|
201 |
|
202 private: // Utility methods |
|
203 |
|
204 /** |
|
205 * Parses descriptor to UID. |
|
206 */ |
|
207 static TInt ParseToUid( const TDesC8& aSource, TUid& aTarget ); |
|
208 |
|
209 /** |
|
210 * Parsers plugin's order number |
|
211 */ |
|
212 static TInt ParseOrderNumber( const TDesC8& aSource, TInt& aOrderNumber ); |
|
213 |
|
214 /** |
|
215 * Print debug information. |
|
216 */ |
|
217 static void PrintInfoDebug( const CImplementationInformation& aInfo, |
|
218 TInt aIterator, |
|
219 TInt aPluginCount ); |
|
220 |
|
221 /** |
|
222 * Display loading error popup message. |
|
223 */ |
|
224 void DisplayErrorPopupL( TInt aError, |
|
225 const CImplementationInformation* aInfo ); |
|
226 |
|
227 private: // From CActive |
|
228 |
|
229 /** |
|
230 * See base class. |
|
231 */ |
|
232 void RunL(); |
|
233 |
|
234 /** |
|
235 * See base class. |
|
236 */ |
|
237 TInt RunError( TInt aError ); |
|
238 |
|
239 /** |
|
240 * See base class. |
|
241 */ |
|
242 void DoCancel(); |
|
243 |
|
244 private: // Data |
|
245 |
|
246 |
|
247 // Pluginloader goes through this array and loads the plugins into |
|
248 // iPluginArray if they fulfill the criterias. |
|
249 RImplInfoPtrArray iImplInfoArray; |
|
250 |
|
251 // Used as an iterator to maintain location in iImplInfoArray. |
|
252 TInt iImplInfoArrayIterator; |
|
253 |
|
254 // Array of loaded plugins.Plugins are owned by iAppUi. Only the array |
|
255 // pointers are owned by this class and therefore only reset array. |
|
256 CArrayPtrFlat<CWriterPluginInterface>* iPluginArray; |
|
257 |
|
258 // Pointer to observer. Not owned. |
|
259 MWriterPluginLoadObserver* iObserver; |
|
260 |
|
261 // Number of RunL calls. |
|
262 TInt iRunLDebugCount; |
|
263 }; |
|
264 |
|
265 |
|
266 /** |
|
267 * Interface for WriterPluginLoader observer. MWriterPluginLoadObserver gets |
|
268 * notifications when plugins are loaded. |
|
269 * |
|
270 * @lib ProfilerEngine.exe/.lib??????????? |
|
271 * @since Series60_30.1 |
|
272 */ |
|
273 |
|
274 class MWriterPluginLoadObserver |
|
275 { |
|
276 public: // Enums |
|
277 enum KWriterPluginLoaderStatus |
|
278 { |
|
279 // One plugin loaded successfully, continue to next. |
|
280 EWriterSuccess, |
|
281 // Loading one plugin failed, contiue to next. |
|
282 EWriterFail, |
|
283 // Client called AbortAsyncLoad(), finished loading. |
|
284 EWriterAborted, |
|
285 // All plugins loaded successfully, finished loading. |
|
286 EWriterFinished, |
|
287 // Severe error with loader, finished loading. |
|
288 EWriterError |
|
289 }; |
|
290 |
|
291 public: // New |
|
292 |
|
293 //CWriterPluginLoader calls this function when each plug-in is loaded or |
|
294 //loading is finished.. |
|
295 |
|
296 IMPORT_C virtual void HandlePluginLoaded( |
|
297 KWriterPluginLoaderStatus aStatus ) = 0; |
|
298 }; |
|
299 |
|
300 |
|
301 #endif // WRITERPLUGINLOADER_H |
|
302 // End of File |