Example #1
0
static struct list *construct_components(void)
{
    struct list *head = NULL, *preload_entry;
    ComponentHandlePtr component_handle;

    /* In Chromium OS, the OMX IL Client will call preload_components()
     * so that the preload_list is already populated. In non-chrome case,
     * we need to create the list here */
    if (!preload_list) {
       if (!create_preload_list()) {
          omx_verboseLog("error: Preload list cannot be populated");
       }
    }

    list_foreach(preload_list, preload_entry) {
        CModule *cmodule;
        struct list *entry;
        OMX_ERRORTYPE ret;

        component_handle = (ComponentHandlePtr) preload_entry->data;

        /* skip libraries starting with # */
        if (component_handle->comp_name[0] == '#')
            continue;

        cmodule = new CModule(component_handle->comp_name);
        if (!cmodule)
            continue;

        omx_verboseLog("found component library %s", component_handle->comp_name);

        ret = cmodule->Load(MODULE_NOW, component_handle->comp_handle);
        if (ret != OMX_ErrorNone)
            goto delete_cmodule;

        ret = cmodule->SetParser(component_handle->parser_handle);
        if (ret != OMX_ErrorNone)
            goto delete_cmodule;

        ret = cmodule->QueryComponentNameAndRoles();
        if (ret != OMX_ErrorNone)
            goto unload_cmodule;

        entry = list_alloc(cmodule);
        if (!entry)
            goto unload_cmodule;
        head = __list_add_tail(head, entry);

        omx_verboseLog("module %s:%s added to component list",
             cmodule->GetLibraryName(), cmodule->GetComponentName());

        continue;

    unload_cmodule:
        cmodule->Unload();
    delete_cmodule:
        delete cmodule;
    }
Example #2
0
oexINT CService::RunModule( CStr x_sModule, CStr x_sCommandLine, oexCPVOID x_pData, oexGUID *x_pguidType, oexINT x_nIdleDelay, oexINT x_nFlags )
{
	// Load the module
	CModule mod;
	if ( !mod.Load( x_sModule.Ptr() ) )
	{	oexERROR( 0, oexMks( oexT( "Failed to load module " ), x_sModule ) );
		return -1;
	} // end if

	service::PFN_SRV_GetModuleInfo pGetModuleInfo =
		(service::PFN_SRV_GetModuleInfo)mod.AddFunction( oexT( "SRV_GetModuleInfo" ) );
	if ( !oexCHECK_PTR( pGetModuleInfo ) )
	{	oexERROR( 0, oexMks( oexT( "Module '" ), x_sModule, oexT( "' does not contain symbol SRV_GetModuleInfo()" ) ) );
		return -2;
	} // end if

	// Get module information
	service::SSrvInfo si;
	oexZeroMemory( &si, sizeof( si ) );
	if ( oexINT ret = pGetModuleInfo( &si ) )
	{	oexERROR( ret, oexMks( oexT( "Module '" ), x_sModule, oexT( "', SRV_GetModuleInfo() failed by returning non-zero" ) ) );
		return -3;
	} // end if

	// Verify correct module type
	if ( oexCHECK_PTR( x_pguidType ) && !guid::CmpGuid( x_pguidType, &si.guidType ) )
	{	oexERROR( 0, oexMks( oexT( "Module '" ), x_sModule, oexT( "', incorrect module type, " ),
	                         CStr().GuidToString( x_pguidType ), oexT( " != " ),  CStr().GuidToString( &si.guidType ) ) );
		return -4;
	} // end if

	// Log information about the module
	oexNOTICE( 0, CStr().Fmt( oexT( "Module Loaded:  '%s'\r\n"
								    "Command Line:   '%s'\r\n"
								    "Name:           %s\r\n"
								    "Version:        %d.%d\r\n"
								    "Description:    %s\r\n"
								    "Type:           %s\r\n"
								    "ID:             %s\r\n"
								    "Instance:       %s\r\n" ),
							   oexStrToMbPtr( x_sModule.Ptr() ),
							   oexStrToMbPtr( x_sCommandLine.Ptr() ),
							   si.szName,
							   oexVERSION_MAJOR( si.lVer ), oexVERSION_MINOR( si.lVer ),
							   si.szDesc,
							   oexStrToMbPtr( CStr().GuidToString( &si.guidType ).Ptr() ),
							   oexStrToMbPtr( CStr().GuidToString( &si.guidId ).Ptr() ),
							   oexStrToMbPtr( CStr().GuidToString( &si.guidInstance ).Ptr() ) ) );

	// Load start function
	service::PFN_SRV_Start pStart =
		(service::PFN_SRV_Start)mod.AddFunction( oexT( "SRV_Start" ) );
	if ( !oexCHECK_PTR( pStart ) )
		oexWARNING( 0, CStr().Fmt( oexT( "Symbol SRV_Start() not found in module '%s'" ),
					   			   oexStrToMbPtr( x_sModule.Ptr() ) ) );

	// Call start function if provided
	else if ( oexINT ret = pStart( CMem::GetRawAllocator(), x_sModule.Ptr(), x_sCommandLine.Ptr(), x_sCommandLine.Length(), x_pData ) )
	{	oexNOTICE( ret, CStr().Fmt( oexT( "Exiting because SRV_Start() returned non-zero in module %s" ),
					   			  oexStrToMbPtr( x_sModule.Ptr() ) ) );
		return 0;
	} // end if

	oexNOTICE( 0, CStr().Fmt( oexT( "Module '%s' started successfully" ),
					       	  oexStrToMbPtr( x_sModule.Ptr() ) ) );

	// Load idle function
	service::PFN_SRV_Idle pIdle =
		(service::PFN_SRV_Idle)mod.AddFunction( oexT( "SRV_Idle" ) );
	if ( !oexCHECK_PTR( pIdle ) )
		oexWARNING( 0, CStr().Fmt( oexT( "Symbol SRV_Idle() not found in module '%s'" ),
					   			   oexStrToMbPtr( x_sModule.Ptr() ) ) );

	// Run idle loop if function provided
	else
		while ( !pIdle() )
			os::CSys::Sleep( x_nIdleDelay );

	// Check for stop function
	service::PFN_SRV_Stop pStop =
		(service::PFN_SRV_Stop)mod.AddFunction( oexT( "SRV_Stop" ) );
	if ( !oexCHECK_PTR( pStop ) )
	{	oexWARNING( 0, CStr().Fmt( oexT( "Symbol SRV_Stop() not found in module '%s'" ),
					   			   oexStrToMbPtr( x_sModule.Ptr() ) ) );
		return 0;
	} // end if

	// Call stop function
	return pStop();
}
static struct list *construct_components(const char *config_file_name)
{
    FILE *config_file;
    char library_name[OMX_MAX_STRINGNAME_SIZE];
    char config_file_path[256];
    struct list *head = NULL;

