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 #include "oscl_shared_library.h" 19 #include "pvprotocolenginenode_pdl_plugin_registry.h" 20 #include "pvmf_protocol_engine_node_shared_lib_interface.h" 21 #include "pvmf_protocol_engine_node_registry_interface.h" 22 #include "pvmf_protocol_engine_node_registry_populator_interface.h" 23 #include "pvmf_protocol_engine_node_progressive_download_container_factory.h" 24 #include "pvmf_protocol_engine_node_common.h" 25 26 27 #define PDL_PLUGIN_LIB_NAME "" 28 29 #define LIB_NAME_MAX_LENGTH 64 30 31 typedef ProtocolContainer*(* LPFN_LIB_CREATE_FUNC)(PVMFProtocolEngineNode *); 32 typedef bool (* LPFN_LIB_RELEASE_FUNC)(ProtocolContainer *); 33 34 // Factory functions 35 ProtocolContainer* ProtocolEngineNodeProgressiveDownloadContainerLoader::CreateProgressiveDownloadContainer(PVMFProtocolEngineNode* aNode) 36 { 37 OsclSharedLibrary* aSharedLibrary = NULL; 38 OSCL_StackString<LIB_NAME_MAX_LENGTH> libname(PDL_PLUGIN_LIB_NAME); 39 40 // Need to load the library for the node 41 aSharedLibrary = OSCL_NEW(OsclSharedLibrary, ()); 42 43 OsclLibStatus result = aSharedLibrary->LoadLib(libname); 44 if (OsclLibSuccess != result) return NULL; 45 aSharedLibrary->AddRef(); 46 47 // Query for create function 48 OsclAny* interfacePtr = NULL; 49 aSharedLibrary->QueryInterface(PENODE_SHARED_LIBRARY_INTERFACE, (OsclAny*&)interfacePtr); 50 if (NULL == interfacePtr) return NULL; 51 52 ProtocolEngineNodeSharedLibraryInterface* libIntPtr = OSCL_DYNAMIC_CAST(ProtocolEngineNodeSharedLibraryInterface*, interfacePtr); 53 54 OsclAny* createFuncTemp = libIntPtr->QueryLibInterface(PENODE_CREATE_LIB_INTERFACE); 55 if (!createFuncTemp) return NULL; 56 57 LPFN_LIB_CREATE_FUNC libCreateFunc = OSCL_DYNAMIC_CAST(ProtocolContainer * (*)(PVMFProtocolEngineNode *), createFuncTemp); 58 59 if (NULL != libCreateFunc) 60 { 61 // call the real node factory function 62 ProtocolContainer *aProtocolContainer = (*(libCreateFunc))(aNode); 63 if (NULL != aProtocolContainer) 64 { 65 aProtocolContainer->SetSharedLibraryPtr(aSharedLibrary); 66 return aProtocolContainer; 67 } 68 } 69 70 aSharedLibrary->RemoveRef(); 71 if (OsclLibSuccess == aSharedLibrary->Close()) 72 { 73 // Close will unload the library if refcount is 0 74 OSCL_DELETE(aSharedLibrary); 75 } 76 return NULL; 77 } 78 79 bool ProtocolEngineNodeProgressiveDownloadContainerLoader::DeleteProgressiveDownloadContainer(ProtocolContainer* aContainer) 80 { 81 if (NULL == aContainer) return false; 82 83 // Retrieve shared library pointer 84 OsclSharedLibrary* aSharedLibrary = aContainer->GetSharedLibraryPtr(); 85 86 bool bStatus = false; 87 if (NULL != aSharedLibrary) 88 { 89 // Query for release function 90 OsclAny* interfacePtr = NULL; 91 aSharedLibrary->QueryInterface(PENODE_SHARED_LIBRARY_INTERFACE, (OsclAny*&)interfacePtr); 92 93 ProtocolEngineNodeSharedLibraryInterface* libIntPtr = OSCL_DYNAMIC_CAST(ProtocolEngineNodeSharedLibraryInterface*, interfacePtr); 94 95 OsclAny* releaseFuncTemp = libIntPtr->QueryLibInterface(PENODE_RELEASE_LIB_INTERFACE); 96 if (!releaseFuncTemp) return false; 97 98 LPFN_LIB_RELEASE_FUNC libReleaseFunc = OSCL_DYNAMIC_CAST(bool (*)(ProtocolContainer*), releaseFuncTemp); 99 100 if (NULL != libReleaseFunc) 101 { 102 bStatus = (*(libReleaseFunc))(aContainer); 103 } 104 105 aSharedLibrary->RemoveRef(); 106 107 if (OsclLibSuccess == aSharedLibrary->Close()) 108 { 109 // Close will unload the library if refcount is 0 110 OSCL_DELETE(aSharedLibrary); 111 } 112 } 113 114 return bStatus; 115 } 116 117 118 class ProtocolEngineNodeProgressiveDownloadContainerRegistryPopulatorInterface: public OsclSharedLibraryInterface, 119 public PVMFProtocolEngineNodeRegistryPopulatorInterface 120 { 121 public: 122 ProtocolEngineNodeProgressiveDownloadContainerRegistryPopulatorInterface() {}; 123 124 // From OsclSharedLibraryInterface 125 OsclAny* SharedLibraryLookup(const OsclUuid& aInterfaceId) 126 { 127 if (aInterfaceId == PVMF_PROTOCOL_ENGINE_NODE_REGISTRY_POPULATOR_INTERFACE) 128 { 129 return OSCL_STATIC_CAST(PVMFProtocolEngineNodeRegistryPopulatorInterface*, this); 130 } 131 return NULL; 132 }; 133 134 // From PVMFProtocolEngineNodeRegistryPopulatorInterface 135 void Register(PVMFProtocolEngineNodeRegistryInterface* aRegistry) 136 { 137 PVMFProtocolEngineContainerInfo aContainerInfo; 138 aContainerInfo.iSourceType = PVMF_MIME_DATA_SOURCE_HTTP_URL; 139 aContainerInfo.iProtocolEngineContainerUUID = KPVMFProtocolEngineNodeProgressiveDownloadUuid; 140 aContainerInfo.iProtocolEngineContainerCreateFunc = ProtocolEngineNodeProgressiveDownloadContainerLoader::CreateProgressiveDownloadContainer; 141 aContainerInfo.iProtocolEngineContainerReleaseFunc = ProtocolEngineNodeProgressiveDownloadContainerLoader::DeleteProgressiveDownloadContainer; 142 if (aRegistry) aRegistry->RegisterProtocolEngineContainer(&aContainerInfo); 143 } 144 145 void Unregister(PVMFProtocolEngineNodeRegistryInterface* aRegistry) 146 { 147 OSCL_UNUSED_ARG(aRegistry); 148 } 149 }; 150 151 extern "C" 152 { 153 OSCL_EXPORT_REF OsclSharedLibraryInterface* PVGetInterface(void) 154 { 155 return OSCL_NEW(ProtocolEngineNodeProgressiveDownloadContainerRegistryPopulatorInterface, ()); 156 } 157 158 OSCL_EXPORT_REF void PVReleaseInterface(OsclSharedLibraryInterface* aInstance) 159 { 160 OSCL_DELETE(aInstance); 161 } 162 } 163 164