|
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: Implements the playback plugin handler. |
|
15 * |
|
16 * There is just one plaback plugin loaded for each plugin handler / engine and |
|
17 * whenever a new plugin is selected for the engine the old one is automatically |
|
18 * unloaded. Different engines can load multiple instances of the same playback |
|
19 * plugin, however there is no connection between these instances as they |
|
20 * are tied to different songs. |
|
21 * |
|
22 * There is no point in applying the reference counting mechanism for playback. |
|
23 * |
|
24 * |
|
25 */ |
|
26 |
|
27 |
|
28 #include <mpxplaybackplugin.h> |
|
29 #include <mpxplaybackpluginobserver.h> |
|
30 #include <mpxpluginmonitor.h> |
|
31 #include <mpxlog.h> |
|
32 #include "mpxplaybackplugininfo.h" |
|
33 #include "mpxplaybackpluginhandler.h" |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS ============================== |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // Two-phased constructor. |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 CMPXPlaybackPluginHandler* CMPXPlaybackPluginHandler::NewL( |
|
42 CMPXPluginMonitor& aPluginMonitor, |
|
43 MMPXPlaybackPluginObserver& aPluginObserver, |
|
44 MMPXPluginHandlerObserver& aObserver) |
|
45 { |
|
46 CMPXPlaybackPluginHandler* p=new(ELeave)CMPXPlaybackPluginHandler( |
|
47 aPluginMonitor, |
|
48 aPluginObserver, |
|
49 aObserver); |
|
50 CleanupStack::PushL(p); |
|
51 p->ConstructL(); |
|
52 CleanupStack::Pop(p); |
|
53 return p; |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // Constructor. |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 CMPXPlaybackPluginHandler::CMPXPlaybackPluginHandler( |
|
61 CMPXPluginMonitor& aPluginMonitor, |
|
62 MMPXPlaybackPluginObserver& aPluginObserver, |
|
63 MMPXPluginHandlerObserver& aObserver) |
|
64 : CMPXPluginHandlerBase(KMPXPlaybackInterfaceUid, |
|
65 ESelectionType, |
|
66 EPbLocal, |
|
67 aObserver, |
|
68 &aPluginMonitor), |
|
69 iPluginObserver(&aPluginObserver), |
|
70 iSelectedSubPlayerIndex(KErrNotFound) |
|
71 { |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------------------------- |
|
75 // 2nd phase constructor. |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 void CMPXPlaybackPluginHandler::ConstructL() |
|
79 { |
|
80 BaseConstructL(); |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // Destructor. |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 CMPXPlaybackPluginHandler::~CMPXPlaybackPluginHandler() |
|
88 { |
|
89 MPX_FUNC_EX("CMPXPlaybackPluginHandler::Destructor"); |
|
90 //close plugins |
|
91 for (TInt i = iLoadedPlugins.Count(); --i >= 0;) |
|
92 { |
|
93 CMPXPlaybackPlugin* p=iLoadedPlugins[i]; |
|
94 TRAP_IGNORE(p->CommandL(EPbCmdClose)); |
|
95 } |
|
96 iLoadedPlugins.ResetAndDestroy(); |
|
97 iLoadedPluginsUids.Close(); |
|
98 delete iDisplayName; |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // Resolve a plugin to iPlugin, based on properties (iDataType, iExt and iScheme) |
|
103 // and selection criteria. If selection is by type, then there is always a |
|
104 // plug-in resolved (if there are any of that type). Room for optimisation. |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 void CMPXPlaybackPluginHandler::ResolvePluginL() |
|
108 { |
|
109 MPX_FUNC_EX("CMPXPlaybackPluginHandler::ResolvePluginL()"); |
|
110 // |
|
111 // Resolve plugin |
|
112 // |
|
113 TUid pluginUid( KNullUid ); |
|
114 TInt index( KErrNotFound ); |
|
115 TPtrC displayName; |
|
116 TInt pluginType( EPbUnknown ); |
|
117 |
|
118 DoResolvePluginL(pluginUid, index, displayName, pluginType ); |
|
119 |
|
120 // |
|
121 // Load resolved plug-in |
|
122 // |
|
123 CMPXPlaybackPlugin* p=CreatePlayerPluginL(pluginUid); |
|
124 UsePlugin(pluginUid); |
|
125 |
|
126 MPX_DEBUG5("CMPXPlaybackPluginHandler::ResolvePluginL() p(%08x), iPlugin(%08x), pluginUid 0x%08x %S", |
|
127 p, iPlugin, pluginUid.iUid, &displayName); |
|
128 if (p!=iPlugin) |
|
129 { |
|
130 if (iPlugin) |
|
131 { |
|
132 UnloadPlugin(iPluginUid); |
|
133 } |
|
134 iPlugin=p; |
|
135 iPluginUid=pluginUid; |
|
136 |
|
137 delete iDisplayName; |
|
138 iDisplayName=NULL; |
|
139 iDisplayName=displayName.AllocL(); |
|
140 iPluginType=static_cast<TMPXPlaybackPlayerType>(pluginType); |
|
141 } |
|
142 |
|
143 if (iSelectedSubPlayerIndex!=KErrNotFound) |
|
144 { |
|
145 iPlugin->SelectSubPlayerL(iSelectedSubPlayerIndex); |
|
146 } |
|
147 } |
|
148 |
|
149 // ---------------------------------------------------------------------------- |
|
150 // Return a plugin with the specific id |
|
151 // ---------------------------------------------------------------------------- |
|
152 // |
|
153 CMPXPlaybackPlugin* CMPXPlaybackPluginHandler::CreatePlayerPluginL( |
|
154 const TUid& aUid) |
|
155 { |
|
156 MPX_DEBUG3("==>CMPXPlaybackPluginHandler::CreatePlayerPluginL 0x%08x (aUid 0x%08x)", |
|
157 this, aUid.iUid); |
|
158 CMPXPlaybackPlugin* p=NULL; |
|
159 TInt i=iLoadedPluginsUids.Find(aUid); |
|
160 if (i==KErrNotFound) |
|
161 { |
|
162 p=CMPXPlaybackPlugin::NewL(aUid,*iPluginObserver); |
|
163 CleanupStack::PushL(p); |
|
164 iLoadedPlugins.AppendL(p); |
|
165 TInt err = iLoadedPluginsUids.Append(aUid); |
|
166 if (err != KErrNone) // if the second append failed, it should revert the first append |
|
167 { |
|
168 iLoadedPlugins.Remove(iLoadedPlugins.Count()-1); |
|
169 User::Leave(err); |
|
170 } |
|
171 CleanupStack::Pop(p); |
|
172 } |
|
173 else |
|
174 { |
|
175 p=iLoadedPlugins[i]; |
|
176 } |
|
177 MPX_DEBUG3("<==CMPXPlaybackPluginHandler::CreatePlayerPluginL 0x%08x (aUid 0x%08x)", |
|
178 this, aUid.iUid); |
|
179 return p; |
|
180 } |
|
181 |
|
182 // ---------------------------------------------------------------------------- |
|
183 // CMPXPlaybackPluginHandler::IsPluginLoaded |
|
184 // ---------------------------------------------------------------------------- |
|
185 // |
|
186 TBool CMPXPlaybackPluginHandler::IsPluginLoaded( |
|
187 const TUid& aPluginUid) |
|
188 { |
|
189 MPX_FUNC_EX("CMPXPlaybackPluginHandler::IsPluginLoaded"); |
|
190 return (iLoadedPluginsUids.Find(aPluginUid) != KErrNotFound); |
|
191 } |
|
192 |
|
193 // ---------------------------------------------------------------------------- |
|
194 // CMPXPlaybackPluginHandler::LoadPluginL |
|
195 // ---------------------------------------------------------------------------- |
|
196 // |
|
197 void CMPXPlaybackPluginHandler::LoadPluginL( |
|
198 const TUid& aPluginUid) |
|
199 { |
|
200 MPX_DEBUG2("===>CMPXPlaybackPluginHandler::LoadPluginL 0x%08x", this); |
|
201 |
|
202 if (iPlugin) |
|
203 { |
|
204 UnloadPlugin(iPluginUid); |
|
205 } |
|
206 |
|
207 iPlugin = CreatePlayerPluginL(aPluginUid); |
|
208 iPluginUid = aPluginUid; |
|
209 |
|
210 delete iDisplayName; |
|
211 iDisplayName = NULL; |
|
212 iDisplayName = PluginName(aPluginUid).AllocL(); |
|
213 MPX_DEBUG3("<===CMPXPlaybackPluginHandler::LoadPluginL 0x%08x plugin name %S", |
|
214 this, iDisplayName); |
|
215 } |
|
216 |
|
217 // ---------------------------------------------------------------------------- |
|
218 // Constructs the collection plugin info class |
|
219 // ---------------------------------------------------------------------------- |
|
220 // |
|
221 CMPXPluginInfo* |
|
222 CMPXPlaybackPluginHandler::ConstructPluginInfoLC( |
|
223 const CImplementationInformation& aData ) |
|
224 { |
|
225 return CMPXPlaybackPluginInfo::NewLC( aData ); |
|
226 } |
|
227 |
|
228 // ---------------------------------------------------------------------------- |
|
229 // Unload the plugin |
|
230 // ---------------------------------------------------------------------------- |
|
231 // |
|
232 void CMPXPlaybackPluginHandler::UnloadPlugin( |
|
233 const TUid& aUid) |
|
234 { |
|
235 MPX_FUNC_EX("CMPXPlaybackPluginHandler::UnloadPlugin"); |
|
236 |
|
237 TInt index(iLoadedPluginsUids.Find(aUid)); |
|
238 if (index != KErrNotFound) |
|
239 { |
|
240 UnloadPlugin(index); |
|
241 } |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // Return player name |
|
246 // ---------------------------------------------------------------------------- |
|
247 // |
|
248 EXPORT_C const TDesC& CMPXPlaybackPluginHandler::PlayerName( |
|
249 TMPXPlaybackPlayerType aType) const |
|
250 { |
|
251 MPX_FUNC("CMPXPlaybackPluginHandler::PlayerName()"); |
|
252 return PluginName(aType); |
|
253 } |
|
254 |
|
255 // ---------------------------------------------------------------------------- |
|
256 // Get player list with the specific type |
|
257 // ---------------------------------------------------------------------------- |
|
258 // |
|
259 EXPORT_C void CMPXPlaybackPluginHandler::GetPlayerListL( |
|
260 RArray<TUid>& aPlayers, |
|
261 TMPXPlaybackPlayerType aType) |
|
262 { |
|
263 MPX_FUNC("CMPXPlaybackPluginHandler::GetPlayerListL()"); |
|
264 GetPluginUidsL(aPlayers, aType); |
|
265 } |
|
266 |
|
267 // ---------------------------------------------------------------------------- |
|
268 // Select players with the specific type |
|
269 // ---------------------------------------------------------------------------- |
|
270 // |
|
271 EXPORT_C void CMPXPlaybackPluginHandler::SelectPlayersL( |
|
272 TMPXPlaybackPlayerType aType) |
|
273 { |
|
274 MPX_FUNC("CMPXPlaybackPluginHandler::SelectPlayersL(TMPXPlaybackPlayerType aType)"); |
|
275 iSelectedSubPlayerIndex=KErrNotFound; |
|
276 SelectPluginL(aType); |
|
277 } |
|
278 |
|
279 // ---------------------------------------------------------------------------- |
|
280 // Returns plug-in appropriate for a Uri and data type |
|
281 // ---------------------------------------------------------------------------- |
|
282 // |
|
283 void CMPXPlaybackPluginHandler::SelectPlayerL( |
|
284 const TDesC& aUri, |
|
285 const TDesC8& aDataType) |
|
286 { |
|
287 MPX_FUNC("CMPXPlaybackPluginHandler::SelectPlayerL(const TDesC& aUri)"); |
|
288 MPX_DEBUG2("CMPXPlaybackPluginHandler::SelectPlayerL(aUri %S)", &aUri); |
|
289 SelectPluginL( aUri, aDataType ); |
|
290 } |
|
291 |
|
292 // ---------------------------------------------------------------------------- |
|
293 // Returns plug-in appropriate for a file; may already be loaded or not |
|
294 // ---------------------------------------------------------------------------- |
|
295 // |
|
296 void CMPXPlaybackPluginHandler::SelectPlayerL(RFile& aFile) |
|
297 { |
|
298 MPX_FUNC("CMPXPlaybackPluginHandler::SelectPlayerL(RFile& aFile)"); |
|
299 SelectPluginL( aFile ); |
|
300 } |
|
301 |
|
302 // ---------------------------------------------------------------------------- |
|
303 // Select players with the specific UID |
|
304 // ---------------------------------------------------------------------------- |
|
305 // |
|
306 EXPORT_C void CMPXPlaybackPluginHandler::SelectPlayerL(TUid aPlayerUid) |
|
307 { |
|
308 MPX_FUNC("CMPXPlaybackPluginHandler::SelectPlayerL(TUid aPlayerUid)"); |
|
309 SelectSubPlayerL(aPlayerUid,KErrNotFound); |
|
310 iSelectedType = iPluginType; |
|
311 } |
|
312 |
|
313 // ---------------------------------------------------------------------------- |
|
314 // Select subplayer |
|
315 // ---------------------------------------------------------------------------- |
|
316 // |
|
317 EXPORT_C void CMPXPlaybackPluginHandler::SelectSubPlayerL( |
|
318 TUid aPlayerUid, |
|
319 TInt aSubPlayerIndex) |
|
320 { |
|
321 MPX_FUNC("CMPXPlaybackPluginHandler::SelectPlayerL(TUid aPlayerUid, TInt aSubPlayerIndex)"); |
|
322 MPX_DEBUG3("CMPXPlaybackPluginHandler::SelectPlayerL(0x%08x, %d)", aPlayerUid.iUid, aSubPlayerIndex); |
|
323 iSelectedSubPlayerIndex=aSubPlayerIndex; |
|
324 SelectPluginL(aPlayerUid); |
|
325 } |
|
326 |
|
327 // ---------------------------------------------------------------------------- |
|
328 // Clear selection |
|
329 // ---------------------------------------------------------------------------- |
|
330 // |
|
331 EXPORT_C void CMPXPlaybackPluginHandler::ClearSelectPlayersL() |
|
332 { |
|
333 MPX_FUNC("CMPXPlaybackPluginHandler::ClearSelectPlayersL()"); |
|
334 SelectPlayersL(EPbLocal); |
|
335 } |
|
336 |
|
337 // ---------------------------------------------------------------------------- |
|
338 // Get current selection |
|
339 // ---------------------------------------------------------------------------- |
|
340 // |
|
341 EXPORT_C void CMPXPlaybackPluginHandler::GetSelection( |
|
342 TMPXPlaybackPlayerType& aType, |
|
343 TUid& aPlayer, |
|
344 TInt& aSubPlayerIndex, |
|
345 TPtrC& aSubPlayerName) |
|
346 { |
|
347 MPX_FUNC("CMPXPlaybackPluginHandler::GetSelectionL()"); |
|
348 aType=iPluginType; |
|
349 aPlayer=iSelectedUid; |
|
350 aSubPlayerIndex=iSelectedSubPlayerIndex; |
|
351 if ( iPlugin ) |
|
352 { |
|
353 aSubPlayerName.Set(iPlugin->SubPlayerName()); |
|
354 } |
|
355 else |
|
356 { |
|
357 aSubPlayerName.Set(KNullDesC); |
|
358 } |
|
359 } |
|
360 |
|
361 // ---------------------------------------------------------------------------- |
|
362 // Return a list of interfaces supported by the plugins |
|
363 // ---------------------------------------------------------------------------- |
|
364 // |
|
365 EXPORT_C CDesCArray* CMPXPlaybackPluginHandler::SupportedInterfacesL() |
|
366 { |
|
367 CDesCArray* descArray = new(ELeave)CDesCArrayFlat(KMPXArrayGranularity); |
|
368 for(TInt i=iPluginInfoArray.Count();--i>=0;) |
|
369 { |
|
370 CMPXPlaybackPluginInfo* pi = |
|
371 static_cast<CMPXPlaybackPluginInfo*>(iPluginInfoArray[i]); |
|
372 MPXUser::MergeArray(pi->SupportedInterfaces(), *descArray); |
|
373 } |
|
374 return descArray; |
|
375 } |
|
376 |
|
377 // ---------------------------------------------------------------------------- |
|
378 // Return a list of interfaces supported by the plugins |
|
379 // ---------------------------------------------------------------------------- |
|
380 // |
|
381 EXPORT_C CDesCArray* CMPXPlaybackPluginHandler::SupportedInterfacesL(const TUid& aUid) |
|
382 { |
|
383 CDesCArray* descArray = new(ELeave)CDesCArrayFlat(KMPXArrayGranularity); |
|
384 CleanupStack::PushL(descArray); |
|
385 for(TInt i=iPluginInfoArray.Count();--i>=0;) |
|
386 { |
|
387 if (aUid == iPluginInfoArray[i]->ImplementationUid()) |
|
388 { |
|
389 CMPXPlaybackPluginInfo* pi = |
|
390 static_cast<CMPXPlaybackPluginInfo*>(iPluginInfoArray[i]); |
|
391 MPXUser::CopyArrayL(pi->SupportedInterfaces(), *descArray); |
|
392 break; |
|
393 } |
|
394 } |
|
395 CleanupStack::Pop(descArray); |
|
396 return descArray; |
|
397 } |
|
398 |
|
399 // ---------------------------------------------------------------------------- |
|
400 // CMPXPlaybackPluginHandler::UnloadPlugin |
|
401 // ---------------------------------------------------------------------------- |
|
402 // |
|
403 void CMPXPlaybackPluginHandler::UnloadPlugin( |
|
404 TInt aIndex) |
|
405 { |
|
406 CMPXPlaybackPlugin* p = iLoadedPlugins[aIndex]; |
|
407 TRAP_IGNORE(p->CommandL(EPbCmdClose)); |
|
408 iLoadedPlugins.Remove(aIndex); |
|
409 iLoadedPluginsUids.Remove(aIndex); |
|
410 if (p == iPlugin) |
|
411 { |
|
412 iPlugin = NULL; |
|
413 } |
|
414 delete p; |
|
415 } |
|
416 |
|
417 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
418 // ---------------------------------------------------------------------------- |
|
419 // Returns plug-in appropriate for a file; may already be loaded or not |
|
420 // ---------------------------------------------------------------------------- |
|
421 // |
|
422 void CMPXPlaybackPluginHandler::SelectPlayer64L(RFile64& aFile) |
|
423 { |
|
424 MPX_FUNC("CMPXPlaybackPluginHandler::SelectPlayer64L(RFile64& aFile)"); |
|
425 SelectPlugin64L( aFile ); |
|
426 } |
|
427 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
428 |
|
429 // end of file |