OMX_ERRORTYPE OmxComponentFactoryDynamicCreate(OMX_OUT OMX_HANDLETYPE* pHandle, OMX_IN  OMX_PTR pAppData, OMX_IN OMX_PTR pProxy, OMX_STRING aOmxLibName, OMX_PTR &aOmxLib, OMX_PTR aOsclUuid, OMX_U32 &aRefCount)
{
    OMX_ERRORTYPE returnStatus = OMX_ErrorUndefined;

    OsclSharedLibrary* lib = NULL;

    // If aOmxLib is NULL, this is the first time this method has been called
    if (NULL == aOmxLib)
    {
        OSCL_StackString<OMX_MAX_LIB_PATH> Libname(aOmxLibName);
        lib = OSCL_NEW(OsclSharedLibrary, (Libname));
    }
    else
    {
        lib = (OsclSharedLibrary *) aOmxLib;
    }


    // Load the associated library. If successful, call the corresponding
    // create function located inside the loaded library
    OsclLibStatus loadStatus = OsclLibSuccess;
    if (aRefCount == 0)
    {
        loadStatus = lib->LoadLib();
    }
    if (loadStatus == OsclLibSuccess)
    {
        aRefCount++;
        // look for the interface
        OsclAny* interfacePtr = NULL;
        if (OsclLibSuccess == lib->QueryInterface(PV_OMX_SHARED_INTERFACE, (OsclAny*&)interfacePtr))
        {
            // the interface ptr should be ok, but check just in case
            if (interfacePtr != NULL)
            {
                OmxSharedLibraryInterface* omxIntPtr =
                    OSCL_DYNAMIC_CAST(OmxSharedLibraryInterface*, interfacePtr);


                OsclUuid *temp = (OsclUuid*) aOsclUuid;
                OsclAny* createCompTemp =
                    omxIntPtr->QueryOmxComponentInterface(*temp, PV_OMX_CREATE_INTERFACE);

                // check if the component contains the correct ptr
                if (createCompTemp != NULL)
                {

                    // createComp is the function pointer to store the creation function
                    // for the omx component located inside the loaded library
                    OMX_ERRORTYPE(*createComp)(OMX_OUT OMX_HANDLETYPE* pHandle, OMX_IN  OMX_PTR pAppData, OMX_IN OMX_PTR pProxy, OMX_STRING aOmxLibName, OMX_PTR &aOmxLib, OMX_PTR aOsclUuid, OMX_U32 &aRefCount);

                    createComp = OSCL_DYNAMIC_CAST(OMX_ERRORTYPE(*)(OMX_OUT OMX_HANDLETYPE * pHandle, OMX_IN  OMX_PTR pAppData, OMX_IN OMX_PTR , OMX_STRING, OMX_PTR &, OMX_PTR , OMX_U32 &), createCompTemp);

                    // call the component AO factory inside the loaded library
                    returnStatus = (*createComp)(pHandle, pAppData, pProxy, aOmxLibName, aOmxLib, aOsclUuid, aRefCount);

                    // Store the shared library so it can be closed later
                    aOmxLib = (OMX_PTR) lib;
                }
            }
// Factory functions
PVMFNodeInterface* StreamingNodesCoreLibraryLoader::CreateStreamingManagerNode(int32 aPriority)
{
    OsclSharedLibrary* streamingSharedLibrary = NULL;
    OSCL_StackString<NODE_REGISTRY_LIB_NAME_MAX_LENGTH> libname(RTSP_LIB_NAME);

    // Need to load the library for the node
    streamingSharedLibrary = OSCL_NEW(OsclSharedLibrary, (libname));
    OsclLibStatus result = streamingSharedLibrary->LoadLib();
    if (OsclLibSuccess != result)
    {
        return NULL;
    }

    streamingSharedLibrary->AddRef();

    // Query for create function
    OsclAny* interfacePtr = NULL;

    streamingSharedLibrary->QueryInterface(PV_NODE_INTERFACE, (OsclAny*&)interfacePtr);

    NodeSharedLibraryInterface* nodeIntPtr = OSCL_DYNAMIC_CAST(NodeSharedLibraryInterface*, interfacePtr);

    OsclAny* createFuncTemp = nodeIntPtr->QueryNodeInterface(KPVMFRTSPStreamingModuleUuid, PV_CREATE_NODE_INTERFACE);

    LPFN_NODE_CREATE_FUNC nodeCreateFunc = OSCL_DYNAMIC_CAST(PVMFNodeInterface * (*)(int32), createFuncTemp);

    if (NULL != nodeCreateFunc)
    {
        PVMFNodeInterface* node = NULL;
        // call the real node factory function
        node = (*(nodeCreateFunc))(aPriority);
        if (NULL == node)
        {
            streamingSharedLibrary->RemoveRef();

            if (OsclLibSuccess == streamingSharedLibrary->Close())
            {
                // Close will unload the library if refcount is 0
                OSCL_DELETE(streamingSharedLibrary);
            }

            return NULL;
        }
        node->SetSharedLibraryPtr(streamingSharedLibrary);
        return node;
    }
    return NULL;
}
// Factory functions
ProtocolContainer* ProtocolEngineNodeProgressiveDownloadContainerLoader::CreateProgressiveDownloadContainer(PVMFProtocolEngineNode* aNode)
{
    OsclSharedLibrary* aSharedLibrary = NULL;
    OSCL_StackString<LIB_NAME_MAX_LENGTH> libname(PDL_PLUGIN_LIB_NAME);

    // Need to load the library for the node
    aSharedLibrary = OSCL_NEW(OsclSharedLibrary, ());

    OsclLibStatus result = aSharedLibrary->LoadLib(libname);
    if (OsclLibSuccess != result) return NULL;
    aSharedLibrary->AddRef();

    // Query for create function
    OsclAny* interfacePtr = NULL;
    aSharedLibrary->QueryInterface(PENODE_SHARED_LIBRARY_INTERFACE, (OsclAny*&)interfacePtr);
    if (NULL == interfacePtr) return NULL;

    ProtocolEngineNodeSharedLibraryInterface* libIntPtr = OSCL_DYNAMIC_CAST(ProtocolEngineNodeSharedLibraryInterface*, interfacePtr);

    OsclAny* createFuncTemp = libIntPtr->QueryLibInterface(PENODE_CREATE_LIB_INTERFACE);
    if (!createFuncTemp) return NULL;

    LPFN_LIB_CREATE_FUNC libCreateFunc = OSCL_DYNAMIC_CAST(ProtocolContainer * (*)(PVMFProtocolEngineNode *), createFuncTemp);

    if (NULL != libCreateFunc)
    {
        // call the real node factory function
        ProtocolContainer *aProtocolContainer = (*(libCreateFunc))(aNode);
        if (NULL != aProtocolContainer)
        {
            aProtocolContainer->SetSharedLibraryPtr(aSharedLibrary);
            return aProtocolContainer;
        }
    }

    aSharedLibrary->RemoveRef();
    if (OsclLibSuccess == aSharedLibrary->Close())
    {
        // Close will unload the library if refcount is 0
        OSCL_DELETE(aSharedLibrary);
    }
    return NULL;
}