    strncpy(config_file_path, "/etc/", 256);
    strncat(config_file_path, config_file_name, 256);
    config_file = fopen(config_file_path, "r");
    if (!config_file) {
        strncpy(config_file_path, "./", 256);
        strncat(config_file_path, config_file_name, 256);
        config_file = fopen(config_file_path, "r");
        if (!config_file) {
            ALOGE("not found file %s\n", config_file_name);
            return NULL;
        }
    }

    while (fscanf(config_file, "%s", library_name) > 0) {
        CModule *cmodule;
        struct list *entry;
        OMX_ERRORTYPE ret;

        library_name[OMX_MAX_STRINGNAME_SIZE-1] = '\0';

        /* skip libraries starting with # */
        if (library_name[0] == '#')
            continue;

        cmodule = new CModule(&library_name[0]);
        if (!cmodule)
            continue;

        ALOGI("found component library %s\n", library_name);

        ret = cmodule->Load(MODULE_LAZY);
        if (ret != OMX_ErrorNone)
            goto delete_cmodule;

        ret = cmodule->QueryComponentNameAndRoles();
        if (ret != OMX_ErrorNone)
            goto unload_cmodule;

        entry = list_alloc(cmodule);
        if (!entry)
            goto unload_cmodule;
        head = __list_add_tail(head, entry);

        cmodule->Unload();
        ALOGI("module %s:%s added to component list\n",
             cmodule->GetLibraryName(), cmodule->GetComponentName());

        continue;

    unload_cmodule:
        cmodule->Unload();
    delete_cmodule:
        delete cmodule;
    }

    fclose(config_file);
    return head;
}