|
1 /* |
|
2 * Copyright (c) 2006 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: Playlist Plugin Handler |
|
15 * |
|
16 * CMPXPlaylistPluginHandler inherits from CMPXPluginHandlerBase which owns a |
|
17 * CMPXPluginMonitor that monitors playlist plugins. |
|
18 * |
|
19 * CMPXPlaylistPluginHandler also contains a list of loaded playlist plugins. |
|
20 * A playlist plugin is added to the list when it's selected for the first |
|
21 * time. When a new plugin is installed, CMPXPluginMonitor notifies this plugin |
|
22 * handler through CMPXPluginMonitorObserver interface. However, the new plugin |
|
23 * will not be loaded at this time until a client explictly selects this new |
|
24 * plugin. |
|
25 * |
|
26 * When a plugin is uninstalled, CMPXPluginMonitor also notifies this plugin |
|
27 * handler through CMPXPluginMonitorObserver interface. If such plugin is |
|
28 * currently loaded, it will be unloaded and removed from the list. All plugins |
|
29 * are removed when CMPXPlaylistPluginHandler is destroyed. |
|
30 * |
|
31 * |
|
32 */ |
|
33 |
|
34 #include <bamdesca.h> |
|
35 #include <badesca.h> |
|
36 #include <uri16.h> |
|
37 #include <apgcli.h> |
|
38 |
|
39 #include <mpxlog.h> |
|
40 #include <mpxuser.h> |
|
41 #include <mpxpluginmonitor.h> |
|
42 #include <mpxpluginhandlerobserver.h> |
|
43 #include "mpxplaylistenginedefs.hrh" |
|
44 #include "mpxplaylistpluginhandler.h" |
|
45 #include "mpxplaylistplugin.h" |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 // ============================ MEMBER FUNCTIONS ============================== |
|
51 // ---------------------------------------------------------------------------- |
|
52 // Constructor. |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 CMPXPlaylistPluginHandler::CMPXPlaylistPluginHandler( |
|
56 MMPXPlaylistPluginObserver& aPluginObserver, |
|
57 MMPXPluginHandlerObserver& aObserver, |
|
58 RFs& aFs, |
|
59 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& aTopCharacterSet, |
|
60 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& aAvailableCharacterSet) |
|
61 : CMPXPluginHandlerBase(TUid::Uid(KMPXPlaylistInterfaceUid), |
|
62 ESelectionType, |
|
63 EMPXPlaylistTypeM3U, |
|
64 aObserver), |
|
65 iPluginObserver(aPluginObserver), |
|
66 iFs(aFs), |
|
67 iTopCharacterSet(aTopCharacterSet), |
|
68 iAvailableCharacterSet(aAvailableCharacterSet), |
|
69 iPluginUid(KNullUid), |
|
70 iPluginType(EMPXPlaylistTypeUnknown) |
|
71 { |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------------------------- |
|
75 // 2nd phase constructor. |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 void CMPXPlaylistPluginHandler::ConstructL() |
|
79 { |
|
80 BaseConstructL(); |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // Two-phased constructor. |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 EXPORT_C CMPXPlaylistPluginHandler* CMPXPlaylistPluginHandler::NewL( |
|
88 MMPXPlaylistPluginObserver& aPluginObserver, |
|
89 MMPXPluginHandlerObserver& aObserver, |
|
90 RFs& aFs, |
|
91 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& aTopCharacterSet, |
|
92 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& aAvailableCharacterSet) |
|
93 { |
|
94 CMPXPlaylistPluginHandler* self = new(ELeave)CMPXPlaylistPluginHandler( |
|
95 aPluginObserver, aObserver, aFs, aTopCharacterSet, aAvailableCharacterSet); |
|
96 CleanupStack::PushL(self); |
|
97 self->ConstructL(); |
|
98 CleanupStack::Pop(self); |
|
99 return self; |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // Destructor. |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C CMPXPlaylistPluginHandler::~CMPXPlaylistPluginHandler() |
|
107 { |
|
108 iLoadedPlugins.ResetAndDestroy(); |
|
109 iLoadedPluginsUids.Close(); |
|
110 delete iDisplayName; |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // selects a plug-in appropriate for a Uri and data type |
|
115 // |
|
116 // This is a wrapper method for the base class's SelectPluginL to grant client |
|
117 // access and gives the method name some context. |
|
118 // ---------------------------------------------------------------------------- |
|
119 // |
|
120 EXPORT_C void CMPXPlaylistPluginHandler::SelectPlaylistPluginL( |
|
121 const TDesC& aUri, |
|
122 const TDesC8& aDataType) |
|
123 { |
|
124 MPX_DEBUG2("CMPXPlaylistPluginHandler::SelectPlaylistPluginL( URI: %S, DataType )", &aUri); |
|
125 |
|
126 ClearSelectionCriteria(); |
|
127 SelectPluginL( aUri, aDataType ); |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // selects a plug-in appropriate for a file |
|
132 // |
|
133 // This is a wrapper method for the base class's SelectPluginL to grant client |
|
134 // access and gives the method name some context. |
|
135 // ---------------------------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C void CMPXPlaylistPluginHandler::SelectPlaylistPluginL(const RFile& aFile) |
|
138 { |
|
139 MPX_DEBUG1("CMPXPlaylistPluginHandler::SelectPlaylistPluginL(RFile)"); |
|
140 |
|
141 ClearSelectionCriteria(); |
|
142 SelectPluginL( aFile ); |
|
143 } |
|
144 |
|
145 // ---------------------------------------------------------------------------- |
|
146 // selects a plug-in appropriate for a plugin type |
|
147 // |
|
148 // This is a wrapper method for the base class's SelectPluginL to grant client |
|
149 // access and gives the method name some context. |
|
150 // ---------------------------------------------------------------------------- |
|
151 // |
|
152 EXPORT_C void CMPXPlaylistPluginHandler::SelectPlaylistPluginL( |
|
153 TUint32 aPluginType) |
|
154 { |
|
155 MPX_DEBUG2("CMPXPlaylistPluginHandler::SelectPlaylistPluginL( ParserType: %x )", aPluginType); |
|
156 |
|
157 SelectPluginL( aPluginType ); |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // selects plug-in with the specified name |
|
162 // |
|
163 // This is a wrapper method for the base class's SelectPluginL to grant client |
|
164 // access and gives the method name some context. |
|
165 // ---------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C void CMPXPlaylistPluginHandler::SelectPlaylistPluginL( |
|
168 const TDesC& aPluginName) |
|
169 { |
|
170 MPX_DEBUG2("CMPXPlaylistPluginHandler::SelectPlaylistPluginL( aPluginName: %S )", &aPluginName); |
|
171 |
|
172 SelectPluginL( aPluginName ); |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------------------------------- |
|
176 // select a plugin with the specific id |
|
177 // |
|
178 // This is a wrapper method for the base class's SelectPluginL to grant client |
|
179 // access and gives the method name some context. |
|
180 // ---------------------------------------------------------------------------- |
|
181 // |
|
182 EXPORT_C void CMPXPlaylistPluginHandler::SelectPlaylistPluginL(const TUid& aUid) |
|
183 { |
|
184 MPX_DEBUG2("CMPXPlaylistPluginHandler::SelectPlaylistPluginL(UID: %x)", aUid.iUid); |
|
185 |
|
186 SelectPluginL( aUid ); |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // creates a plugin with the specific id. if already loaded, returns the reference |
|
191 // without recreating it |
|
192 // ---------------------------------------------------------------------------- |
|
193 // |
|
194 CMPXPlaylistPlugin* CMPXPlaylistPluginHandler::CreatePlaylistPluginL(const TUid& aUid) |
|
195 { |
|
196 MPX_DEBUG2("CMPXPlaylistPluginHandler::CreatePlaylistPluginL(UID: %x)", aUid.iUid); |
|
197 |
|
198 CMPXPlaylistPlugin* p(NULL); |
|
199 TInt i=iLoadedPluginsUids.Find(aUid); |
|
200 if (i==KErrNotFound) |
|
201 { |
|
202 p=CMPXPlaylistPlugin::NewL(aUid, iPluginObserver, iFs, iTopCharacterSet, iAvailableCharacterSet); |
|
203 CleanupStack::PushL(p); |
|
204 iLoadedPlugins.AppendL(p); |
|
205 TInt err = iLoadedPluginsUids.Append(aUid); |
|
206 if (err != KErrNone) // if the second append failed, it should revert the first append |
|
207 { |
|
208 iLoadedPlugins.Remove(iLoadedPlugins.Count()); |
|
209 User::Leave(err); |
|
210 } |
|
211 CleanupStack::Pop(p); |
|
212 } |
|
213 else |
|
214 { |
|
215 p=iLoadedPlugins[i]; |
|
216 } |
|
217 return p; |
|
218 } |
|
219 |
|
220 // ---------------------------------------------------------------------------- |
|
221 // Resolve a plugin to iPlugin, based on properties (iDataType, iExt and iScheme) |
|
222 // and selection criteria. |
|
223 // ---------------------------------------------------------------------------- |
|
224 // |
|
225 void CMPXPlaylistPluginHandler::ResolvePluginL() |
|
226 { |
|
227 MPX_DEBUG1("CMPXPlaylistPluginHandler::ResolvePluginL"); |
|
228 |
|
229 // |
|
230 // Resolve plugin |
|
231 // |
|
232 TUid pluginUid( KNullUid ); |
|
233 TInt index( KErrNotFound ); |
|
234 TPtrC displayName; |
|
235 TInt pluginType( EMPXPlaylistTypeUnknown ); |
|
236 |
|
237 DoResolvePluginL(pluginUid, index, displayName, pluginType ); |
|
238 |
|
239 // |
|
240 // Load resolved plug-in |
|
241 // |
|
242 CMPXPlaylistPlugin* p = CreatePlaylistPluginL(pluginUid); |
|
243 UsePlugin(pluginUid); |
|
244 |
|
245 if (p != iPlugin) |
|
246 { |
|
247 iPlugin = p; |
|
248 |
|
249 iPluginUid = pluginUid; |
|
250 |
|
251 delete iDisplayName; |
|
252 iDisplayName = NULL; |
|
253 iDisplayName = displayName.AllocL(); |
|
254 |
|
255 iPluginType = pluginType; |
|
256 } |
|
257 } |
|
258 |
|
259 // ---------------------------------------------------------------------------- |
|
260 // CMPXPlaylistPluginHandler::IsPluginLoaded |
|
261 // ---------------------------------------------------------------------------- |
|
262 // |
|
263 TBool CMPXPlaylistPluginHandler::IsPluginLoaded( |
|
264 const TUid& aPluginUid) |
|
265 { |
|
266 return iLoadedPluginsUids.Find(aPluginUid) != KErrNotFound; |
|
267 } |
|
268 |
|
269 // ---------------------------------------------------------------------------- |
|
270 // CMPXPlaylistPluginHandler::LoadPluginL |
|
271 // ---------------------------------------------------------------------------- |
|
272 // |
|
273 void CMPXPlaylistPluginHandler::LoadPluginL( |
|
274 const TUid& aPluginUid) |
|
275 { |
|
276 (void)CreatePlaylistPluginL(aPluginUid); |
|
277 } |
|
278 |
|
279 // ---------------------------------------------------------------------------- |
|
280 // Unloads a specified plugin. |
|
281 // ---------------------------------------------------------------------------- |
|
282 // |
|
283 void CMPXPlaylistPluginHandler::UnloadPlugin( |
|
284 const TUid& aPluginUid) |
|
285 { |
|
286 MPX_FUNC("CMPXPlaylistPluginHandler::UnloadPlugin"); |
|
287 TInt i = iLoadedPluginsUids.Find(aPluginUid); |
|
288 if (i != KErrNotFound) |
|
289 { |
|
290 UnloadPlugin(i); |
|
291 } |
|
292 } |
|
293 |
|
294 // ---------------------------------------------------------------------------- |
|
295 // Unloads a plugin by index. |
|
296 // ---------------------------------------------------------------------------- |
|
297 // |
|
298 void CMPXPlaylistPluginHandler::UnloadPlugin( |
|
299 TInt aIndex) |
|
300 { |
|
301 MPX_FUNC("CMPXPlaylistPluginHandler::UnloadPlugin"); |
|
302 |
|
303 CMPXPlaylistPlugin* p = iLoadedPlugins[aIndex]; |
|
304 if (p == iPlugin) |
|
305 { |
|
306 iPlugin = NULL; |
|
307 iPluginUid = KNullUid; |
|
308 iPluginType = EMPXPlaylistTypeUnknown; |
|
309 delete iDisplayName; |
|
310 iDisplayName = NULL; |
|
311 } |
|
312 |
|
313 iLoadedPlugins.Remove(aIndex); |
|
314 iLoadedPluginsUids.Remove(aIndex); |
|
315 delete p; |
|
316 } |
|
317 |
|
318 // End of file |