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