1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18
19 #ifndef OSCL_EXCLUSIVE_PTR_H_INCLUDED
20 #include "oscl_exclusive_ptr.h"
21 #endif
22 #ifndef PVLOGGER_H_INCLUDED
23 #include "pvlogger.h"
24 #endif
25 #ifndef PVMF_BASIC_ERRORINFOMESSAGE_H_INCLUDED
26 #include "pvmf_basic_errorinfomessage.h"
27 #endif
28 #ifndef PVMF_ERRORINFOMESSAGE_EXTENSION_H_INCLUDED
29 #include "pvmf_errorinfomessage_extension.h"
30 #endif
31 #ifndef PVMF_CPMPLUGIN_INTERFACE_H_INCLUDED
32 #include "pvmf_cpmplugin_interface.h"
33 #endif
34 #ifndef PVMF_CPMPLUGIN_AUTHORIZATION_INTERFACE_H_INCLUDED
35 #include "pvmf_cpmplugin_authorization_interface.h"
36 #endif
37 #ifndef PVMF_CPMPLUGIN_AUTHENTICATION_INTERFACE_H_INCLUDED
38 #include "pvmf_cpmplugin_authentication_interface.h"
39 #endif
40 #ifndef PVMF_CPMPLUGIN_ACCESS_INTERFACE_FACTORY_H_INCLUDED
41 #include "pvmf_cpmplugin_access_interface_factory.h"
42 #endif
43 #ifndef CPM_H_INCLUDED
44 #include "cpm.h"
45 #endif
46 #ifndef CPM_INTERNAL_H_INCLUDED
47 #include "cpm_internal.h"
48 #endif
49 #ifndef CPM_PLUGIN_REGISTRY_H
50 #include "cpm_plugin_registry.h"
51 #endif
52 #ifndef OSCL_DLL_H_INCLUDED
53 #include "oscl_dll.h"
54 #endif
55 #ifndef OSCL_MIME_STRING_UTILS_H
56 #include "pv_mime_string_utils.h"
57 #endif
58 // Define entry point for this DLL
OSCL_DLL_ENTRY_POINT_DEFAULT()59 OSCL_DLL_ENTRY_POINT_DEFAULT()
60
61 #include "oscl_registry_access_client.h"
62
63 static void _AddPluginInstance(CPMPluginRegistry* aRegistry, PVMFCPMPluginFactory* aFactory, const OSCL_String& aMimestring)
64 {
65 if (aRegistry
66 && aFactory)
67 {
68 //Create an instance of the plugin.
69 PVMFCPMPluginInterface* plugin = aFactory->CreateCPMPlugin();
70 if (plugin)
71 {
72 //Package the plugin with its user authentication data.
73 CPMPluginContainer container(*plugin, NULL);
74 //Add the plugin to the registry with its mime string.
75 aRegistry->addPluginToRegistry((OSCL_String&)aMimestring, container);
76 }
77 }
78 }
79
_RemovePluginInstance(CPMPluginRegistry * aRegistry,PVMFCPMPluginFactory * aFactory,const OSCL_String & aMimestring)80 static void _RemovePluginInstance(CPMPluginRegistry* aRegistry, PVMFCPMPluginFactory* aFactory, const OSCL_String& aMimestring)
81 {
82 if (aRegistry)
83 {
84 if (aFactory)
85 {
86 CPMPluginContainer* container = aRegistry->lookupPlugin((OSCL_String&)aMimestring);
87 if (container)
88 aFactory->DestroyCPMPlugin(&container->PlugIn());
89 }
90 aRegistry->removePluginFromRegistry((OSCL_String&)aMimestring);
91 }
92 }
93
94 #ifdef USE_LOADABLE_MODULES
95 #include "oscl_shared_library.h"
96 #include "osclconfig_lib.h"
97
_AddLoadablePlugins(CPMPluginRegistry * pRegistry)98 static void _AddLoadablePlugins(CPMPluginRegistry* pRegistry)
99 {
100 if (!pRegistry)
101 return;
102
103 //Create a list of all libs that implement CPM registry populator
104 pRegistry->AccessSharedLibraryList() = OSCL_NEW(OsclSharedLibraryList, ());
105 OSCL_HeapString<OsclMemAllocator> configPath = PV_DYNAMIC_LOADING_CONFIG_FILE_PATH;
106 pRegistry->AccessSharedLibraryList()->Populate(configPath, PVMF_CPM_PLUGIN_REGISTRY_POPULATOR_UUID);
107
108 //For each lib, add its factory to the registry.
109 for (uint32 i = 0; i < pRegistry->AccessSharedLibraryList()->Size(); i++)
110 {
111 OsclAny* temp = NULL;
112 pRegistry->AccessSharedLibraryList()->QueryInterfaceAt(i, temp);
113 PVMFCPMPluginRegistryPopulator* pop = (PVMFCPMPluginRegistryPopulator*) temp;
114 if (pop)
115 {
116 OSCL_HeapString<OsclMemAllocator> mimestring;
117 PVMFCPMPluginFactory* fac = pop->GetFactoryAndMimeString(mimestring);
118 if (fac)
119 _AddPluginInstance(pRegistry, fac, mimestring);
120 }
121 }
122 }
_RemoveLoadablePlugins(CPMPluginRegistry * aRegistry)123 static void _RemoveLoadablePlugins(CPMPluginRegistry* aRegistry)
124 {
125 if (!aRegistry)
126 return;
127
128 if (aRegistry->AccessSharedLibraryList())
129 {
130 //Loop through loaded modules & remove plugin from list.
131 for (uint32 i = 0; i < aRegistry->AccessSharedLibraryList()->Size(); i++)
132 {
133 OsclAny* temp = NULL;
134 aRegistry->AccessSharedLibraryList()->QueryInterfaceAt(i, temp);
135 PVMFCPMPluginRegistryPopulator* pop = (PVMFCPMPluginRegistryPopulator*) temp;
136 if (pop)
137 {
138 OSCL_HeapString<OsclMemAllocator> mimestring;
139 PVMFCPMPluginFactory* fac = pop->GetFactoryAndMimeString(mimestring);
140 if (fac)
141 {
142 _RemovePluginInstance(aRegistry, fac, mimestring);
143 pop->ReleaseFactory();
144 }
145 }
146 }
147
148 //Delete loaded module list
149 OSCL_DELETE(aRegistry->AccessSharedLibraryList());
150 aRegistry->AccessSharedLibraryList() = NULL;
151 }
152 }
153 #endif //USE_LOADABLE_MODULES
154
PopulateCPMPluginRegistry()155 static CPMPluginRegistry* PopulateCPMPluginRegistry()
156 {
157 //Create registry
158 CPMPluginRegistry* pRegistry = CPMPluginRegistryFactory::CreateCPMPluginRegistry();
159 if (pRegistry)
160 {
161 //Add plugins from global component registry.
162 OsclRegistryAccessClient cli;
163 if (cli.Connect() == OsclErrNone)
164 {
165 //Get all the current CPM plugin factory functions.
166 Oscl_Vector<OsclRegistryAccessElement, OsclMemAllocator> factories;
167 OSCL_HeapString<OsclMemAllocator> id("X-CPM-PLUGIN");//PVMF_MIME_CPM_PLUGIN
168 cli.GetFactories(id, factories);
169
170 //Add each plugin
171 for (uint32 i = 0; i < factories.size(); i++)
172 {
173 if (factories[i].iFactory)
174 {
175 _AddPluginInstance(pRegistry, (PVMFCPMPluginFactory*)factories[i].iFactory, factories[i].iMimeString);
176 }
177 }
178 cli.Close();
179 }
180 #ifdef USE_LOADABLE_MODULES
181 //Add plugins from loadable modules.
182 _AddLoadablePlugins(pRegistry);
183 #endif
184 }
185 return pRegistry;
186 }
187
DePopulateCPMPluginRegistry(CPMPluginRegistry * aRegistry)188 static void DePopulateCPMPluginRegistry(CPMPluginRegistry* aRegistry)
189 {
190 if (aRegistry)
191 {
192 #ifdef USE_LOADABLE_MODULES
193 //Remove dynamically loaded plugins
194 _RemoveLoadablePlugins(aRegistry);
195 #endif
196 //Remove plugins created by the global component registry.
197 OsclRegistryAccessClient cli;
198 if (cli.Connect() == OsclErrNone)
199 {
200 //Get all the current CPM plugin factory functions.
201 Oscl_Vector<OsclRegistryAccessElement, OsclMemAllocator> factories;
202 OSCL_HeapString<OsclMemAllocator> id("X-CPM-PLUGIN");//PVMF_MIME_CPM_PLUGIN
203 cli.GetFactories(id, factories);
204
205 for (uint32 i = 0; i < factories.size(); i++)
206 {
207 if (factories[i].iFactory)
208 {
209 _RemovePluginInstance(aRegistry, (PVMFCPMPluginFactory*)factories[i].iFactory, factories[i].iMimeString);
210 }
211 }
212 cli.Close();
213 }
214 //Destroy the plugin registry
215 CPMPluginRegistryFactory::DestroyCPMPluginRegistry(aRegistry);
216 }
217 }
218
219 OSCL_EXPORT_REF
CreateContentPolicyManager(PVMFCPMStatusObserver & aObserver)220 PVMFCPM* PVMFCPMFactory::CreateContentPolicyManager(PVMFCPMStatusObserver& aObserver)
221 {
222 PVMFCPM* cpm = NULL;
223 int32 err;
224 OSCL_TRY(err,
225 /*
226 * Create Content Policy Manager
227 */
228 cpm = OSCL_NEW(PVMFCPMImpl, (aObserver));
229 );
230 if (err != OsclErrNone)
231 {
232 OSCL_LEAVE(err);
233 }
234 return (cpm);
235 }
236
DestroyContentPolicyManager(PVMFCPM * aCPM)237 OSCL_EXPORT_REF void PVMFCPMFactory::DestroyContentPolicyManager(PVMFCPM* aCPM)
238 {
239 OSCL_DELETE(aCPM);
240 }
241
PVMFCPMImpl(PVMFCPMStatusObserver & aObserver,int32 aPriority)242 OSCL_EXPORT_REF PVMFCPMImpl::PVMFCPMImpl(PVMFCPMStatusObserver& aObserver,
243 int32 aPriority)
244 : OsclActiveObject(aPriority, "PVMFCPMImpl")
245 , iObserver(aObserver)
246 {
247 iPluginRegistry = NULL;
248 iLogger = NULL;
249 iNumQueryAuthenticationInterfacePending = 0;
250 iNumQueryAuthenticationInterfaceComplete = 0;
251 iNumRegisteredPlugInInitPending = 0;
252 iNumRegisteredPlugInInitComplete = 0;
253 iNumRegisteredPlugInResetPending = 0;
254 iNumRegisteredPlugInResetComplete = 0;
255 iNumQueryMetaDataExtensionInterfacePending = 0;
256 iNumQueryMetaDataExtensionInterfaceComplete = 0;
257 iLicenseInterface = NULL;
258 iNumQueryCapConfigExtensionInterfacePending = 0;
259 iNumQueryCapConfigExtensionInterfaceComplete = 0;
260
261 iGetMetaDataKeysFromPlugInsDone = false;
262 iGetMetaDataKeysInProgress = false;
263
264 iExtensionRefCount = 0;
265 iGetLicenseCmdId = 0;
266
267 int32 err = OsclErrNone;
268 OSCL_TRY(err,
269 /*
270 * Create the input command queue. Use a reserve to avoid lots of
271 * dynamic memory allocation
272 */
273 iInputCommands.Construct(PVMF_CPM_COMMAND_ID_START,
274 PVMF_CPM_INTERNAL_CMDQ_SIZE);
275
276 /*
277 * Create the "current command" queue. It will only contain one
278 * command at a time, so use a reserve of 1
279 */
280 iCurrentCommand.Construct(0, 1);
281 /*
282 * Create the "cancel command" queue. It will only contain one
283 * command at a time, so use a reserve of 1.
284 */
285 iCancelCommand.Construct(0, 1);
286
287 );
288 if (err != OsclErrNone)
289 {
290 OSCL_LEAVE(err);
291 }
292 }
293
~PVMFCPMImpl()294 PVMFCPMImpl::~PVMFCPMImpl()
295 {
296 /*
297 * Cleanup commands
298 * The command queues are self-deleting, but we want to
299 * notify the observer of unprocessed commands.
300 */
301 while (!iCancelCommand.empty())
302 {
303 CommandComplete(iCancelCommand, iCancelCommand.front(), PVMFFailure);
304 }
305 while (!iCurrentCommand.empty())
306 {
307 CommandComplete(iCurrentCommand, iCurrentCommand.front(), PVMFFailure);
308 }
309 while (!iInputCommands.empty())
310 {
311 CommandComplete(iInputCommands, iInputCommands.front(), PVMFFailure);
312 }
313
314 //Disconnect from all plugins in case it wasn't done in Reset.
315 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
316 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
317 {
318 if (it->iConnected)
319 it->iPlugInInterface->Disconnect(it->iPlugInSessionID);
320 it->iConnected = false;
321 }
322
323 /* Clear all vectors */
324 iPlugInParamsVec.clear();
325 iActivePlugInParamsVec.clear();
326 iContentUsageContextVec.clear();
327 iListofActiveSessions.clear();
328 }
329
ThreadLogon()330 OSCL_EXPORT_REF void PVMFCPMImpl::ThreadLogon()
331 {
332 iLogger = PVLogger::GetLoggerObject("PVMFCPMImpl");
333
334 AddToScheduler();
335
336 //Create the plugin registry and leave in case there
337 // are no plugins. This is done here in order to allow the
338 // source node to avoid going through a series of unnecessary
339 // async commands.
340
341 /*
342 * Create plugin params for all registered plugins. This container class
343 * holds all the required info about the plugin, thereby obviating the need
344 * to query the registry all the time for info
345 */
346 iNumRegisteredPlugInInitPending = 0;
347 iNumRegisteredPlugInInitComplete = 0;
348 iNumQueryMetaDataExtensionInterfacePending = 0;
349 iNumQueryMetaDataExtensionInterfaceComplete = 0;
350
351 //create the plugin registry, instantiating all the current plugins
352 //from the factory registry.
353 //first remove any old registry.
354 if (iPluginRegistry)
355 {
356 DePopulateCPMPluginRegistry(iPluginRegistry);
357 /** Cleanup all registered plugins*/
358 iPluginRegistry = NULL;
359 /* Clear all vectors */
360 iPlugInParamsVec.clear();
361 iActivePlugInParamsVec.clear();
362 iContentUsageContextVec.clear();
363 iListofActiveSessions.clear();
364 /**/
365 }
366
367 iPluginRegistry = PopulateCPMPluginRegistry();
368
369 //check for empty registry & leave.
370 if (iPluginRegistry
371 && iPluginRegistry->GetNumPlugIns() == 0)
372 {
373 CPMPluginRegistryFactory::DestroyCPMPluginRegistry(iPluginRegistry);
374 iPluginRegistry = NULL;
375 OSCL_LEAVE(OsclErrGeneral);
376 }
377
378 }
379
ThreadLogoff()380 OSCL_EXPORT_REF void PVMFCPMImpl::ThreadLogoff()
381 {
382 //Note: registry cleanup logically belongs under Reset command, but
383 //some nodes currently hang onto their access interfaces after
384 //CPM is reset, which means the plugins need to survive until after
385 //the access interfaces are cleaned up.
386 //@TODO this should be moved to the CompleteCPMReset routine.
387 if (iPluginRegistry)
388 {
389 DePopulateCPMPluginRegistry(iPluginRegistry);
390 iPluginRegistry = NULL;
391 //clear the plugin params vec since all plugins are destroyed.
392 iPlugInParamsVec.clear();
393 }
394
395 Cancel();
396
397 if (IsAdded())
398 {
399 RemoveFromScheduler();
400 }
401 }
402
addRef()403 OSCL_EXPORT_REF void PVMFCPMImpl::addRef()
404 {
405 iExtensionRefCount++;
406 }
407
removeRef()408 OSCL_EXPORT_REF void PVMFCPMImpl::removeRef()
409 {
410 --iExtensionRefCount;
411 }
412
queryInterface(const PVUuid & uuid,PVInterface * & iface)413 OSCL_EXPORT_REF bool PVMFCPMImpl::queryInterface(const PVUuid& uuid,
414 PVInterface*& iface)
415 {
416 iface = NULL;
417 if (uuid == KPVMFMetadataExtensionUuid)
418 {
419 PVMFMetadataExtensionInterface* myInterface =
420 OSCL_STATIC_CAST(PVMFMetadataExtensionInterface*, this);
421 iface = OSCL_STATIC_CAST(PVInterface*, myInterface);
422 return true;
423 }
424 else if (uuid == PVMFCPMPluginLicenseInterfaceUuid)
425 {
426 PVMFCPMPluginLicenseInterface* myInterface =
427 OSCL_STATIC_CAST(PVMFCPMPluginLicenseInterface*, this);
428 iface = OSCL_STATIC_CAST(PVInterface*, myInterface);
429 return true;
430 }
431 else if (uuid == PVMI_CAPABILITY_AND_CONFIG_PVUUID)
432 {
433 PvmiCapabilityAndConfig* myInterface =
434 OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, this);
435 iface = OSCL_STATIC_CAST(PVInterface*, myInterface);
436 return true;
437 }
438 return false;
439 }
440
Init(const OsclAny * aContext)441 OSCL_EXPORT_REF PVMFCommandId PVMFCPMImpl::Init(const OsclAny* aContext)
442 {
443 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl:Init"));
444 PVMFCPMCommand cmd;
445 cmd.Construct(PVMF_CPM_INIT, aContext);
446 return QueueCommandL(cmd);
447 }
448
449 OSCL_EXPORT_REF PVMFCommandId
OpenSession(PVMFSessionId & aSessionId,const OsclAny * aContext)450 PVMFCPMImpl::OpenSession(PVMFSessionId& aSessionId,
451 const OsclAny* aContext)
452 {
453 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl:OpenSession"));
454 PVMFCPMCommand cmd;
455 cmd.Construct(PVMF_CPM_OPEN_SESSION,
456 &aSessionId,
457 aContext);
458 return QueueCommandL(cmd);
459 }
460
461 OSCL_EXPORT_REF PVMFCommandId
RegisterContent(PVMFSessionId aSessionId,OSCL_wString & aSourceURL,PVMFFormatType & aSourceFormat,OsclAny * aSourceData,const OsclAny * aContext)462 PVMFCPMImpl::RegisterContent(PVMFSessionId aSessionId,
463 OSCL_wString& aSourceURL,
464 PVMFFormatType& aSourceFormat,
465 OsclAny* aSourceData,
466 const OsclAny* aContext)
467 {
468 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl:RegisterContent"));
469 PVMFCPMCommand cmd;
470 cmd.Construct(aSessionId,
471 PVMF_CPM_REGISTER_CONTENT,
472 &aSourceURL,
473 &aSourceFormat,
474 aSourceData,
475 NULL,
476 aContext);
477 return QueueCommandL(cmd);
478 }
479
480 OSCL_EXPORT_REF PVMFStatus
GetContentAccessFactory(PVMFSessionId aSessionId,PVMFCPMPluginAccessInterfaceFactory * & aContentAccessFactory)481 PVMFCPMImpl::GetContentAccessFactory(PVMFSessionId aSessionId,
482 PVMFCPMPluginAccessInterfaceFactory*& aContentAccessFactory)
483 {
484 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::GetContentAccessFactory"));
485
486 aContentAccessFactory = NULL;
487 CPMSessionInfo* sInfo = LookUpSessionInfo(aSessionId);
488 if (sInfo != NULL)
489 {
490 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
491 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
492 {
493 if (it->iPlugInID == sInfo->iAccessPlugInID)
494 {
495 it->iPlugInAccessInterfaceFactory->addRef();
496 aContentAccessFactory = it->iPlugInAccessInterfaceFactory;
497 return PVMFSuccess;
498 }
499 }
500 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::GetContentAccessFactory - No Access Plugin"));
501 }
502 else
503 {
504 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::GetContentAccessFactory - Invalid Session ID"));
505 }
506 return PVMFFailure;
507 }
508
509 OSCL_EXPORT_REF PVMFCommandId
ApproveUsage(PVMFSessionId aSessionId,PvmiKvp & aRequestedUsage,PvmiKvp & aApprovedUsage,PvmiKvp & aAuthorizationData,PVMFCPMUsageID & aUsageID,const OsclAny * aContext)510 PVMFCPMImpl::ApproveUsage(PVMFSessionId aSessionId,
511 PvmiKvp& aRequestedUsage,
512 PvmiKvp& aApprovedUsage,
513 PvmiKvp& aAuthorizationData,
514 PVMFCPMUsageID& aUsageID,
515 const OsclAny* aContext)
516 {
517 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::ApproveUsage"));
518 PVMFCPMCommand cmd;
519 cmd.Construct(aSessionId,
520 PVMF_CPM_APPROVE_USAGE,
521 &aRequestedUsage,
522 &aApprovedUsage,
523 &aAuthorizationData,
524 &aUsageID,
525 aContext);
526 return QueueCommandL(cmd);
527 }
528
GetCPMContentType(PVMFSessionId aSessionId)529 PVMFCPMContentType PVMFCPMImpl::GetCPMContentType(PVMFSessionId aSessionId)
530 {
531 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::GetCPMContentType"));
532 CPMSessionInfo* sInfo = LookUpSessionInfo(aSessionId);
533 if (sInfo != NULL)
534 {
535 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
536 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
537 {
538 if (it->iPlugInID == sInfo->iAccessPlugInID)
539 {
540 return (it->iPlugInInterface->GetCPMContentType());
541 }
542 }
543 }
544 return PVMF_CPM_CONTENT_FORMAT_UNKNOWN;
545 }
546
GetCPMContentFilename(PVMFSessionId aSessionId,OSCL_wString & aFileName)547 OSCL_EXPORT_REF PVMFStatus PVMFCPMImpl::GetCPMContentFilename(PVMFSessionId aSessionId, OSCL_wString& aFileName)
548 {
549 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::GetCPMContentFilename"));
550 CPMSessionInfo* sInfo = LookUpSessionInfo(aSessionId);
551 if (sInfo != NULL)
552 {
553 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
554 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
555 {
556 if (it->iPlugInID == sInfo->iAccessPlugInID)
557 {
558 return (it->iPlugInInterface->GetCPMContentFilename(aFileName));
559 }
560 }
561 }
562 return PVMF_CPM_CONTENT_FORMAT_UNKNOWN;
563 }
564
565
566 OSCL_EXPORT_REF PVMFCommandId
UsageComplete(PVMFSessionId aSessionId,PVMFCPMUsageID & aUsageID,OsclAny * aContext)567 PVMFCPMImpl::UsageComplete(PVMFSessionId aSessionId,
568 PVMFCPMUsageID& aUsageID,
569 OsclAny* aContext)
570 {
571 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::UsageComplete"));
572 PVMFCPMCommand cmd;
573 cmd.Construct(aSessionId,
574 PVMF_CPM_USAGE_COMPLETE,
575 NULL,
576 NULL,
577 &aUsageID,
578 NULL,
579 aContext);
580 return QueueCommandL(cmd);
581 }
582
583 OSCL_EXPORT_REF PVMFCommandId
CloseSession(PVMFSessionId & aSessionId,const OsclAny * aContext)584 PVMFCPMImpl::CloseSession(PVMFSessionId& aSessionId,
585 const OsclAny* aContext)
586 {
587 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::CloseSession"));
588 PVMFCPMCommand cmd;
589 cmd.Construct(PVMF_CPM_CLOSE_SESSION,
590 &aSessionId,
591 aContext);
592 return QueueCommandL(cmd);
593 }
594
Reset(const OsclAny * aContext)595 OSCL_EXPORT_REF PVMFCommandId PVMFCPMImpl::Reset(const OsclAny* aContext)
596 {
597 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::Reset"));
598 PVMFCPMCommand cmd;
599 cmd.Construct(PVMF_CPM_RESET, aContext);
600 return QueueCommandL(cmd);
601 }
602
603 OSCL_EXPORT_REF PVMFCommandId
GetNodeMetadataKeys(PVMFSessionId aSessionId,PVMFMetadataList & aKeyList,uint32 aStartingKeyIndex,int32 aMaxKeyEntries,char * aQueryKeyString,const OsclAny * aContextData)604 PVMFCPMImpl::GetNodeMetadataKeys(PVMFSessionId aSessionId,
605 PVMFMetadataList& aKeyList,
606 uint32 aStartingKeyIndex,
607 int32 aMaxKeyEntries,
608 char* aQueryKeyString,
609 const OsclAny* aContextData)
610 {
611 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::GetNodeMetadataKeys"));
612 PVMFCPMCommand cmd;
613 cmd.Construct(aSessionId,
614 PVMF_CPM_GET_METADATA_KEYS,
615 aKeyList,
616 aStartingKeyIndex,
617 aMaxKeyEntries,
618 aQueryKeyString,
619 aContextData);
620 return QueueCommandL(cmd);
621 }
622
623 OSCL_EXPORT_REF PVMFCommandId
GetNodeMetadataValues(PVMFSessionId aSessionId,PVMFMetadataList & aKeyList,Oscl_Vector<PvmiKvp,OsclMemAllocator> & aValueList,uint32 aStartingValueIndex,int32 aMaxValueEntries,const OsclAny * aContextData)624 PVMFCPMImpl::GetNodeMetadataValues(PVMFSessionId aSessionId,
625 PVMFMetadataList& aKeyList,
626 Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList,
627 uint32 aStartingValueIndex,
628 int32 aMaxValueEntries,
629 const OsclAny* aContextData)
630 {
631 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::GetNodeMetadataValues"));
632 PVMFCPMCommand cmd;
633 cmd.Construct(aSessionId,
634 PVMF_CPM_GET_METADATA_VALUES,
635 aKeyList,
636 aValueList,
637 aStartingValueIndex,
638 aMaxValueEntries,
639 aContextData);
640 return QueueCommandL(cmd);
641 }
642
643 OSCL_EXPORT_REF PVMFStatus
ReleaseNodeMetadataKeys(PVMFMetadataList & aKeyList,uint32 aStartingKeyIndex,uint32 aEndKeyIndex)644 PVMFCPMImpl::ReleaseNodeMetadataKeys(PVMFMetadataList& aKeyList,
645 uint32 aStartingKeyIndex,
646 uint32 aEndKeyIndex)
647 {
648 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::ReleaseNodeMetadataKeys called"));
649 if (((int32)aStartingKeyIndex < 0) ||
650 (aStartingKeyIndex > aEndKeyIndex) ||
651 (aKeyList.size() == 0))
652 {
653 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::ReleaseNodeMetadataKeys() Invalid start/end index"));
654 return PVMFErrArgument;
655 }
656 if (aEndKeyIndex >= aKeyList.size())
657 {
658 aEndKeyIndex = aKeyList.size() - 1;
659 }
660
661 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
662 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
663 {
664 uint32 plugInStartIndex = it->iMetaDataKeyStartIndex;
665 uint32 plugInEndIndex = it->iMetaDataKeyEndIndex;
666
667 uint32 releaseStartIndex = 0;
668 uint32 releaseEndIndex = 0;
669
670 if ((aStartingKeyIndex >= plugInStartIndex) &&
671 (aStartingKeyIndex <= plugInEndIndex))
672 {
673 releaseStartIndex = aStartingKeyIndex;
674 if (aEndKeyIndex > plugInEndIndex)
675 {
676 releaseEndIndex = plugInEndIndex;
677 }
678 else
679 {
680 releaseEndIndex = aEndKeyIndex;
681 }
682
683 if (NULL != it->iPlugInMetaDataExtensionInterface)
684 {
685 it->iPlugInMetaDataExtensionInterface->ReleaseNodeMetadataKeys(aKeyList,
686 releaseStartIndex,
687 releaseEndIndex);
688 }
689 }
690 aStartingKeyIndex = releaseEndIndex + 1;
691 }
692 return PVMFSuccess;
693 }
694
695 OSCL_EXPORT_REF PVMFStatus
ReleaseNodeMetadataValues(Oscl_Vector<PvmiKvp,OsclMemAllocator> & aValueList,uint32 aStartingValueIndex,uint32 aEndValueIndex)696 PVMFCPMImpl::ReleaseNodeMetadataValues(Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList,
697 uint32 aStartingValueIndex,
698 uint32 aEndValueIndex)
699 {
700 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::ReleaseNodeMetadataValues called"));
701
702 if (((int32)aStartingValueIndex < 0) ||
703 (aStartingValueIndex > aEndValueIndex) ||
704 (aValueList.size() == 0))
705 {
706 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::ReleaseNodeMetadataValues() Invalid start/end index"));
707 return PVMFErrArgument;
708 }
709
710 if (aEndValueIndex >= aValueList.size())
711 {
712 aEndValueIndex = aValueList.size() - 1;
713 }
714
715 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
716 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
717 {
718 uint32 plugInStartIndex = it->iMetaDataValueStartIndex;
719 uint32 plugInEndIndex = it->iMetaDataValueEndIndex;
720
721 uint32 releaseStartIndex = 0;
722 uint32 releaseEndIndex = 0;
723
724 if ((aStartingValueIndex >= plugInStartIndex) &&
725 (aStartingValueIndex <= plugInEndIndex))
726 {
727 releaseStartIndex = aStartingValueIndex;
728 if (aEndValueIndex > plugInEndIndex)
729 {
730 releaseEndIndex = plugInEndIndex;
731 }
732 else
733 {
734 releaseEndIndex = aEndValueIndex;
735 }
736 if (NULL != it->iPlugInMetaDataExtensionInterface)
737 {
738 it->iPlugInMetaDataExtensionInterface->ReleaseNodeMetadataValues(aValueList,
739 releaseStartIndex,
740 releaseEndIndex);
741 }
742 }
743 aStartingValueIndex = releaseEndIndex + 1;
744 }
745 return PVMFSuccess;
746 }
747
748 OSCL_EXPORT_REF PVMFCommandId
QueryInterface(PVMFSessionId aSessionId,const PVUuid & aUuid,PVInterface * & aInterfacePtr,const OsclAny * aContext)749 PVMFCPMImpl::QueryInterface(PVMFSessionId aSessionId,
750 const PVUuid& aUuid,
751 PVInterface*& aInterfacePtr,
752 const OsclAny* aContext)
753 {
754 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::GetNodeMetadataValues"));
755 PVMFCPMCommand cmd;
756 cmd.PVMFCPMCommandBase::Construct(aSessionId,
757 PVMF_CPM_QUERY_INTERFACE,
758 aUuid,
759 aInterfacePtr,
760 aContext);
761 return QueueCommandL(cmd);
762 }
763
764
765 /**
766 * This routine is called by various command APIs to queue an
767 * asynchronous command for processing by the command handler AO.
768 * This function may leave if the command can't be queued due to
769 * memory allocation failure.
770 */
QueueCommandL(PVMFCPMCommand & aCmd)771 PVMFCommandId PVMFCPMImpl::QueueCommandL(PVMFCPMCommand& aCmd)
772 {
773 PVMFCommandId id;
774 id = iInputCommands.AddL(aCmd);
775 /* wakeup the AO */
776 RunIfNotReady();
777 return id;
778 }
779
780 /**
781 * The various command handlers call this when a command is complete.
782 */
CommandComplete(PVMFCPMCommandCmdQ & aCmdQ,PVMFCPMCommand & aCmd,PVMFStatus aStatus,OsclAny * aEventData,PVUuid * aEventUUID,int32 * aEventCode)783 void PVMFCPMImpl::CommandComplete(PVMFCPMCommandCmdQ& aCmdQ,
784 PVMFCPMCommand& aCmd,
785 PVMFStatus aStatus,
786 OsclAny* aEventData,
787 PVUuid* aEventUUID,
788 int32* aEventCode)
789 {
790 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::CommandComplete Id %d Cmd %d Status %d Context %d Data %d"
791 , aCmd.iId, aCmd.iCmd, aStatus, aCmd.iContext, aEventData));
792
793 PVInterface* extif = NULL;
794 PVMFBasicErrorInfoMessage* errormsg = NULL;
795 if (aEventUUID && aEventCode)
796 {
797 errormsg = OSCL_NEW(PVMFBasicErrorInfoMessage, (*aEventCode, *aEventUUID, NULL));
798 extif = OSCL_STATIC_CAST(PVInterface*, errormsg);
799 }
800
801 /* create response */
802 PVMFCmdResp resp(aCmd.iId, aCmd.iContext, aStatus, extif, aEventData);
803
804 /* Erase the command from the queue */
805 aCmdQ.Erase(&aCmd);
806
807 /* Report completion to the session observer */
808 iObserver.CPMCommandCompleted(resp);
809
810 if (errormsg)
811 {
812 errormsg->removeRef();
813 }
814
815 /* Reschedule AO if input command queue is not empty */
816 if (!iInputCommands.empty()
817 && IsAdded())
818 {
819 RunIfNotReady();
820 }
821 }
822
CommandComplete(PVMFCPMCommandCmdQ & aCmdQ,PVMFCPMCommand & aCmd,PVMFStatus aStatus,PVInterface * aErrorExtIntf)823 void PVMFCPMImpl::CommandComplete(PVMFCPMCommandCmdQ& aCmdQ,
824 PVMFCPMCommand& aCmd,
825 PVMFStatus aStatus,
826 PVInterface* aErrorExtIntf)
827 {
828 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::CommandComplete Id %d Cmd %d Status %d"
829 , aCmd.iId, aCmd.iCmd, aStatus));
830
831 /* create response */
832 PVMFCmdResp resp(aCmd.iId, aCmd.iContext, aStatus, aErrorExtIntf, NULL);
833
834 /* Erase the command from the queue */
835 aCmdQ.Erase(&aCmd);
836
837 /* Report completion to the session observer */
838 iObserver.CPMCommandCompleted(resp);
839
840 /* Reschedule AO if input command queue is not empty */
841 if (!iInputCommands.empty())
842 {
843 RunIfNotReady();
844 }
845 }
846
847 void
MoveCmdToCurrentQueue(PVMFCPMCommand & aCmd)848 PVMFCPMImpl::MoveCmdToCurrentQueue(PVMFCPMCommand& aCmd)
849 {
850 int32 err = OsclErrNone;
851 OSCL_TRY(err, iCurrentCommand.StoreL(aCmd););
852 if (err != OsclErrNone)
853 {
854 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::MoveCmdToCurrentQueue - No Memory"));
855 CommandComplete(iInputCommands, aCmd, PVMFErrNoMemory);
856 return;
857 }
858 iInputCommands.Erase(&aCmd);
859 return;
860 }
861
862 void
MoveCmdToCancelQueue(PVMFCPMCommand & aCmd)863 PVMFCPMImpl::MoveCmdToCancelQueue(PVMFCPMCommand& aCmd)
864 {
865 /*
866 * note: the StoreL cannot fail since the queue is never more than 1 deep
867 * and we reserved space.
868 */
869 iCancelCommand.StoreL(aCmd);
870 iInputCommands.Erase(&aCmd);
871 }
872
RequestNewInternalCmd()873 PVMFCPMCommandContext* PVMFCPMImpl::RequestNewInternalCmd()
874 {
875 int32 i = 0;
876 /* Search for the next free node command in the pool */
877 while (i < PVMF_CPM_INTERNAL_CMDQ_SIZE)
878 {
879 if (iInternalCmdPool[i].oFree)
880 {
881 iInternalCmdPool[i].oFree = false;
882 return &(iInternalCmdPool[i]);
883 }
884 ++i;
885 }
886 /* Free one not found so return NULL */
887 return NULL;
888 }
889
890 /**
891 * Called by the command handler AO to process a command from
892 * the input queue.
893 * Return true if a command was processed, false if the command
894 * processor is busy and can't process another command now.
895 */
ProcessCommand(PVMFCPMCommand & aCmd)896 bool PVMFCPMImpl::ProcessCommand(PVMFCPMCommand& aCmd)
897 {
898 /*
899 * normally this node will not start processing one command
900 * until the prior one is finished. However, a hi priority
901 * command such as Cancel must be able to interrupt a command
902 * in progress.
903 */
904 if (!iCurrentCommand.empty() && !aCmd.hipri() && aCmd.iCmd != PVMF_CPM_CANCEL_GET_LICENSE)
905 return false;
906
907 switch (aCmd.iCmd)
908 {
909 case PVMF_CPM_INIT:
910 DoInit(aCmd);
911 break;
912
913 case PVMF_CPM_OPEN_SESSION:
914 DoOpenSession(aCmd);
915 break;
916
917 case PVMF_CPM_REGISTER_CONTENT:
918 DoRegisterContent(aCmd);
919 break;
920
921 case PVMF_CPM_APPROVE_USAGE:
922 DoApproveUsage(aCmd);
923 break;
924
925 case PVMF_CPM_USAGE_COMPLETE:
926 DoUsageComplete(aCmd);
927 break;
928
929 case PVMF_CPM_CLOSE_SESSION:
930 DoCloseSession(aCmd);
931 break;
932
933 case PVMF_CPM_RESET:
934 DoReset(aCmd);
935 break;
936
937 case PVMF_CPM_GET_METADATA_KEYS:
938 {
939 PVMFStatus status = DoGetMetadataKeys(aCmd);
940 if (status != PVMFPending)
941 {
942 CommandComplete(iInputCommands, aCmd, status);
943 }
944 else
945 {
946 MoveCmdToCurrentQueue(aCmd);
947 }
948 }
949 break;
950
951 case PVMF_CPM_GET_METADATA_VALUES:
952 DoGetMetadataValues(aCmd);
953 break;
954
955 case PVMF_CPM_QUERY_INTERFACE:
956 DoQueryInterface(aCmd);
957 break;
958
959 case PVMF_CPM_GET_LICENSE_W:
960 {
961 PVMFStatus status = DoGetLicense(aCmd, true);
962 if (status == PVMFPending)
963 {
964 MoveCmdToCurrentQueue(aCmd);
965 }
966 else
967 {
968 CommandComplete(iInputCommands, aCmd, status);
969 }
970 }
971 break;
972
973 case PVMF_CPM_GET_LICENSE:
974 {
975 PVMFStatus status = DoGetLicense(aCmd);
976 if (status == PVMFPending)
977 {
978 MoveCmdToCurrentQueue(aCmd);
979 }
980 else
981 {
982 CommandComplete(iInputCommands, aCmd, status);
983 }
984 }
985 break;
986
987 case PVMF_CPM_CANCEL_GET_LICENSE:
988 DoCancelGetLicense(aCmd);
989 break;
990
991 default:
992 {
993 /* unknown command type */
994 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::ProcessCommand - Unknown Command"));
995 CommandComplete(iInputCommands, aCmd, PVMFErrNotSupported);
996 }
997 break;
998 }
999
1000 return true;
1001 }
1002
DoInit(PVMFCPMCommand & aCmd)1003 void PVMFCPMImpl::DoInit(PVMFCPMCommand& aCmd)
1004 {
1005 if (!iPluginRegistry)
1006 {
1007 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoInit - No Plugin Registry"));
1008 CommandComplete(iInputCommands, aCmd, PVMFFailure);
1009 }
1010
1011 for (uint32 i = 0; i < iPluginRegistry->GetNumPlugIns(); i++)
1012 {
1013 CPMPlugInParams plugInParams;
1014
1015 iPluginRegistry->GetPluginMimeType(i, plugInParams.iPlugInMimeType);
1016 plugInParams.iPlugInID = i;
1017
1018 CPMPluginContainer* container =
1019 iPluginRegistry->lookupPlugin(plugInParams.iPlugInMimeType);
1020
1021 if (container)
1022 {
1023 PVMFCPMPluginInterface& iface = container->PlugIn();
1024 OsclAny* _pPlugInData = container->PlugInUserAuthenticationData();
1025 plugInParams.iPlugInInterface = &iface;
1026 plugInParams.iPlugInData = _pPlugInData;
1027 iPlugInParamsVec.push_back(plugInParams);
1028 }
1029 }
1030 /* Connect with all plugins */
1031 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1032 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
1033 {
1034 it->iPlugInSessionID = it->iPlugInInterface->Connect(*this);
1035 it->iConnected = true;
1036 }
1037 PVMFStatus status = InitRegisteredPlugIns();
1038 if (status == PVMFSuccess)
1039 {
1040 MoveCmdToCurrentQueue(aCmd);
1041 }
1042 else
1043 {
1044 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoInit - InitRegisteredPlugIns Failed"));
1045 CommandComplete(iInputCommands, aCmd, status);
1046 }
1047 }
1048
InitRegisteredPlugIns()1049 PVMFStatus PVMFCPMImpl::InitRegisteredPlugIns()
1050 {
1051 if (iPlugInParamsVec.size() > 0)
1052 {
1053 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1054 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
1055 {
1056 /* Get Authentication interface */
1057 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1058 if (internalCmd != NULL)
1059 {
1060 internalCmd->cmd = PVMF_CPM_INTERNAL_INIT_CMD;
1061 internalCmd->parentCmd = PVMF_CPM_INIT;
1062 internalCmd->plugInID = it->iPlugInID;
1063 OsclAny *cmdContextData =
1064 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1065
1066 it->iPlugInInterface->Init(it->iPlugInSessionID,
1067 cmdContextData);
1068 iNumRegisteredPlugInInitPending++;
1069 }
1070 else
1071 {
1072 return PVMFErrNoMemory;
1073 }
1074 }
1075 return PVMFSuccess;
1076 }
1077 /* No registered plugins */
1078 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::InitRegisteredPlugIns - Registered plugin list empty"));
1079 return PVMFFailure;
1080 }
1081
CompleteInitPlugIns()1082 void PVMFCPMImpl::CompleteInitPlugIns()
1083 {
1084 if (iNumRegisteredPlugInInitPending ==
1085 iNumRegisteredPlugInInitComplete)
1086 {
1087 PVMFStatus status = QueryForPlugInMetaDataExtensionInterface();
1088
1089 if (status != PVMFSuccess)
1090 {
1091 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteInitPlugIns - QueryForPlugInAuthenticationInterface Failed"));
1092 CommandComplete(iCurrentCommand,
1093 iCurrentCommand.front(),
1094 status);
1095 }
1096 }
1097 }
1098
QueryForPlugInMetaDataExtensionInterface()1099 PVMFStatus PVMFCPMImpl::QueryForPlugInMetaDataExtensionInterface()
1100 {
1101 if (iPlugInParamsVec.size() > 0)
1102 {
1103 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1104 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
1105 {
1106 /* Get MetaDataExtension interface */
1107 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1108 if (internalCmd != NULL)
1109 {
1110 internalCmd->cmd =
1111 PVMF_CPM_INTERNAL_QUERY_METADATA_EXTENSION_INTERFACE_CMD;
1112 internalCmd->parentCmd = PVMF_CPM_INIT;
1113 internalCmd->plugInID = it->iPlugInID;
1114 OsclAny *cmdContextData =
1115 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1116 it->iPlugInMetaDataExtensionInterfacePVI = NULL;
1117 it->iPlugInInterface->QueryInterface(it->iPlugInSessionID,
1118 KPVMFMetadataExtensionUuid,
1119 it->iPlugInMetaDataExtensionInterfacePVI,
1120 cmdContextData);
1121 iNumQueryMetaDataExtensionInterfacePending++;
1122 }
1123 else
1124 {
1125 return PVMFErrNoMemory;
1126 }
1127 }
1128 return PVMFSuccess;
1129 }
1130 /* No registered plugins */
1131 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::QueryForPlugInMetaDataExtensionInterface - Registered plugin list empty"));
1132 return PVMFFailure;
1133 }
1134
1135
CompleteMetaDataExtInterfaceQueryFromPlugIns()1136 void PVMFCPMImpl::CompleteMetaDataExtInterfaceQueryFromPlugIns()
1137 {
1138 if (iNumQueryMetaDataExtensionInterfacePending ==
1139 iNumQueryMetaDataExtensionInterfaceComplete)
1140 {
1141 PVMFStatus status = QueryForPlugInCapConfigInterface();
1142
1143 if (status != PVMFSuccess)
1144 {
1145 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteMetaDataExtInterfaceQueryFromPlugIns - QueryForPlugInCapConfigInterface Failed"));
1146 CommandComplete(iCurrentCommand,
1147 iCurrentCommand.front(),
1148 status);
1149 }
1150 }
1151 }
1152
QueryForPlugInCapConfigInterface()1153 PVMFStatus PVMFCPMImpl::QueryForPlugInCapConfigInterface()
1154 {
1155 if (iPlugInParamsVec.size() > 0)
1156 {
1157 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1158 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
1159 {
1160 /* Get MetaDataExtension interface */
1161 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1162 if (internalCmd != NULL)
1163 {
1164 internalCmd->cmd =
1165 PVMF_CPM_INTERNAL_QUERY_CAP_CONFIG_INTERFACE_CMD;
1166 internalCmd->parentCmd = PVMF_CPM_INIT;
1167 internalCmd->plugInID = it->iPlugInID;
1168 OsclAny *cmdContextData =
1169 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1170 it->iPlugInCapConfigExtensionInterfacePVI = NULL;
1171 it->iPlugInInterface->QueryInterface(it->iPlugInSessionID,
1172 PVMI_CAPABILITY_AND_CONFIG_PVUUID,
1173 it->iPlugInCapConfigExtensionInterfacePVI,
1174 cmdContextData);
1175 iNumQueryCapConfigExtensionInterfacePending++;
1176 }
1177 else
1178 {
1179 return PVMFErrNoMemory;
1180 }
1181 }
1182 return PVMFSuccess;
1183 }
1184 /* No registered plugins */
1185 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::QueryForPlugInCapConfigInterface - Registered plugin list empty"));
1186 return PVMFFailure;
1187 }
1188
1189
CompleteCapConfigExtInterfaceQueryFromPlugIns()1190 void PVMFCPMImpl::CompleteCapConfigExtInterfaceQueryFromPlugIns()
1191 {
1192 if (iNumQueryCapConfigExtensionInterfacePending ==
1193 iNumQueryCapConfigExtensionInterfaceComplete)
1194 {
1195 PVMFStatus status = QueryForPlugInAuthenticationInterface();
1196
1197 if (status != PVMFSuccess)
1198 {
1199 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteCapConfigExtInterfaceQueryFromPlugIns - QueryForPlugInAuthenticationInterface Failed"));
1200 CommandComplete(iCurrentCommand,
1201 iCurrentCommand.front(),
1202 status);
1203 }
1204 }
1205 }
1206
QueryForPlugInAuthenticationInterface()1207 PVMFStatus PVMFCPMImpl::QueryForPlugInAuthenticationInterface()
1208 {
1209 if (iPlugInParamsVec.size() > 0)
1210 {
1211 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1212 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
1213 {
1214 /* Get Authentication interface */
1215 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1216 if (internalCmd != NULL)
1217 {
1218 internalCmd->cmd =
1219 PVMF_CPM_INTERNAL_QUERY_AUTHENTICATION_INTERFACE_CMD;
1220 internalCmd->parentCmd = PVMF_CPM_INIT;
1221 internalCmd->plugInID = it->iPlugInID;
1222 OsclAny *cmdContextData =
1223 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1224 it->iPlugInAuthenticationInterfacePVI = NULL;
1225 it->iPlugInInterface->QueryInterface(it->iPlugInSessionID,
1226 PVMFCPMPluginAuthenticationInterfaceUuid,
1227 it->iPlugInAuthenticationInterfacePVI,
1228 cmdContextData);
1229 iNumQueryAuthenticationInterfacePending++;
1230 }
1231 else
1232 {
1233 return PVMFErrNoMemory;
1234 }
1235 }
1236 return PVMFSuccess;
1237 }
1238 /* No registered plugins */
1239 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::QueryForPlugInAuthenticationInterface - Registered plugin list empty"));
1240 return PVMFFailure;
1241 }
1242
CompleteCPMInit()1243 void PVMFCPMImpl::CompleteCPMInit()
1244 {
1245 if (iNumQueryAuthenticationInterfacePending ==
1246 iNumQueryAuthenticationInterfaceComplete)
1247 {
1248 CommandComplete(iCurrentCommand,
1249 iCurrentCommand.front(),
1250 PVMFSuccess);
1251 }
1252 }
1253
DoOpenSession(PVMFCPMCommand & aCmd)1254 void PVMFCPMImpl::DoOpenSession(PVMFCPMCommand& aCmd)
1255 {
1256 OsclAny* temp = NULL;
1257 aCmd.Parse(temp);
1258 PVMFSessionId* sessionIdPtr = OSCL_STATIC_CAST(PVMFSessionId*, temp);
1259
1260 /* Create a session info */
1261 CPMSessionInfo sessionInfo;
1262 sessionInfo.iSessionId = iListofActiveSessions.size();
1263 *sessionIdPtr = sessionInfo.iSessionId;
1264 iListofActiveSessions.push_back(sessionInfo);
1265 PVMFStatus status =
1266 AuthenticateWithAllRegisteredPlugIns(sessionInfo.iSessionId);
1267 if (status == PVMFSuccess)
1268 {
1269 MoveCmdToCurrentQueue(aCmd);
1270 }
1271 else
1272 {
1273 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoOpenSession - AuthenticateWithAllRegisteredPlugIns Failed"));
1274 CommandComplete(iInputCommands, aCmd, status);
1275 }
1276 }
1277
AuthenticateWithAllRegisteredPlugIns(PVMFSessionId aSessionId)1278 PVMFStatus PVMFCPMImpl::AuthenticateWithAllRegisteredPlugIns(PVMFSessionId aSessionId)
1279 {
1280 if (iPlugInParamsVec.size() > 0)
1281 {
1282 CPMSessionInfo* sessionInfo = LookUpSessionInfo(aSessionId);
1283
1284 if (sessionInfo != NULL)
1285 {
1286 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1287 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
1288 {
1289 /* Get Authentication interface */
1290 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1291 if (internalCmd != NULL)
1292 {
1293 internalCmd->cmd = PVMF_CPM_INTERNAL_AUTHENTICATE_CMD;
1294 internalCmd->parentCmd = PVMF_CPM_OPEN_SESSION;
1295 internalCmd->plugInID = it->iPlugInID;
1296 OsclAny *cmdContextData =
1297 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1298
1299 it->iPlugInAuthenticationInterface->AuthenticateUser(it->iPlugInSessionID,
1300 it->iPlugInData,
1301 cmdContextData);
1302 sessionInfo->iNumPlugInAunthenticateRequestsPending++;
1303 }
1304 else
1305 {
1306 return PVMFErrNoMemory;
1307 }
1308 }
1309 return PVMFSuccess;
1310 }
1311 else
1312 {
1313 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::AuthenticateWithAllRegisteredPlugIns - Invalid Session ID"));
1314 return PVMFErrArgument;
1315 }
1316 }
1317 /* No registered plugins */
1318 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::AuthenticateWithAllRegisteredPlugIns - Registered plugin list empty"));
1319 return PVMFFailure;
1320 }
1321
CompleteOpenSession(CPMSessionInfo * aSessionInfo)1322 void PVMFCPMImpl::CompleteOpenSession(CPMSessionInfo* aSessionInfo)
1323 {
1324 if (aSessionInfo == NULL)
1325 {
1326 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteOpenSession - Invalid Session ID"));
1327 CommandComplete(iCurrentCommand,
1328 iCurrentCommand.front(),
1329 PVMFFailure);
1330 }
1331 else
1332 {
1333 aSessionInfo->iNumPlugInAunthenticateRequestsComplete++;
1334
1335 if (aSessionInfo->iNumPlugInAunthenticateRequestsComplete ==
1336 aSessionInfo->iNumPlugInAunthenticateRequestsPending)
1337 {
1338 CommandComplete(iCurrentCommand,
1339 iCurrentCommand.front(),
1340 PVMFSuccess);
1341 }
1342 }
1343 return;
1344 }
1345
DoRegisterContent(PVMFCPMCommand & aCmd)1346 void PVMFCPMImpl::DoRegisterContent(PVMFCPMCommand& aCmd)
1347 {
1348 OsclAny* temp1 = NULL;
1349 OsclAny* temp2 = NULL;
1350 OsclAny* aSourceData;
1351 OsclAny* placeHolder;
1352
1353 aCmd.Parse(temp1,
1354 temp2,
1355 aSourceData,
1356 placeHolder);
1357
1358 OSCL_wString* sourceURL = OSCL_STATIC_CAST(OSCL_wString*, temp1);
1359 PVMFFormatType* sourceFormatType = OSCL_STATIC_CAST(PVMFFormatType*, temp2);
1360
1361 CPMSessionInfo* sInfo = LookUpSessionInfo(aCmd.iSession);
1362
1363 if (sInfo != NULL)
1364 {
1365 sInfo->iSourceURL = *sourceURL;
1366 sInfo->iSourceFormatType = *sourceFormatType;
1367 sInfo->iSourceData = aSourceData;
1368 PVMFStatus status = PopulateListOfActivePlugIns(sInfo);
1369 if (status == PVMFSuccess)
1370 {
1371 status = QueryForAuthorizationInterface(sInfo);
1372 if (status == PVMFSuccess)
1373 {
1374 MoveCmdToCurrentQueue(aCmd);
1375 }
1376 else
1377 {
1378 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoRegisterContent - QueryForAuthorizationInterface Failed"));
1379 CommandComplete(iInputCommands, aCmd, status);
1380 }
1381 }
1382 else
1383 {
1384 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoRegisterContent - PopulateListOfActivePlugIns Failed"));
1385 CommandComplete(iInputCommands, aCmd, status);
1386 }
1387 }
1388 else
1389 {
1390 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoRegisterContent - Invalid Session ID"));
1391 CommandComplete(iInputCommands, aCmd, PVMFErrArgument);
1392 }
1393 }
1394
PopulateListOfActivePlugIns(CPMSessionInfo * aInfo)1395 PVMFStatus PVMFCPMImpl::PopulateListOfActivePlugIns(CPMSessionInfo* aInfo)
1396 {
1397 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1398 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
1399 {
1400 PVMFStatus status =
1401 it->iPlugInInterface->SetSourceInitializationData(aInfo->iSourceURL,
1402 aInfo->iSourceFormatType,
1403 aInfo->iSourceData);
1404 if (status == PVMFSuccess)
1405 {
1406 /* Add this plug to the active list */
1407 iActivePlugInParamsVec.push_back(*it);
1408 }
1409 }
1410 if (iActivePlugInParamsVec.size() > 0)
1411 {
1412 return PVMFSuccess;
1413 }
1414 //no plugins care about this clip
1415 return PVMFErrNotSupported;
1416 }
1417
QueryForAuthorizationInterface(CPMSessionInfo * aInfo)1418 PVMFStatus PVMFCPMImpl::QueryForAuthorizationInterface(CPMSessionInfo* aInfo)
1419 {
1420 if (iActivePlugInParamsVec.size() > 0)
1421 {
1422 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1423 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
1424 {
1425 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1426 if (internalCmd != NULL)
1427 {
1428 internalCmd->cmd =
1429 PVMF_CPM_INTERNAL_QUERY_AUTHORIZATION_INTERFACE_CMD;
1430 internalCmd->parentCmd = PVMF_CPM_REGISTER_CONTENT;
1431 internalCmd->plugInID = it->iPlugInID;
1432 internalCmd->sessionid = aInfo->iSessionId;
1433 OsclAny *cmdContextData =
1434 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1435 it->iPlugInAuthorizationInterfacePVI = NULL;
1436 it->iPlugInInterface->QueryInterface(it->iPlugInSessionID,
1437 PVMFCPMPluginAuthorizationInterfaceUuid,
1438 it->iPlugInAuthorizationInterfacePVI,
1439 cmdContextData);
1440 aInfo->iNumPlugInAuthorizeInterfaceQueryRequestsPending++;
1441 }
1442 else
1443 {
1444 return PVMFErrNoMemory;
1445 }
1446 }
1447 return PVMFSuccess;
1448 }
1449 /* No active plugins */
1450 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::QueryForAuthorizationInterface - No Active Plugins"));
1451 return PVMFFailure;
1452 }
1453
QueryForAccessInterfaceFactory(CPMSessionInfo * aInfo)1454 PVMFStatus PVMFCPMImpl::QueryForAccessInterfaceFactory(CPMSessionInfo* aInfo)
1455 {
1456 if (iActivePlugInParamsVec.size() > 0)
1457 {
1458 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1459 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
1460 {
1461 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1462 if (internalCmd != NULL)
1463 {
1464 internalCmd->cmd =
1465 PVMF_CPM_INTERNAL_QUERY_ACCESS_INTERFACE_FACTORY_CMD;
1466 internalCmd->parentCmd = PVMF_CPM_REGISTER_CONTENT;
1467 internalCmd->plugInID = it->iPlugInID;
1468 internalCmd->sessionid = aInfo->iSessionId;
1469 OsclAny *cmdContextData =
1470 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1471 it->iPlugInAccessInterfaceFactoryPVI = NULL;
1472 it->iPlugInInterface->QueryInterface(it->iPlugInSessionID,
1473 PVMFCPMPluginAccessInterfaceFactoryUuid,
1474 it->iPlugInAccessInterfaceFactoryPVI,
1475 cmdContextData);
1476 aInfo->iNumPlugInAccessInterfaceFactoryQueryRequestsPending++;
1477 }
1478 else
1479 {
1480 return PVMFErrNoMemory;
1481 }
1482 }
1483 return PVMFSuccess;
1484 }
1485 /* No active plugins */
1486 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::QueryForAccessInterfaceFactory - No Active Plugins"));
1487 return PVMFFailure;
1488 }
1489
DetermineAccessPlugIn(CPMSessionInfo * aInfo)1490 PVMFStatus PVMFCPMImpl::DetermineAccessPlugIn(CPMSessionInfo* aInfo)
1491 {
1492 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1493 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
1494 {
1495 if (it->iPlugInAccessInterfaceFactory != NULL)
1496 {
1497 aInfo->iAccessPlugInID = it->iPlugInID;
1498 return PVMFSuccess;
1499 }
1500 }
1501 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DetermineAccessPlugIn Failed"));
1502 return PVMFFailure;
1503 }
1504
QueryForLicenseInterface(CPMSessionInfo * aInfo)1505 PVMFStatus PVMFCPMImpl::QueryForLicenseInterface(CPMSessionInfo* aInfo)
1506 {
1507 if (iActivePlugInParamsVec.size() > 0)
1508 {
1509 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1510 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
1511 {
1512 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1513 if (internalCmd != NULL)
1514 {
1515 internalCmd->cmd =
1516 PVMF_CPM_INTERNAL_QUERY_LICENSE_INTERFACE_CMD;
1517 internalCmd->parentCmd = PVMF_CPM_REGISTER_CONTENT;
1518 internalCmd->plugInID = it->iPlugInID;
1519 internalCmd->sessionid = aInfo->iSessionId;
1520 OsclAny *cmdContextData =
1521 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1522 it->iPlugInLicenseInterfacePVI = NULL;
1523 it->iPlugInInterface->QueryInterface(it->iPlugInSessionID,
1524 PVMFCPMPluginLicenseInterfaceUuid,
1525 it->iPlugInLicenseInterfacePVI,
1526 cmdContextData);
1527 aInfo->iNumPlugInLicenseAcquisitionInterfaceRequestsPending++;
1528 }
1529 else
1530 {
1531 return PVMFErrNoMemory;
1532 }
1533 }
1534 return PVMFSuccess;
1535 }
1536 /* No active plugins */
1537 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::QueryForLicenseInterface - No Active Plugins"));
1538 return PVMFFailure;
1539 }
1540
CompleteRegisterContentPhase1(CPMSessionInfo * aInfo)1541 void PVMFCPMImpl::CompleteRegisterContentPhase1(CPMSessionInfo* aInfo)
1542 {
1543 if (aInfo == NULL)
1544 {
1545 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteRegisterContentPhase1 - Invalid Session ID"));
1546 CommandComplete(iCurrentCommand,
1547 iCurrentCommand.front(),
1548 PVMFFailure);
1549 }
1550 else
1551 {
1552 aInfo->iNumPlugInAuthorizeInterfaceQueryRequestsComplete++;
1553
1554 if (aInfo->iNumPlugInAuthorizeInterfaceQueryRequestsComplete ==
1555 aInfo->iNumPlugInAuthorizeInterfaceQueryRequestsPending)
1556 {
1557 PVMFStatus status = QueryForAccessInterfaceFactory(aInfo);
1558 if (status != PVMFSuccess)
1559 {
1560 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteRegisterContentPhase1 - QueryForAccessInterfaceFactory Failed"));
1561 CommandComplete(iCurrentCommand,
1562 iCurrentCommand.front(),
1563 status);
1564 }
1565 }
1566 }
1567 return;
1568 }
1569
CompleteRegisterContentPhase2(CPMSessionInfo * aInfo)1570 void PVMFCPMImpl::CompleteRegisterContentPhase2(CPMSessionInfo* aInfo)
1571 {
1572 if (aInfo == NULL)
1573 {
1574 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteRegisterContentPhase2 - Invalid Session ID"));
1575 CommandComplete(iCurrentCommand,
1576 iCurrentCommand.front(),
1577 PVMFFailure);
1578 }
1579 else
1580 {
1581 aInfo->iNumPlugInAccessInterfaceFactoryQueryRequestsComplete++;
1582
1583 if (aInfo->iNumPlugInAccessInterfaceFactoryQueryRequestsComplete ==
1584 aInfo->iNumPlugInAccessInterfaceFactoryQueryRequestsPending)
1585 {
1586 PVMFStatus status = DetermineAccessPlugIn(aInfo);
1587 if (status != PVMFSuccess)
1588 {
1589 CommandComplete(iCurrentCommand,
1590 iCurrentCommand.front(),
1591 status);
1592 }
1593 else
1594 {
1595 status = QueryForLicenseInterface(aInfo);
1596 if (status != PVMFSuccess)
1597 {
1598 CommandComplete(iCurrentCommand,
1599 iCurrentCommand.front(),
1600 status);
1601 }
1602 }
1603 }
1604 }
1605 return;
1606 }
1607
CompleteRegisterContentPhase3(CPMSessionInfo * aInfo)1608 void PVMFCPMImpl::CompleteRegisterContentPhase3(CPMSessionInfo* aInfo)
1609 {
1610 if (aInfo == NULL)
1611 {
1612 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteRegisterContentPhase3 - Invalid Session ID"));
1613 CommandComplete(iCurrentCommand,
1614 iCurrentCommand.front(),
1615 PVMFFailure);
1616 }
1617 else
1618 {
1619 aInfo->iNumPlugInLicenseAcquisitionInterfaceRequestsComplete++;
1620
1621 if (aInfo->iNumPlugInLicenseAcquisitionInterfaceRequestsComplete ==
1622 aInfo->iNumPlugInLicenseAcquisitionInterfaceRequestsPending)
1623 {
1624 CommandComplete(iCurrentCommand,
1625 iCurrentCommand.front(),
1626 PVMFSuccess);
1627 }
1628 }
1629 return;
1630 }
1631
1632
DoApproveUsage(PVMFCPMCommand & aCmd)1633 void PVMFCPMImpl::DoApproveUsage(PVMFCPMCommand& aCmd)
1634 {
1635 OsclAny* temp1 = NULL;
1636 OsclAny* temp2 = NULL;
1637 OsclAny* temp3 = NULL;
1638 OsclAny* temp4 = NULL;
1639
1640 aCmd.Parse(temp1, temp2, temp3, temp4);
1641
1642 PVMFCPMUsageID* usageID = OSCL_STATIC_CAST(PVMFCPMUsageID*, temp4);
1643
1644 /* Create Usage context */
1645 *usageID = iContentUsageContextVec.size();
1646 CPMContentUsageContext usageContext;
1647 usageContext.iUsageID = *usageID;
1648 iContentUsageContextVec.push_back(usageContext);
1649
1650 PVMFStatus status = RequestApprovalFromActivePlugIns(aCmd);
1651 if (status == PVMFSuccess)
1652 {
1653 MoveCmdToCurrentQueue(aCmd);
1654 }
1655 else
1656 {
1657 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoApproveUsage - RequestApprovalFromActivePlugIns Failed"));
1658 CommandComplete(iInputCommands, aCmd, status);
1659 }
1660 }
1661
RequestApprovalFromActivePlugIns(PVMFCPMCommand & aCmd)1662 PVMFStatus PVMFCPMImpl::RequestApprovalFromActivePlugIns(PVMFCPMCommand& aCmd)
1663 {
1664 if (iActivePlugInParamsVec.size() > 0)
1665 {
1666 OsclAny* temp1 = NULL;
1667 OsclAny* temp2 = NULL;
1668 OsclAny* temp3 = NULL;
1669 OsclAny* temp4 = NULL;
1670
1671 aCmd.Parse(temp1, temp2, temp3, temp4);
1672
1673 PvmiKvp* requestedUsage = OSCL_STATIC_CAST(PvmiKvp*, temp1);
1674 PvmiKvp* approvedUsage = OSCL_STATIC_CAST(PvmiKvp*, temp2);
1675 PvmiKvp* authorizationData = OSCL_STATIC_CAST(PvmiKvp*, temp3);
1676 PVMFCPMUsageID* usageID = OSCL_STATIC_CAST(PVMFCPMUsageID*, temp4);
1677
1678 CPMSessionInfo* sInfo = NULL; // initialize to ensure that if LookUpSeesionInfo() fail, sInfo will be NULL
1679 sInfo = LookUpSessionInfo(aCmd.iSession);
1680 OSCL_ASSERT(sInfo);
1681 if (!sInfo)
1682 {
1683 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::RequestApprovalFromActivePlugIns - No Session Info"));
1684 return PVMFFailure;
1685 }
1686
1687 CPMContentUsageContext* usageContext = LookUpContentUsageContext(*usageID);
1688 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1689 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
1690 {
1691 if (it->iPlugInID == sInfo->iAccessPlugInID)
1692 {
1693 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1694 if (internalCmd != NULL)
1695 {
1696 internalCmd->cmd = PVMF_CPM_INTERNAL_AUTHORIZE_CMD;
1697 internalCmd->parentCmd = PVMF_CPM_APPROVE_USAGE;
1698 internalCmd->plugInID = it->iPlugInID;
1699 internalCmd->usageid = *usageID;
1700 OsclAny *cmdContextData =
1701 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1702
1703 it->iPlugInAuthorizationInterface->AuthorizeUsage(it->iPlugInSessionID,
1704 *requestedUsage,
1705 *approvedUsage,
1706 *authorizationData,
1707 it->iAuthorizationRequestTimeOut,
1708 cmdContextData);
1709 OSCL_ASSERT(usageContext);
1710 if (!usageContext)
1711 {
1712 return PVMFFailure;
1713 }
1714 usageContext->iNumAuthorizeRequestsPending++;
1715 }
1716 else
1717 {
1718 return PVMFErrNoMemory;
1719 }
1720 }
1721 }
1722 return PVMFSuccess;
1723 }
1724 /* No active plugins */
1725 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::RequestApprovalFromActivePlugIns - No Active Plugins"));
1726 return PVMFFailure;
1727 }
1728
CompleteApproveUsage(CPMContentUsageContext * aContext)1729 void PVMFCPMImpl::CompleteApproveUsage(CPMContentUsageContext* aContext)
1730 {
1731 if (aContext == NULL)
1732 {
1733 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteApproveUsage - Invalid Usage ID"));
1734 CommandComplete(iCurrentCommand,
1735 iCurrentCommand.front(),
1736 PVMFFailure);
1737 }
1738 else
1739 {
1740 aContext->iNumAuthorizeRequestsComplete++;
1741
1742 if (aContext->iNumAuthorizeRequestsComplete ==
1743 aContext->iNumAuthorizeRequestsPending)
1744 {
1745 if (CheckForMetaDataInterfaceAvailability())
1746 {
1747 PVMFStatus status = QueryForMetaDataKeys(iCurrentCommand.front());
1748 if (status != PVMFSuccess)
1749 {
1750 CommandComplete(iCurrentCommand,
1751 iCurrentCommand.front(),
1752 status);
1753 }
1754 }
1755 else
1756 {
1757 // No meta data
1758 CommandComplete(iCurrentCommand,
1759 iCurrentCommand.front(),
1760 PVMFSuccess);
1761 }
1762 }
1763 }
1764 return;
1765 }
1766
CheckForMetaDataInterfaceAvailability()1767 bool PVMFCPMImpl::CheckForMetaDataInterfaceAvailability()
1768 {
1769 uint32 num = 0;
1770 if (iActivePlugInParamsVec.size() > 0)
1771 {
1772 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1773 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
1774 {
1775 if (it->iPlugInMetaDataExtensionInterface != NULL)
1776 {
1777 num++;
1778 }
1779 }
1780 if (num > 0)
1781 {
1782 return true;
1783 }
1784 }
1785 return false;
1786 }
1787
QueryForMetaDataKeys(PVMFCPMCommand & aParentCmd)1788 PVMFStatus PVMFCPMImpl::QueryForMetaDataKeys(PVMFCPMCommand& aParentCmd)
1789 {
1790 if (iActivePlugInParamsVec.size() > 0)
1791 {
1792 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1793 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
1794 {
1795 if (it->iPlugInMetaDataExtensionInterface != NULL)
1796 {
1797 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1798 if (internalCmd != NULL)
1799 {
1800 internalCmd->cmd =
1801 PVMF_CPM_INTERNAL_GET_PLUGIN_META_DATA_KEYS_CMD;
1802 internalCmd->parentCmd = aParentCmd.iCmd;
1803 internalCmd->plugInID = it->iPlugInID;
1804 OsclAny *cmdContextData =
1805 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1806
1807 it->iNumMetaDataKeysAvailable = 0;
1808 it->iAvailableMetadataKeys.clear();
1809
1810 it->iNumMetaDataKeysAvailable =
1811 it->iPlugInMetaDataExtensionInterface->GetNumMetadataKeys();
1812 it->iPlugInMetaDataExtensionInterface->GetNodeMetadataKeys(it->iPlugInSessionID,
1813 it->iAvailableMetadataKeys,
1814 0,
1815 it->iNumMetaDataKeysAvailable,
1816 NULL,
1817 cmdContextData);
1818 }
1819 else
1820 {
1821 return PVMFErrNoMemory;
1822 }
1823 }
1824 else
1825 {
1826 it->iGetMetaDataKeysComplete = true;
1827 }
1828 }
1829 return PVMFSuccess;
1830 }
1831 /* No active plugins */
1832 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::QueryForMetaDataKeys - No Active Plugins"));
1833 return PVMFFailure;
1834 }
1835
CompleteGetMetaDataKeys(uint32 aPlugInID)1836 void PVMFCPMImpl::CompleteGetMetaDataKeys(uint32 aPlugInID)
1837 {
1838 CPMPlugInParams* pluginInParams = LookUpPlugInParamsFromActiveList(aPlugInID);
1839 if (pluginInParams == NULL)
1840 {
1841 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteGetMetaDataKeys - Invalid PlugIn ID"));
1842 CommandComplete(iCurrentCommand,
1843 iCurrentCommand.front(),
1844 PVMFFailure);
1845 }
1846 else
1847 {
1848 pluginInParams->iGetMetaDataKeysComplete = true;
1849 if (CheckForGetMetaDataKeysCompletion())
1850 {
1851 PVMFStatus status = PVMFSuccess;
1852 if (iGetMetaDataKeysInProgress == true)
1853 {
1854 status = CompleteDoGetMetadataKeys(iCurrentCommand.front());
1855 }
1856 CommandComplete(iCurrentCommand,
1857 iCurrentCommand.front(),
1858 status);
1859 iGetMetaDataKeysFromPlugInsDone = true;
1860 }
1861 }
1862 return;
1863 }
1864
CheckForGetMetaDataKeysCompletion()1865 bool PVMFCPMImpl::CheckForGetMetaDataKeysCompletion()
1866 {
1867 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1868 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
1869 {
1870 if (it->iPlugInMetaDataExtensionInterface != NULL)
1871 {
1872 if (it->iGetMetaDataKeysComplete == false)
1873 {
1874 return false;
1875 }
1876 }
1877 }
1878 return true;
1879 }
1880
1881
DoUsageComplete(PVMFCPMCommand & aCmd)1882 void PVMFCPMImpl::DoUsageComplete(PVMFCPMCommand& aCmd)
1883 {
1884 OsclAny* placeHolder1;
1885 OsclAny* placeHolder2;
1886 OsclAny* placeHolder3;
1887 OsclAny* temp = NULL;
1888
1889 aCmd.Parse(OSCL_STATIC_CAST(OsclAny*&, placeHolder1),
1890 OSCL_STATIC_CAST(OsclAny*&, placeHolder2),
1891 temp,
1892 OSCL_STATIC_CAST(OsclAny*&, placeHolder3));
1893
1894 PVMFCPMUsageID* usageID = OSCL_STATIC_CAST(PVMFCPMUsageID*, temp);
1895
1896 PVMFStatus status = SendUsageCompleteToRegisteredPlugIns(*usageID);
1897 if (status == PVMFSuccess)
1898 {
1899 MoveCmdToCurrentQueue(aCmd);
1900 }
1901 else
1902 {
1903 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoUsageComplete - SendUsageCompleteToRegisteredPlugIns Failed"));
1904 CommandComplete(iInputCommands, aCmd, status);
1905 }
1906 }
1907
SendUsageCompleteToRegisteredPlugIns(PVMFCPMUsageID aID)1908 PVMFStatus PVMFCPMImpl::SendUsageCompleteToRegisteredPlugIns(PVMFCPMUsageID aID)
1909 {
1910 if (iActivePlugInParamsVec.size() > 0)
1911 {
1912 CPMContentUsageContext* usageContext = LookUpContentUsageContext(aID);
1913 if (usageContext != NULL)
1914 {
1915 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
1916 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
1917 {
1918 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
1919 if (internalCmd != NULL)
1920 {
1921 internalCmd->cmd = PVMF_CPM_INTERNAL_USAGE_COMPLETE_CMD;
1922 internalCmd->parentCmd = PVMF_CPM_USAGE_COMPLETE;
1923 internalCmd->plugInID = it->iPlugInID;
1924 internalCmd->usageid = aID;
1925 OsclAny *cmdContextData =
1926 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
1927
1928 it->iPlugInAuthorizationInterface->UsageComplete(it->iPlugInSessionID,
1929 cmdContextData);
1930 usageContext->iNumUsageCompleteRequestsPending++;
1931 }
1932 else
1933 {
1934 return PVMFErrNoMemory;
1935 }
1936 }
1937 return PVMFSuccess;
1938 }
1939 else
1940 {
1941 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::SendUsageCompleteToRegisteredPlugIns - Invalid UsageContext"));
1942 return PVMFFailure;
1943 }
1944 }
1945 /* No active plugins */
1946 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::SendUsageCompleteToRegisteredPlugIns - No Active Plugins"));
1947 return PVMFFailure;
1948 }
1949
CompleteUsageComplete(CPMContentUsageContext * aContext)1950 void PVMFCPMImpl::CompleteUsageComplete(CPMContentUsageContext* aContext)
1951 {
1952 if (aContext == NULL)
1953 {
1954 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteUsageComplete - Invalid Usage ID"));
1955 CommandComplete(iCurrentCommand,
1956 iCurrentCommand.front(),
1957 PVMFFailure);
1958 }
1959 else
1960 {
1961 aContext->iNumUsageCompleteRequestsComplete++;
1962
1963 if (aContext->iNumUsageCompleteRequestsComplete ==
1964 aContext->iNumUsageCompleteRequestsPending)
1965 {
1966 CommandComplete(iCurrentCommand,
1967 iCurrentCommand.front(),
1968 PVMFSuccess);
1969 }
1970 }
1971 return;
1972 }
1973
DoCloseSession(PVMFCPMCommand & aCmd)1974 void PVMFCPMImpl::DoCloseSession(PVMFCPMCommand& aCmd)
1975 {
1976 OsclAny* temp = NULL;
1977 aCmd.Parse(temp);
1978 PVMFSessionId* sessionId = OSCL_STATIC_CAST(PVMFSessionId*, temp);
1979
1980 CPMSessionInfo* sessionInfo = NULL;
1981
1982 Oscl_Vector<CPMSessionInfo, OsclMemAllocator>::iterator it;
1983 for (it = iListofActiveSessions.begin(); it != iListofActiveSessions.end(); it++)
1984 {
1985 if (it->iSessionId == *sessionId)
1986 {
1987 sessionInfo = it;
1988 break;
1989 }
1990 }
1991 if (sessionInfo == NULL)
1992 {
1993 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoCloseSession - Invalid Session ID"));
1994 CommandComplete(iInputCommands, aCmd, PVMFErrArgument);
1995 return;
1996 }
1997 iListofActiveSessions.erase(it);
1998 CommandComplete(iInputCommands, aCmd, PVMFSuccess);
1999 return;
2000 }
2001
DoReset(PVMFCPMCommand & aCmd)2002 void PVMFCPMImpl::DoReset(PVMFCPMCommand& aCmd)
2003 {
2004 PVMFStatus status = ResetRegisteredPlugIns();
2005 if (status == PVMFSuccess)
2006 {
2007 MoveCmdToCurrentQueue(aCmd);
2008 }
2009 else
2010 {
2011 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoReset - ResetRegisteredPlugIns Failed"));
2012 CommandComplete(iInputCommands, aCmd, status);
2013 }
2014 iNumRegisteredPlugInInitPending = 0;
2015 iNumRegisteredPlugInInitComplete = 0;
2016 iNumQueryMetaDataExtensionInterfacePending = 0;
2017 iNumQueryMetaDataExtensionInterfaceComplete = 0;
2018
2019 iGetMetaDataKeysFromPlugInsDone = false;
2020 iGetMetaDataKeysInProgress = false;
2021
2022 }
2023
ResetRegisteredPlugIns()2024 PVMFStatus PVMFCPMImpl::ResetRegisteredPlugIns()
2025 {
2026 if (iPlugInParamsVec.size() > 0)
2027 {
2028 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2029 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
2030 {
2031 /* Get Authentication interface */
2032 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
2033 if (internalCmd != NULL)
2034 {
2035 internalCmd->cmd = PVMF_CPM_INTERNAL_RESET_CMD;
2036 internalCmd->parentCmd = PVMF_CPM_RESET;
2037 internalCmd->plugInID = it->iPlugInID;
2038 OsclAny *cmdContextData =
2039 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
2040
2041 it->iPlugInInterface->Reset(it->iPlugInSessionID,
2042 cmdContextData);
2043 iNumRegisteredPlugInResetPending++;
2044 }
2045 else
2046 {
2047 return PVMFErrNoMemory;
2048 }
2049 }
2050 return PVMFSuccess;
2051 }
2052 /* No registered plugins */
2053 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::ResetRegisteredPlugIns - Registered plugin list empty"));
2054 return PVMFFailure;
2055 }
2056
CompleteCPMReset()2057 void PVMFCPMImpl::CompleteCPMReset()
2058 {
2059 if (iNumRegisteredPlugInResetPending ==
2060 iNumRegisteredPlugInResetComplete)
2061 {
2062 /* Disonnect from all plugins */
2063 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2064 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
2065 {
2066 if (it->iConnected)
2067 it->iPlugInInterface->Disconnect(it->iPlugInSessionID);
2068 it->iConnected = false;
2069 }
2070 CommandComplete(iCurrentCommand,
2071 iCurrentCommand.front(),
2072 PVMFSuccess);
2073 }
2074 }
2075
DoQueryInterface(PVMFCPMCommand & aCmd)2076 void PVMFCPMImpl::DoQueryInterface(PVMFCPMCommand& aCmd)
2077 {
2078 PVUuid* uuid;
2079 PVInterface** ptr;
2080 aCmd.PVMFCPMCommandBase::Parse(uuid, ptr);
2081
2082 PVMFStatus status = PVMFErrNotSupported;
2083 PVInterface* iFace = NULL;
2084 if (queryInterface(*uuid, iFace))
2085 {
2086 status = PVMFSuccess;
2087 *ptr = OSCL_STATIC_CAST(PVInterface*, iFace);
2088 }
2089 CommandComplete(iInputCommands, aCmd, status);
2090 return;
2091 }
2092
Run()2093 void PVMFCPMImpl::Run()
2094 {
2095 /*
2096 * Process commands.
2097 */
2098 if (!iInputCommands.empty())
2099 {
2100 ProcessCommand(iInputCommands.front());
2101 }
2102 }
2103
CPMPluginCommandCompleted(const PVMFCmdResp & aResponse)2104 void PVMFCPMImpl::CPMPluginCommandCompleted(const PVMFCmdResp& aResponse)
2105 {
2106 PVMFCPMCommandContext *cmdContextData =
2107 OSCL_REINTERPRET_CAST(PVMFCPMCommandContext*, aResponse.GetContext());
2108
2109 cmdContextData->oFree = true;
2110
2111 if (cmdContextData->cmd == PVMF_CPM_INTERNAL_CANCEL_GET_LICENSE)
2112 {
2113 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::CompleteCancelGetLicense - status=%d", aResponse.GetCmdStatus()));
2114 CommandComplete(iCancelCommand,
2115 iCancelCommand.front(),
2116 aResponse.GetCmdStatus());
2117 return;
2118 }
2119 if (aResponse.GetCmdStatus() != PVMFSuccess)
2120 {
2121 if (((cmdContextData->cmd == PVMF_CPM_INTERNAL_QUERY_METADATA_EXTENSION_INTERFACE_CMD) ||
2122 (cmdContextData->cmd == PVMF_CPM_INTERNAL_QUERY_CAP_CONFIG_INTERFACE_CMD) ||
2123 (cmdContextData->cmd == PVMF_CPM_INTERNAL_QUERY_LICENSE_INTERFACE_CMD)) &&
2124 (aResponse.GetCmdStatus() == PVMFErrNotSupported))
2125 {
2126 /*
2127 * Do nothing - Not all plugins have to support:
2128 * metadata, license interface
2129 */
2130 }
2131 else
2132 {
2133 /*
2134 * This call is in response to a command issued by CPM to one
2135 * of its plugins. This also means that there is current
2136 * command in the iCurrentCommand queue blocking the command loop
2137 * waiting for the all plugin commands to complete. Report failure
2138 * on it in case the parent id of this command is same as that of
2139 * the current blocking command. In case more than one child node
2140 * report error on same parent command, then the first one to
2141 * report would report failure on the parent command, and subsequent
2142 * ones would just log errors and return.
2143 */
2144 if (iCurrentCommand.size() > 0)
2145 {
2146 if (cmdContextData->parentCmd == iCurrentCommand.front().iCmd)
2147 {
2148 /* pass up any extra error info, if any */
2149 CommandComplete(iCurrentCommand,
2150 iCurrentCommand.front(),
2151 aResponse.GetCmdStatus(),
2152 aResponse.GetEventExtensionInterface());
2153 return;
2154 }
2155 }
2156 }
2157 }
2158
2159 switch (cmdContextData->cmd)
2160 {
2161 case PVMF_CPM_INTERNAL_INIT_CMD:
2162 iNumRegisteredPlugInInitComplete++;
2163 CompleteInitPlugIns();
2164 break;
2165
2166 case PVMF_CPM_INTERNAL_QUERY_METADATA_EXTENSION_INTERFACE_CMD:
2167 {
2168 CPMPlugInParams* plugInParams =
2169 LookUpPlugInParams(cmdContextData->plugInID);
2170 if (plugInParams)
2171 {
2172 plugInParams->iPlugInMetaDataExtensionInterface =
2173 OSCL_STATIC_CAST(PVMFMetadataExtensionInterface*,
2174 plugInParams->iPlugInMetaDataExtensionInterfacePVI);
2175 plugInParams->iPlugInMetaDataExtensionInterfacePVI = NULL;
2176 }
2177 iNumQueryMetaDataExtensionInterfaceComplete++;
2178 CompleteMetaDataExtInterfaceQueryFromPlugIns();
2179 }
2180 break;
2181
2182 case PVMF_CPM_INTERNAL_QUERY_AUTHENTICATION_INTERFACE_CMD:
2183 {
2184 CPMPlugInParams* plugInParams =
2185 LookUpPlugInParams(cmdContextData->plugInID);
2186 if (plugInParams)
2187 {
2188 plugInParams->iPlugInAuthenticationInterface =
2189 OSCL_STATIC_CAST(PVMFCPMPluginAuthenticationInterface*,
2190 plugInParams->iPlugInAuthenticationInterfacePVI);
2191 plugInParams->iPlugInAuthenticationInterfacePVI = NULL;
2192 }
2193 iNumQueryAuthenticationInterfaceComplete++;
2194 CompleteCPMInit();
2195 }
2196 break;
2197
2198 case PVMF_CPM_INTERNAL_AUTHENTICATE_CMD:
2199 {
2200 CPMSessionInfo* sessionInfo =
2201 LookUpSessionInfo(cmdContextData->sessionid);
2202 CompleteOpenSession(sessionInfo);
2203 }
2204 break;
2205
2206 case PVMF_CPM_INTERNAL_QUERY_AUTHORIZATION_INTERFACE_CMD:
2207 {
2208 CPMPlugInParams* plugInParams =
2209 LookUpPlugInParamsFromActiveList(cmdContextData->plugInID);
2210 if (plugInParams)
2211 {
2212 plugInParams->iPlugInAuthorizationInterface =
2213 OSCL_STATIC_CAST(PVMFCPMPluginAuthorizationInterface*,
2214 plugInParams->iPlugInAuthorizationInterfacePVI);
2215 plugInParams->iPlugInAuthorizationInterfacePVI = NULL;
2216 }
2217 CPMSessionInfo* sessionInfo =
2218 LookUpSessionInfo(cmdContextData->sessionid);
2219 CompleteRegisterContentPhase1(sessionInfo);
2220 }
2221 break;
2222
2223 case PVMF_CPM_INTERNAL_QUERY_ACCESS_INTERFACE_FACTORY_CMD:
2224 {
2225 CPMPlugInParams* plugInParams =
2226 LookUpPlugInParamsFromActiveList(cmdContextData->plugInID);
2227 if (plugInParams)
2228 {
2229 plugInParams->iPlugInAccessInterfaceFactory =
2230 OSCL_STATIC_CAST(PVMFCPMPluginAccessInterfaceFactory*,
2231 plugInParams->iPlugInAccessInterfaceFactoryPVI);
2232 plugInParams->iPlugInAccessInterfaceFactoryPVI = NULL;
2233 }
2234 CPMSessionInfo* sessionInfo =
2235 LookUpSessionInfo(cmdContextData->sessionid);
2236 CompleteRegisterContentPhase2(sessionInfo);
2237 }
2238 break;
2239
2240 case PVMF_CPM_INTERNAL_QUERY_LICENSE_INTERFACE_CMD:
2241 {
2242 CPMPlugInParams* plugInParams =
2243 LookUpPlugInParamsFromActiveList(cmdContextData->plugInID);
2244 if (plugInParams)
2245 {
2246 plugInParams->iPlugInLicenseInterface =
2247 OSCL_STATIC_CAST(PVMFCPMPluginLicenseInterface*,
2248 plugInParams->iPlugInLicenseInterfacePVI);
2249 plugInParams->iPlugInLicenseInterfacePVI = NULL;
2250 }
2251 CPMSessionInfo* sessionInfo =
2252 LookUpSessionInfo(cmdContextData->sessionid);
2253 CompleteRegisterContentPhase3(sessionInfo);
2254 }
2255 break;
2256
2257 case PVMF_CPM_INTERNAL_AUTHORIZE_CMD:
2258 {
2259 CPMContentUsageContext* usageContext =
2260 LookUpContentUsageContext(cmdContextData->usageid);
2261 CompleteApproveUsage(usageContext);
2262 CPMPlugInParams* plugInParams =
2263 LookUpPlugInParams(cmdContextData->plugInID);
2264 if (plugInParams)
2265 plugInParams->iAuthorized = true;
2266 }
2267 break;
2268
2269 case PVMF_CPM_INTERNAL_USAGE_COMPLETE_CMD:
2270 {
2271 CPMContentUsageContext* usageContext =
2272 LookUpContentUsageContext(cmdContextData->usageid);
2273 CompleteUsageComplete(usageContext);
2274 CPMPlugInParams* plugInParams =
2275 LookUpPlugInParams(cmdContextData->plugInID);
2276 if (plugInParams)
2277 plugInParams->iAuthorized = false;
2278 }
2279 break;
2280
2281 case PVMF_CPM_INTERNAL_RESET_CMD:
2282 iNumRegisteredPlugInResetComplete++;
2283 CompleteCPMReset();
2284 break;
2285
2286 case PVMF_CPM_INTERNAL_GET_PLUGIN_META_DATA_KEYS_CMD:
2287 CompleteGetMetaDataKeys(cmdContextData->plugInID);
2288 break;
2289
2290 case PVMF_CPM_INTERNAL_GET_PLUGIN_META_DATA_VALUES_CMD:
2291 {
2292 CompleteGetMetaDataValues(cmdContextData);
2293 }
2294 break;
2295
2296 case PVMF_CPM_INTERNAL_GET_LICENSE_CMD:
2297 {
2298 CompleteGetLicense();
2299 }
2300 break;
2301
2302 case PVMF_CPM_INTERNAL_QUERY_CAP_CONFIG_INTERFACE_CMD:
2303 {
2304 CPMPlugInParams* plugInParams =
2305 LookUpPlugInParams(cmdContextData->plugInID);
2306 if (plugInParams)
2307 {
2308 plugInParams->iPlugInCapConfigExtensionInterface =
2309 OSCL_STATIC_CAST(PvmiCapabilityAndConfig*,
2310 plugInParams->iPlugInCapConfigExtensionInterfacePVI);
2311 plugInParams->iPlugInCapConfigExtensionInterfacePVI = NULL;
2312 }
2313 iNumQueryCapConfigExtensionInterfaceComplete++;
2314 CompleteCapConfigExtInterfaceQueryFromPlugIns();
2315 }
2316 break;
2317
2318 default:
2319 break;
2320 }
2321 return;
2322 }
2323
2324 CPMSessionInfo*
LookUpSessionInfo(PVMFSessionId aID)2325 PVMFCPMImpl::LookUpSessionInfo(PVMFSessionId aID)
2326 {
2327 Oscl_Vector<CPMSessionInfo, OsclMemAllocator>::iterator it;
2328 for (it = iListofActiveSessions.begin(); it != iListofActiveSessions.end(); it++)
2329 {
2330 if (it->iSessionId == aID)
2331 {
2332 return (it);
2333 }
2334 }
2335 return NULL;
2336 }
2337
LookUpContentUsageContext(PVMFCPMUsageID aID)2338 CPMContentUsageContext* PVMFCPMImpl::LookUpContentUsageContext(PVMFCPMUsageID aID)
2339 {
2340 Oscl_Vector<CPMContentUsageContext, OsclMemAllocator>::iterator it;
2341 for (it = iContentUsageContextVec.begin(); it != iContentUsageContextVec.end(); it++)
2342 {
2343 if (it->iUsageID == aID)
2344 {
2345 return (it);
2346 }
2347 }
2348 return NULL;
2349 }
2350
LookUpPlugInParams(uint32 aID)2351 CPMPlugInParams* PVMFCPMImpl::LookUpPlugInParams(uint32 aID)
2352 {
2353 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2354 for (it = iPlugInParamsVec.begin(); it != iPlugInParamsVec.end(); it++)
2355 {
2356 if (it->iPlugInID == aID)
2357 {
2358 return (it);
2359 }
2360 }
2361 return NULL;
2362 }
2363
LookUpPlugInParamsFromActiveList(uint32 aID)2364 CPMPlugInParams* PVMFCPMImpl::LookUpPlugInParamsFromActiveList(uint32 aID)
2365 {
2366 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2367 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2368 {
2369 if (it->iPlugInID == aID)
2370 {
2371 return (it);
2372 }
2373 }
2374 return NULL;
2375 }
2376
2377 OSCL_EXPORT_REF uint32
GetNumMetadataKeys(char * aQueryKeyString)2378 PVMFCPMImpl::GetNumMetadataKeys(char* aQueryKeyString)
2379 {
2380 uint32 numMetaDataKeys = 0;
2381 if (iActivePlugInParamsVec.size() > 0)
2382 {
2383 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2384 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2385 {
2386 if (NULL != it->iPlugInMetaDataExtensionInterface)
2387 {
2388 numMetaDataKeys +=
2389 it->iPlugInMetaDataExtensionInterface->GetNumMetadataKeys(aQueryKeyString);
2390 }
2391 }
2392 return numMetaDataKeys;
2393 }
2394 /* No active plugins */
2395 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::GetNumMetadataKeys - No Active Plugins"));
2396 return numMetaDataKeys;
2397 }
2398
2399 OSCL_EXPORT_REF uint32
GetNumMetadataValues(PVMFMetadataList & aKeyList)2400 PVMFCPMImpl::GetNumMetadataValues(PVMFMetadataList& aKeyList)
2401 {
2402 uint32 numMetaDataValues = 0;
2403 if (iActivePlugInParamsVec.size() > 0)
2404 {
2405 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2406 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2407 {
2408 if (NULL != it->iPlugInMetaDataExtensionInterface)
2409 {
2410 numMetaDataValues +=
2411 it->iPlugInMetaDataExtensionInterface->GetNumMetadataValues(aKeyList);
2412 }
2413 }
2414 return numMetaDataValues;
2415 }
2416 /* No active plugins */
2417 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::GetNumMetadataValues - No Active Plugins"));
2418 return numMetaDataValues;
2419 }
2420
2421 PVMFStatus
DoGetMetadataKeys(PVMFCPMCommand & aCmd)2422 PVMFCPMImpl::DoGetMetadataKeys(PVMFCPMCommand& aCmd)
2423 {
2424 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::DoGetMetadataKeys Called"));
2425 if (iActivePlugInParamsVec.size() == 0)
2426 {
2427 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoGetMetadataKeys - No Active Plugins"));
2428 return PVMFErrInvalidState;
2429 }
2430
2431 iGetMetaDataKeysInProgress = true;
2432
2433 if (iGetMetaDataKeysFromPlugInsDone == false)
2434 {
2435 if (CheckForMetaDataInterfaceAvailability())
2436 {
2437 PVMFStatus status = QueryForMetaDataKeys(aCmd);
2438 if (status != PVMFSuccess)
2439 {
2440 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoGetMetadataKeys - QueryForMetaDataKeys Failed"));
2441 return status;
2442 }
2443 return PVMFPending;
2444 }
2445 }
2446 return (CompleteDoGetMetadataKeys(aCmd));
2447 }
2448 PVMFStatus
CompleteDoGetMetadataKeys(PVMFCPMCommand & aCmd)2449 PVMFCPMImpl::CompleteDoGetMetadataKeys(PVMFCPMCommand& aCmd)
2450 {
2451 iGetMetaDataKeysInProgress = false;
2452
2453 int32 leavecode = OsclErrNone;
2454 PVMFMetadataList* keylistptr = NULL;
2455 int32 starting_index;
2456 int32 max_entries;
2457 char* query_key = NULL;
2458 aCmd.PVMFCPMCommand::Parse(keylistptr,
2459 starting_index,
2460 max_entries,
2461 query_key);
2462
2463 /* Check parameters */
2464 if ((keylistptr == NULL) ||
2465 (starting_index < 0) ||
2466 (max_entries == 0))
2467 {
2468 /* Invalid starting index and/or max entries */
2469 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteDoGetMetadataKeys - Invalid Args"));
2470 return PVMFErrArgument;
2471 }
2472
2473 /* Copy the requested keys from all active plugins */
2474 uint32 num_entries = 0;
2475 int32 num_added = 0;
2476 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2477 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2478 {
2479 it->iMetaDataKeyStartIndex = keylistptr->size();
2480 for (uint32 lcv = 0; lcv < it->iAvailableMetadataKeys.size(); lcv++)
2481 {
2482 if (query_key == NULL)
2483 {
2484 /* No query key so this key is counted */
2485 ++num_entries;
2486 if (num_entries > (uint32)starting_index)
2487 {
2488 /* Past the starting index so copy the key */
2489 leavecode = OsclErrNone;
2490 leavecode = PushKVPKey(it->iAvailableMetadataKeys[lcv], *keylistptr);
2491 if (OsclErrNone != leavecode)
2492 {
2493 return PVMFErrNoMemory;
2494 }
2495 num_added++;
2496 }
2497 }
2498 else
2499 {
2500 /* Check if the key matches the query key */
2501 if (pv_mime_strcmp((char*)it->iAvailableMetadataKeys[lcv].get_cstr(), query_key) >= 0)
2502 {
2503 /* This key is counted */
2504 ++num_entries;
2505 if (num_entries > (uint32)starting_index)
2506 {
2507 /* Past the starting index so copy the key */
2508 leavecode = OsclErrNone;
2509 leavecode = PushKVPKey(it->iAvailableMetadataKeys[lcv], *keylistptr);
2510 if (OsclErrNone != leavecode)
2511 {
2512 return PVMFErrNoMemory;
2513 }
2514 num_added++;
2515 }
2516 }
2517 }
2518 /* Check if max number of entries have been copied */
2519 if ((max_entries > 0) && (num_added >= max_entries))
2520 {
2521 break;
2522 }
2523 }
2524 it->iMetaDataValueEndIndex = keylistptr->size();
2525 }
2526 return PVMFSuccess;
2527 }
2528
2529 void
DoGetMetadataValues(PVMFCPMCommand & aCmd)2530 PVMFCPMImpl::DoGetMetadataValues(PVMFCPMCommand& aCmd)
2531 {
2532 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::DoGetMetadataValues Called"));
2533 MoveCmdToCurrentQueue(aCmd);
2534
2535 if (iActivePlugInParamsVec.size() == 0)
2536 {
2537 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoGetMetadataValues - No Active Plugins"));
2538 CommandComplete(iCurrentCommand,
2539 iCurrentCommand.front(),
2540 PVMFErrInvalidState);
2541 return;
2542 }
2543
2544 iKeyListPtr = NULL;
2545 iValueListPtr = NULL;
2546 iGetMetaDataValuesStartingIndex = 0;
2547 iGetMetaDataValuesMaxEntries = 0;
2548
2549
2550 aCmd.PVMFCPMCommand::Parse(iKeyListPtr,
2551 iValueListPtr,
2552 iGetMetaDataValuesStartingIndex,
2553 iGetMetaDataValuesMaxEntries);
2554
2555 /* Check the parameters */
2556 if (iKeyListPtr == NULL || iValueListPtr == NULL)
2557 {
2558 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoGetMetadataValues - Null Args"));
2559 CommandComplete(iCurrentCommand,
2560 iCurrentCommand.front(),
2561 PVMFErrArgument);
2562 return;
2563 }
2564
2565 uint32 numkeys = iKeyListPtr->size();
2566
2567 if ((iGetMetaDataValuesStartingIndex < 0) ||
2568 (iGetMetaDataValuesStartingIndex > (int32)(numkeys - 1)) ||
2569 ((int32)numkeys <= 0) ||
2570 (iGetMetaDataValuesMaxEntries == 0))
2571 {
2572 /* Don't do anything */
2573 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoGetMetadataValues - Invalid Args"));
2574 CommandComplete(iCurrentCommand,
2575 iCurrentCommand.front(),
2576 PVMFErrArgument);
2577 return;
2578 }
2579
2580 if (iActivePlugInParamsVec.size() > 0)
2581 {
2582 if (IsGetMetaDataValuesFromPlugInsComplete() == false)
2583 {
2584 CPMPlugInParams* plugInParams =
2585 LookUpNextPlugInForGetMetaDataValues();
2586
2587 SendGetMetaDataValuesToPlugIn(plugInParams);
2588 return;
2589 }
2590 else
2591 {
2592 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::DoGetMetadataValues - No Active Plugins With MetaData Support"));
2593 CommandComplete(iCurrentCommand,
2594 iCurrentCommand.front(),
2595 PVMFSuccess);
2596 return;
2597 }
2598 }
2599 /* No active plugins */
2600 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoGetMetadataValues - No Active Plugins"));
2601 CommandComplete(iCurrentCommand,
2602 iCurrentCommand.front(),
2603 PVMFFailure);
2604 return;
2605 }
2606
LookUpNextPlugInForGetMetaDataValues()2607 CPMPlugInParams* PVMFCPMImpl::LookUpNextPlugInForGetMetaDataValues()
2608 {
2609 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2610 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2611 {
2612 if (it->iGetMetaDataValuesComplete == false)
2613 {
2614 return (it);
2615 }
2616 }
2617 return NULL;
2618 }
2619
IsGetMetaDataValuesFromPlugInsComplete()2620 bool PVMFCPMImpl::IsGetMetaDataValuesFromPlugInsComplete()
2621 {
2622 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2623 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2624 {
2625 if (it->iPlugInMetaDataExtensionInterface == NULL)
2626 {
2627 /* No metadata ext intf - so treat it as complete */
2628 it->iGetMetaDataValuesComplete = true;
2629 }
2630 else
2631 {
2632 if (it->iGetMetaDataValuesComplete == false)
2633 {
2634 return false;
2635 }
2636 }
2637 }
2638 return true;
2639 }
2640
2641 void
SendGetMetaDataValuesToPlugIn(CPMPlugInParams * aParams)2642 PVMFCPMImpl::SendGetMetaDataValuesToPlugIn(CPMPlugInParams* aParams)
2643 {
2644 if (aParams != NULL)
2645 {
2646 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
2647 if (internalCmd != NULL)
2648 {
2649 internalCmd->cmd =
2650 PVMF_CPM_INTERNAL_GET_PLUGIN_META_DATA_VALUES_CMD;
2651 internalCmd->parentCmd = PVMF_CPM_GET_METADATA_VALUES;
2652 internalCmd->plugInID = aParams->iPlugInID;
2653 OsclAny *cmdContextData =
2654 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
2655
2656 aParams->iNumMetaDataValuesAvailable =
2657 aParams->iPlugInMetaDataExtensionInterface->GetNumMetadataValues((PVMFMetadataList&)(*iKeyListPtr));
2658 aParams->iMetaDataValueStartIndex = iValueListPtr->size();
2659 aParams->iPlugInMetaDataExtensionInterface->GetNodeMetadataValues(aParams->iPlugInSessionID,
2660 (PVMFMetadataList&)(*iKeyListPtr),
2661 (Oscl_Vector<PvmiKvp, OsclMemAllocator>&)(*iValueListPtr),
2662 0,
2663 aParams->iNumMetaDataValuesAvailable,
2664 cmdContextData);
2665 }
2666 else
2667 {
2668 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::RequestMetaDataValues - SendGetMetaDataValuesToPlugIn Failed"));
2669 CommandComplete(iCurrentCommand,
2670 iCurrentCommand.front(),
2671 PVMFErrNoMemory);
2672 return;
2673 }
2674 }
2675 }
2676
2677 void
CompleteGetMetaDataValues(PVMFCPMCommandContext * aContext)2678 PVMFCPMImpl::CompleteGetMetaDataValues(PVMFCPMCommandContext* aContext)
2679 {
2680 if (iActivePlugInParamsVec.size() > 0)
2681 {
2682 CPMPlugInParams* currPlugInParams =
2683 LookUpPlugInParamsFromActiveList(aContext->plugInID);
2684 OSCL_ASSERT(currPlugInParams);
2685 if (!currPlugInParams)
2686 return; // unlikely: lookup failed.
2687 currPlugInParams->iMetaDataValueEndIndex = iValueListPtr->size();
2688 currPlugInParams->iGetMetaDataValuesComplete = true;
2689
2690 if (IsGetMetaDataValuesFromPlugInsComplete() == false)
2691 {
2692 CPMPlugInParams* nextPlugInParams =
2693 LookUpNextPlugInForGetMetaDataValues();
2694
2695 SendGetMetaDataValuesToPlugIn(nextPlugInParams);
2696 }
2697 else
2698 {
2699 /* Reset for future retrievals */
2700 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2701 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2702 {
2703 it->iGetMetaDataValuesComplete = false;
2704 }
2705 CommandComplete(iCurrentCommand,
2706 iCurrentCommand.front(),
2707 PVMFSuccess);
2708 }
2709 return;
2710 }
2711 /* No active plugins */
2712 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::CompleteGetMetaDataValues - No Active Plugins"));
2713 CommandComplete(iCurrentCommand,
2714 iCurrentCommand.front(),
2715 PVMFFailure);
2716 return;
2717 }
2718
getParametersSync(PvmiMIOSession aSession,PvmiKeyType aIdentifier,PvmiKvp * & aParameters,int & num_parameter_elements,PvmiCapabilityContext aContext)2719 PVMFStatus PVMFCPMImpl::getParametersSync(PvmiMIOSession aSession,
2720 PvmiKeyType aIdentifier,
2721 PvmiKvp*& aParameters,
2722 int& num_parameter_elements,
2723 PvmiCapabilityContext aContext)
2724 {
2725 OSCL_UNUSED_ARG(aSession);
2726 OSCL_UNUSED_ARG(aIdentifier);
2727 OSCL_UNUSED_ARG(aParameters);
2728 OSCL_UNUSED_ARG(num_parameter_elements);
2729 OSCL_UNUSED_ARG(aContext);
2730
2731 return PVMFErrNotSupported;
2732 }
2733
2734
releaseParameters(PvmiMIOSession aSession,PvmiKvp * aParameters,int num_elements)2735 PVMFStatus PVMFCPMImpl::releaseParameters(PvmiMIOSession aSession,
2736 PvmiKvp* aParameters,
2737 int num_elements)
2738 {
2739 PVMFStatus status = PVMFFailure;
2740 if (aParameters)
2741 {
2742 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2743 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2744 {
2745 if (it->iPlugInCapConfigExtensionInterface != NULL)
2746 {
2747 status =
2748 it->iPlugInCapConfigExtensionInterface->releaseParameters(aSession,
2749 aParameters,
2750 num_elements);
2751 }
2752 }
2753 }
2754 return status;
2755 }
2756
2757
setParametersSync(PvmiMIOSession aSession,PvmiKvp * aParameters,int num_elements,PvmiKvp * & aRet_kvp)2758 void PVMFCPMImpl::setParametersSync(PvmiMIOSession aSession,
2759 PvmiKvp* aParameters,
2760 int num_elements,
2761 PvmiKvp*& aRet_kvp)
2762 {
2763 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2764 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2765 {
2766 if (it->iPlugInCapConfigExtensionInterface != NULL)
2767 {
2768 int32 err = OsclErrNone;
2769 OSCL_TRY(err,
2770 it->iPlugInCapConfigExtensionInterface->setParametersSync(aSession,
2771 aParameters,
2772 num_elements,
2773 aRet_kvp););
2774 /* Ignore error - Not all plugins need support all config params */
2775 }
2776 }
2777 }
2778
2779
verifyParametersSync(PvmiMIOSession aSession,PvmiKvp * aParameters,int num_elements)2780 PVMFStatus PVMFCPMImpl::verifyParametersSync(PvmiMIOSession aSession,
2781 PvmiKvp* aParameters,
2782 int num_elements)
2783 {
2784 PVMFStatus status = PVMFFailure;
2785 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2786 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2787 {
2788 if (it->iPlugInCapConfigExtensionInterface != NULL)
2789 {
2790 status =
2791 it->iPlugInCapConfigExtensionInterface->verifyParametersSync(aSession,
2792 aParameters,
2793 num_elements);
2794 }
2795 }
2796 return status;
2797 }
2798 PVMFCommandId
GetLicense(PVMFSessionId aSessionId,OSCL_wString & aContentName,OsclAny * aData,uint32 aDataSize,int32 aTimeoutMsec,OsclAny * aContextData)2799 PVMFCPMImpl::GetLicense(PVMFSessionId aSessionId,
2800 OSCL_wString& aContentName,
2801 OsclAny* aData,
2802 uint32 aDataSize,
2803 int32 aTimeoutMsec,
2804 OsclAny* aContextData)
2805 {
2806 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl:GetLicense - Wide"));
2807 PVMFCPMCommand cmd;
2808 cmd.Construct(aSessionId,
2809 PVMF_CPM_GET_LICENSE_W,
2810 aContentName,
2811 aData,
2812 aDataSize,
2813 aTimeoutMsec,
2814 aContextData);
2815 return QueueCommandL(cmd);
2816 }
2817
2818 PVMFCommandId
GetLicense(PVMFSessionId aSessionId,OSCL_String & aContentName,OsclAny * aData,uint32 aDataSize,int32 aTimeoutMsec,OsclAny * aContextData)2819 PVMFCPMImpl::GetLicense(PVMFSessionId aSessionId,
2820 OSCL_String& aContentName,
2821 OsclAny* aData,
2822 uint32 aDataSize,
2823 int32 aTimeoutMsec,
2824 OsclAny* aContextData)
2825 {
2826 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl:GetLicense"));
2827 PVMFCPMCommand cmd;
2828 cmd.Construct(aSessionId,
2829 PVMF_CPM_GET_LICENSE,
2830 aContentName,
2831 aData,
2832 aDataSize,
2833 aTimeoutMsec,
2834 aContextData);
2835 return QueueCommandL(cmd);
2836 }
2837
2838 PVMFCommandId
CancelGetLicense(PVMFSessionId aSessionId,PVMFCommandId aCmdId,OsclAny * aContextData)2839 PVMFCPMImpl::CancelGetLicense(PVMFSessionId aSessionId, PVMFCommandId aCmdId, OsclAny* aContextData)
2840 {
2841 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl:CancelGetLicense"));
2842 PVMFCPMCommand cmd;
2843 cmd.PVMFCPMCommandBase::Construct(aSessionId,
2844 PVMF_CPM_CANCEL_GET_LICENSE,
2845 aCmdId,
2846 aContextData);
2847 return QueueCommandL(cmd);
2848 }
2849
GetLicenseStatus(PVMFCPMLicenseStatus & aStatus)2850 PVMFStatus PVMFCPMImpl::GetLicenseStatus(
2851 PVMFCPMLicenseStatus& aStatus)
2852 {
2853 if (iLicenseInterface)
2854 return iLicenseInterface->GetLicenseStatus(aStatus);
2855 return PVMFFailure;
2856 }
2857
DoGetLicense(PVMFCPMCommand & aCmd,bool aWideCharVersion)2858 PVMFStatus PVMFCPMImpl::DoGetLicense(PVMFCPMCommand& aCmd,
2859 bool aWideCharVersion)
2860 {
2861 iLicenseInterface = NULL;
2862 CPMSessionInfo* sInfo = LookUpSessionInfo(aCmd.iSession);
2863 CPMPlugInParams* pluginParamsPtr = NULL;
2864 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2865 if (sInfo != NULL)
2866 {
2867 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2868 {
2869 if (it->iPlugInID == sInfo->iAccessPlugInID)
2870 {
2871 iLicenseInterface = it->iPlugInLicenseInterface;
2872 pluginParamsPtr = it;
2873 }
2874 }
2875 }
2876
2877 if (iLicenseInterface == NULL)
2878 {
2879 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoGetLicense - No License Interface"));
2880 return PVMFErrNotSupported;
2881 }
2882
2883 if (aWideCharVersion == true)
2884 {
2885 OSCL_wString* contentName = NULL;
2886 OsclAny* data = NULL;
2887 uint32 dataSize = 0;
2888 int32 timeoutMsec = 0;
2889 aCmd.Parse(contentName,
2890 data,
2891 dataSize,
2892 timeoutMsec);
2893
2894 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
2895 if (internalCmd != NULL)
2896 {
2897 internalCmd->cmd = PVMF_CPM_INTERNAL_GET_LICENSE_CMD;
2898 internalCmd->parentCmd = PVMF_CPM_GET_LICENSE_W;
2899 internalCmd->plugInID = pluginParamsPtr->iPlugInID;
2900 OsclAny *cmdContextData =
2901 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
2902 iGetLicenseCmdId =
2903 iLicenseInterface->GetLicense(pluginParamsPtr->iPlugInSessionID,
2904 *contentName,
2905 data,
2906 dataSize,
2907 timeoutMsec,
2908 cmdContextData);
2909 }
2910 else
2911 {
2912 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoGetLicense - RequestNewInternalCmd Failed"));
2913 return PVMFErrNoMemory;
2914 }
2915 }
2916 else
2917 {
2918 OSCL_String* contentName = NULL;
2919 OsclAny* data = NULL;
2920 uint32 dataSize = 0;
2921 int32 timeoutMsec = 0;
2922 aCmd.Parse(contentName,
2923 data,
2924 dataSize,
2925 timeoutMsec);
2926 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
2927 if (internalCmd != NULL)
2928 {
2929 internalCmd->cmd = PVMF_CPM_INTERNAL_GET_LICENSE_CMD;
2930 internalCmd->parentCmd = PVMF_CPM_GET_LICENSE;
2931 internalCmd->plugInID = pluginParamsPtr->iPlugInID;
2932 OsclAny *cmdContextData =
2933 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
2934 iGetLicenseCmdId =
2935 iLicenseInterface->GetLicense(pluginParamsPtr->iPlugInSessionID,
2936 *contentName,
2937 data,
2938 dataSize,
2939 timeoutMsec,
2940 cmdContextData);
2941 }
2942 else
2943 {
2944 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoGetLicense - RequestNewInternalCmd Failed"));
2945 return PVMFErrNoMemory;
2946 }
2947 }
2948 return PVMFPending;
2949 }
2950
CompleteGetLicense()2951 void PVMFCPMImpl::CompleteGetLicense()
2952 {
2953 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl::CompleteGetLicense - Success"));
2954 CommandComplete(iCurrentCommand,
2955 iCurrentCommand.front(),
2956 PVMFSuccess);
2957 }
2958
DoCancelGetLicense(PVMFCPMCommand & aCmd)2959 void PVMFCPMImpl::DoCancelGetLicense(PVMFCPMCommand& aCmd)
2960 {
2961 PVMF_CPM_LOGINFO((0, "PVMFCPMImpl:DoCancelGetLicense is called"));
2962 /* extract the command ID from the parameters.*/
2963 PVMFCommandId id;
2964 aCmd.PVMFCPMCommandBase::Parse(id);
2965 PVMFStatus status = PVMFErrArgument;
2966
2967 iLicenseInterface = NULL;
2968 CPMSessionInfo* sInfo = LookUpSessionInfo(aCmd.iSession);
2969 CPMPlugInParams* pluginParamsPtr = NULL;
2970 Oscl_Vector<CPMPlugInParams, OsclMemAllocator>::iterator it;
2971 if (sInfo != NULL)
2972 {
2973 for (it = iActivePlugInParamsVec.begin(); it != iActivePlugInParamsVec.end(); it++)
2974 {
2975 if (it->iPlugInID == sInfo->iAccessPlugInID)
2976 {
2977 iLicenseInterface = it->iPlugInLicenseInterface;
2978 pluginParamsPtr = it;
2979 }
2980 }
2981 }
2982
2983 /* first check "current" command if any */
2984 PVMFCPMCommand* cmd = iCurrentCommand.FindById(id);
2985 if (cmd)
2986 {
2987 if (cmd->iCmd == PVMF_CPM_GET_LICENSE_W || cmd->iCmd == PVMF_CPM_GET_LICENSE)
2988 {
2989 PVMFCPMCommandContext* internalCmd = RequestNewInternalCmd();
2990 if (internalCmd != NULL)
2991 {
2992 internalCmd->cmd = PVMF_CPM_INTERNAL_CANCEL_GET_LICENSE;
2993 internalCmd->parentCmd = PVMF_CPM_CANCEL_GET_LICENSE;
2994
2995 OSCL_ASSERT(pluginParamsPtr);
2996
2997 if (!pluginParamsPtr)
2998
2999 {
3000
3001 status = PVMFErrCorrupt;
3002
3003 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoCancelGetLicense - data corrupted"));
3004
3005 CommandComplete(iInputCommands, aCmd, status);
3006
3007 return;
3008
3009 }
3010
3011 internalCmd->plugInID = pluginParamsPtr->iPlugInID;
3012
3013 OsclAny *cmdContextData =
3014 OSCL_REINTERPRET_CAST(OsclAny*, internalCmd);
3015
3016 iLicenseInterface->CancelGetLicense(pluginParamsPtr->iPlugInSessionID, iGetLicenseCmdId, cmdContextData);
3017
3018 /*
3019 * the queued commands are all asynchronous commands to the
3020 * CPM module. CancelGetLicense can cancel only for GetLicense cmd.
3021 * We need to wait CPMPluginCommandCompleted.
3022 */
3023 MoveCmdToCancelQueue(aCmd);
3024 return;
3025 }
3026 else
3027 {
3028 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoCancelGetLicense - RequestNewInternalCmd Failed"));
3029 status = PVMFErrNoMemory;
3030 }
3031 }
3032 }
3033 PVMF_CPM_LOGERROR((0, "PVMFCPMImpl::DoCancelGetLicense - current cmd is not GetLicense"));
3034 CommandComplete(iInputCommands, aCmd, status);
3035 return;
3036 }
3037
addPluginToRegistry(OSCL_String & aMimeType,CPMPluginContainer & aPlugInContainer)3038 OSCL_EXPORT_REF bool CPMPluginRegistryImpl::addPluginToRegistry(OSCL_String& aMimeType,
3039 CPMPluginContainer& aPlugInContainer)
3040 {
3041 CPMPluginContainer*container = lookupPlugin(aMimeType);
3042 if (container)
3043 return false;//duplicate mime type!
3044 container = OSCL_NEW(CPMPluginContainer, (aPlugInContainer));
3045 iCPMPluginRegistry.insert(value_type(aMimeType, container));
3046 iListofPlugInMimeTypes.push_back(aMimeType);
3047 return true;
3048 }
3049
removePluginFromRegistry(OSCL_String & aMimeType)3050 OSCL_EXPORT_REF void CPMPluginRegistryImpl::removePluginFromRegistry(OSCL_String& aMimeType)
3051 {
3052 CPMPluginContainer*container = lookupPlugin(aMimeType);
3053 if (container)
3054 {
3055 OSCL_DELETE(container);
3056 }
3057 for (uint32 i = 0; i < iListofPlugInMimeTypes.size(); i++)
3058 {
3059 if (iListofPlugInMimeTypes[i] == aMimeType)
3060 {
3061 iListofPlugInMimeTypes.erase(&iListofPlugInMimeTypes[i]);
3062 iCPMPluginRegistry.erase(iCPMPluginRegistry.find(aMimeType));
3063 }
3064 }
3065 }
3066
lookupPlugin(OSCL_String & aMimeType)3067 OSCL_EXPORT_REF CPMPluginContainer* CPMPluginRegistryImpl::lookupPlugin(OSCL_String& aMimeType)
3068 {
3069 Oscl_Map<string_key_type, CPMPluginContainer*, OsclMemAllocator, string_key_compare_class>::iterator it;
3070 it = iCPMPluginRegistry.find(aMimeType);
3071
3072 /* Workaround for the ADS1.2 compiler*/
3073 if (!(it == iCPMPluginRegistry.end()))
3074 {
3075 return (((*it).second));
3076 }
3077 return NULL;
3078 }
3079
GetNumPlugIns()3080 OSCL_EXPORT_REF uint32 CPMPluginRegistryImpl::GetNumPlugIns()
3081 {
3082 return (iCPMPluginRegistry.size());
3083 }
3084
GetPluginMimeType(uint32 aIndex,OSCL_String & aMimeType)3085 OSCL_EXPORT_REF bool CPMPluginRegistryImpl::GetPluginMimeType(uint32 aIndex, OSCL_String& aMimeType)
3086 {
3087 if (aIndex < GetNumPlugIns())
3088 {
3089 aMimeType = iListofPlugInMimeTypes[aIndex];
3090 return true;
3091 }
3092 return false;//invalid index.
3093 }
3094
CPMPluginRegistryImpl()3095 OSCL_EXPORT_REF CPMPluginRegistryImpl::CPMPluginRegistryImpl()
3096 {
3097 iRefCount = 0;
3098 iSharedLibList = NULL;
3099 }
3100
3101 #ifdef USE_LOADABLE_MODULES
3102 #include "oscl_shared_library.h"
3103 #endif
3104
~CPMPluginRegistryImpl()3105 OSCL_EXPORT_REF CPMPluginRegistryImpl::~CPMPluginRegistryImpl()
3106 {
3107 //just in case plugins weren't removed, go through and cleanup
3108 for (uint32 i = 0; i < iListofPlugInMimeTypes.size(); i++)
3109 {
3110 CPMPluginContainer* container = lookupPlugin(iListofPlugInMimeTypes[i]);
3111 if (container)
3112 OSCL_DELETE(container);
3113 }
3114 #ifdef USE_LOADABLE_MODULES
3115 if (iSharedLibList)
3116 OSCL_DELETE(iSharedLibList);
3117 #endif
3118 }
3119
CreateCPMPluginRegistry()3120 CPMPluginRegistry* CPMPluginRegistryFactory::CreateCPMPluginRegistry()
3121 {
3122 return (CPMPluginRegistry*)OSCL_NEW(CPMPluginRegistryImpl, ());
3123 }
3124
DestroyCPMPluginRegistry(CPMPluginRegistry * aReg)3125 void CPMPluginRegistryFactory::DestroyCPMPluginRegistry(CPMPluginRegistry* aReg)
3126 {
3127 CPMPluginRegistryImpl* impl = (CPMPluginRegistryImpl*)aReg;
3128 OSCL_DELETE(impl);
3129 }
3130
PushKVPKey(OSCL_String & aString,PVMFMetadataList & aKeyList)3131 int32 PVMFCPMImpl::PushKVPKey(OSCL_String& aString, PVMFMetadataList& aKeyList)
3132 {
3133 int32 leavecode = OsclErrNone;
3134 OSCL_TRY(leavecode, aKeyList.push_back(aString));
3135 return leavecode;
3136 }
3137