• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ dlopen函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中dlopen函数的典型用法代码示例。如果您正苦于以下问题:C++ dlopen函数的具体用法?C++ dlopen怎么用?C++ dlopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了dlopen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: dlopen

ModHandle CModules::OpenModule(const CString& sModule, const CString& sModPath, bool &bVersionMismatch,
		bool &bIsGlobal, CString& sDesc, CString& sRetMsg) {
	// Some sane defaults in case anything errors out below
	bVersionMismatch = false;
	bIsGlobal = false;
	sDesc.clear();
	sRetMsg.clear();

	for (unsigned int a = 0; a < sModule.length(); a++) {
		if (((sModule[a] < '0') || (sModule[a] > '9')) && ((sModule[a] < 'a') || (sModule[a] > 'z')) && ((sModule[a] < 'A') || (sModule[a] > 'Z')) && (sModule[a] != '_')) {
			sRetMsg = "Module names can only contain letters, numbers and underscores, [" + sModule + "] is invalid.";
			return NULL;
		}
	}

#ifndef _WIN32
	// The second argument to dlopen() has a long history. It seems clear
	// that (despite what the man page says) we must include either of
	// RTLD_NOW and RTLD_LAZY and either of RTLD_GLOBAL and RTLD_LOCAL.
	//
	// RTLD_NOW vs. RTLD_LAZY: We use RTLD_NOW to avoid znc dying due to
	// failed symbol lookups later on. Doesn't really seem to have much of a
	// performance impact.
	//
	// RTLD_GLOBAL vs. RTLD_LOCAL: If perl is loaded with RTLD_LOCAL and later on
	// loads own modules (which it apparently does with RTLD_LAZY), we will die in a
	// name lookup since one of perl's symbols isn't found. That's worse
	// than any theoretical issue with RTLD_GLOBAL.
	ModHandle p = dlopen((sModPath).c_str(), RTLD_NOW | RTLD_GLOBAL);
#else
	ModHandle p = dlopen((sModPath).c_str(), RTLD_NOW | RTLD_LOCAL);
#endif

	if (!p) {
		sRetMsg = "Unable to open module [" + sModule + "] [" + dlerror() + "]";
		return NULL;
	}

	typedef double (*dFP)();
	dFP Version = (dFP) dlsym(p, "ZNCModVersion");

	if (!Version) {
		dlclose(p);
		sRetMsg = "Could not find ZNCModVersion() in module [" + sModule + "]";
		return NULL;
	}

	typedef bool (*bFP)();
	bFP IsGlobal = (bFP) dlsym(p, "ZNCModGlobal");

	if (!IsGlobal) {
		dlclose(p);
		sRetMsg = "Could not find ZNCModGlobal() in module [" + sModule + "]";
		return NULL;
	}

	typedef const char *(*sFP)();
	sFP GetDesc = (sFP) dlsym(p, "ZNCModDescription");

	if (!GetDesc) {
		dlclose(p);
		sRetMsg = "Could not find ZNCModDescription() in module [" + sModule + "]";
		return NULL;
	}

	if (CModule::GetCoreVersion() != Version()) {
		bVersionMismatch = true;
#ifndef _WIN32
		sRetMsg = "Version mismatch, recompile this module.";
#else
		sRetMsg = "Module version is '" + CString(Version(), 3) + "', but core expects '" +
			CString(CModule::GetCoreVersion(), 3) + "'. Please re-download/re-install/re-compile the module.";
#endif
	} else {
		sRetMsg = "";
		bVersionMismatch = false;
		bIsGlobal = IsGlobal();
		sDesc = GetDesc();
	}

	return p;
}
开发者ID:BGCX261,项目名称:znc-msvc-svn-to-git,代码行数:82,代码来源:Modules.cpp


示例2: dlopen

CMMBDataSource::CMMBDataSource(int fd)
{
    const char* dlerr;
    //do null
    pVideoFrame = NULL;
    FrameOffset = 0;

    
    libcmmbsp_handle = dlopen("/data/data/com.mediatek.cmmb.app/lib/libcmmbsp.so",RTLD_NOW);                           // dlopen ´ò¿ªso

    dlerr = dlerror();
    if (dlerr != NULL) 
	    LOGE("CMMBDataSource: dlopen() error: %s\n", dlerr);
    if(!libcmmbsp_handle)
    {
	    LOGE("CMMBDataSource dlopen /data/data/com.mediatek.cmmb.app/lib/libcmmbsp fail,then open /system/lib/so");
	    libcmmbsp_handle = dlopen("libcmmbsp.so",RTLD_NOW);
	    if(!libcmmbsp_handle)
	    {
		    LOGE("CMMBDataSource dlopen /system/lib/so fail");
	    }
    }
    if(libcmmbsp_handle){
            LOGI("dlopen success,then dlsym");
	    // get CmmbFreeVideoFrame function point 
	    F_CmmbFreeVideoFrame = (CmmbFreeVideoFrame_T)dlsym(libcmmbsp_handle,"CmmbFreeVideoFrame");    
	    dlerr = dlerror();
	    if (dlerr != NULL){
		    LOGE( "CMMBDataSource::CMMBDataSource CmmbFreeVideoFrame dlsym() error: %s\n", dlerr);
                    F_CmmbFreeVideoFrame=NULL;
	    }
	    // get CmmbReadVideoFrame function point 
	    F_CmmbReadVideoFrame = (CmmbReadVideoFrame_T)dlsym(libcmmbsp_handle,"CmmbReadVideoFrame");    
	    dlerr = dlerror();
	    if (dlerr != NULL){
		    LOGE( "CMMBDataSource::CMMBDataSource CmmbReadVideoFrame dlsym() error: %s\n", dlerr);
                    F_CmmbReadVideoFrame = NULL;
	    }
	    // get CmmbReadAudioFrame function point
	    F_CmmbReadAudioFrame=(CmmbReadAudioFrame_T)dlsym(libcmmbsp_handle,"CmmbReadAudioFrame");    
	    dlerr = dlerror();
	    if (dlerr != NULL){
		    LOGE( "CMMBDataSource::CMMBDataSource CmmbReadAudioFrame dlsym() error: %s\n", dlerr);
                    F_CmmbReadAudioFrame=NULL;
	    }
	    // get CmmbFreeAudioFrame function point 
	    F_CmmbFreeAudioFrame = (CmmbFreeAudioFrame_T)dlsym(libcmmbsp_handle,"CmmbFreeAudioFrame");   
	    dlerr = dlerror();
	    if (dlerr != NULL){
		    LOGE( "CMMBDataSource::CMMBDataSource CmmbFreeAudioFrame dlsym() error: %s\n", dlerr);
                    F_CmmbFreeAudioFrame=NULL;
	    }
	    // get CmmbFlushAVFrame function point 
	    F_CmmbFlushAVFrame = (CmmbFlushAVFrame_T)dlsym(libcmmbsp_handle,"CmmbFlushAVFrame");    
	    dlerr = dlerror();
	    if (dlerr != NULL){
		    LOGE( "CMMBDataSource::CMMBDataSource CmmbFlushAVFrame dlsym() error: %s\n", dlerr);
                    F_CmmbFlushAVFrame =NULL;
	    }
	    // get CmmbGetMetadata function point 
	    F_CmmbGetMetadata = (CmmbGetMetadata_T)dlsym(libcmmbsp_handle,"CmmbGetMetadata");    
	    dlerr = dlerror();
	    if (dlerr != NULL){
		    LOGE( "CMMBDataSource::CMMBDataSource CmmbGetMetadata dlsym() error: %s\n", dlerr);
                    F_CmmbGetMetadata = NULL;
	    }

	    // get CmmbFlushOldestFrame function point 
	    F_CmmbFlushOldestFrame = (CmmbFlushOldestFrame_T)dlsym(libcmmbsp_handle,"CmmbFlushOldestFrame");    
	    dlerr = dlerror();
	    if (dlerr != NULL){
		    LOGE( "CMMBDataSource::CMMBDataSource CmmbFlushOldestFrame dlsym() error: %s\n", dlerr);
                    F_CmmbFlushOldestFrame = NULL;
	    }
    }

    /*release redundancy frame to push forward playback*/
    if(F_CmmbFlushOldestFrame)
    {
	    F_CmmbFlushOldestFrame();
    }
    else
    {
	    LOGE("Error F_CmmbFlushOldestFrame=NULL");
    }
    //test	
 #if 0   
    filesource = new CMMBFileSource;
#endif	
}
开发者ID:AwaisKing,项目名称:mt6577_aosp_source,代码行数:90,代码来源:CMMBDataSource.cpp


示例3: load_dll

static int
load_dll(ClipMachine * mp, const char *name, struct Coll *names, ClipVar * resp)
{
	void *hp;
	char buf[256], *s, *e;
	char uname[128];
	const char **spp;
	ClipModule *entry;
	ClipFunction **fpp;
	ClipNameEntry *np;
	ClipFile **cpp;
	struct DBFuncTable **dpp;
	unsigned l, i;
	int ret = 0;

	s = strrchr(name, '/');
	if (s)
		snprintf(buf, sizeof(buf), "%s", name);
	else
		snprintf(buf, sizeof(buf), "%s/lib/%s", CLIPROOT, name);

	if (!loaded_dlls)
	{
		loaded_dlls = new_Coll(free, strcmp);
	}
	else
	{
		if (search_Coll(loaded_dlls, buf, 0))
			return 0;
	}

	hp = dlopen(buf, RTLD_NOW);
	if (!hp)
	{
		_clip_trap_printf(mp, __FILE__, __LINE__, "shared loading problem: %s: file %s", dlerror(), buf);
		return _clip_call_errblock(mp, 1);
	}

	insert_Coll(loaded_dlls, strdup(buf));

/*
   path/name.ext -> name_module entry symbol
 */

	s = strrchr(name, '/');
	if (!s)
		s = (char *) name;
	else
		s = s + 1;
	e = strchr(s, '.');
	if (e)
		l = e - s;
	else
		l = strlen(s);
	if (l > sizeof(uname))
		l = sizeof(uname);

	for (i = 0; i < l; i++, s++)
	{
		if (*s == '-')
			uname[i] = '_';
		else
			uname[i] = toupper(*s);
	}
	uname[l] = 0;
	snprintf(buf, sizeof(buf), "clip__MODULE_%s", uname);

	entry = (ClipModule *) dlsym(hp, buf);

	if (!entry)
	{
		_clip_trap_printf(mp, __FILE__, __LINE__, "shared '%s' fetch name '%s' problem: %s", name, buf, dlerror());
		return _clip_call_errblock(mp, 1);
	}

	for (np = entry->cfunctions; np && np->f; ++np)
		_clip_register_hash(mp, np->f, np->hash);

	for (fpp = entry->inits; fpp && *fpp; ++fpp)
		_clip_main_func(mp, *fpp, _clip_argc, _clip_argv, _clip_envp);

	for (fpp = entry->exits; fpp && *fpp; ++fpp)
	{
		mp->cexits = realloc(mp->cexits, (mp->ncexits + 1) * sizeof(ClipFunction *));
		mp->cexits[mp->ncexits] = *fpp;
		++mp->ncexits;
	}

	for (spp = entry->pfunctions; spp && *spp; ++spp)
		if (_clip_load(mp, *spp, 0, 0))
			++ret;
/*
	if (entry->cpfile && _clip_register_file(mp, entry->cpfile))
		++ret;
*/
	for (cpp = entry->cpfiles; cpp && *cpp; ++cpp)
		if (_clip_register_file(mp, *cpp))
			++ret;

	for (dpp = entry->dbdrivers; dpp && *dpp; ++dpp)
//.........这里部分代码省略.........
开发者ID:amery,项目名称:clip-itk,代码行数:101,代码来源:clipvm.c


示例4: VID_LoadRefresh

/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh( char *name )
{
	refimport_t	ri;
	GetRefAPI_t	GetRefAPI;
	char	fn[MAX_OSPATH];
	struct stat st;
	extern uid_t saved_euid;
	FILE *fp;
	
	if ( reflib_active )
	{
		if (KBD_Close_fp)
			KBD_Close_fp();
		if (RW_IN_Shutdown_fp)
			RW_IN_Shutdown_fp();
		KBD_Close_fp = NULL;
		RW_IN_Shutdown_fp = NULL;
		re.Shutdown();
		VID_FreeReflib ();
	}

	Com_Printf( "------- Loading %s -------\n", name );

	//regain root
	seteuid(saved_euid);

	if ((fp = fopen(so_file, "r")) == NULL) {
		Com_Printf( "LoadLibrary(\"%s\") failed: can't open %s (required for location of ref libraries)\n", name, so_file);
		return false;
	}
	fgets(fn, sizeof(fn), fp);
	fclose(fp);
	while (*fn && isspace(fn[strlen(fn) - 1]))
		fn[strlen(fn) - 1] = 0;

	strcat(fn, "/");
	strcat(fn, name);

	// permission checking
	if (strstr(fn, "softx") == NULL) { // softx doesn't require root
		if (stat(fn, &st) == -1) {
			Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
			return false;
		}
#if 0
		if (st.st_uid != 0) {
			Com_Printf( "LoadLibrary(\"%s\") failed: ref is not owned by root\n", name);
			return false;
		}
		if ((st.st_mode & 0777) & ~0700) {
			Com_Printf( "LoadLibrary(\"%s\") failed: invalid permissions, must be 700 for security considerations\n", name);
			return false;
		}
#endif
	} else {
		// softx requires we give up root now
		setreuid(getuid(), getuid());
		setegid(getgid());
	}

	if ( ( reflib_library = dlopen( fn, RTLD_LAZY | RTLD_GLOBAL ) ) == 0 )
	{
		Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name , dlerror());
		return false;
	}

  Com_Printf( "LoadLibrary(\"%s\")\n", fn );

	ri.Cmd_AddCommand = Cmd_AddCommand;
	ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
	ri.Cmd_Argc = Cmd_Argc;
	ri.Cmd_Argv = Cmd_Argv;
	ri.Cmd_ExecuteText = Cbuf_ExecuteText;
	ri.Con_Printf = VID_Printf;
	ri.Sys_Error = VID_Error;
	ri.FS_LoadFile = FS_LoadFile;
	ri.FS_FreeFile = FS_FreeFile;
	ri.FS_Gamedir = FS_Gamedir;
	ri.Cvar_Get = Cvar_Get;
	ri.Cvar_Set = Cvar_Set;
	ri.Cvar_SetValue = Cvar_SetValue;
	ri.Vid_GetModeInfo = VID_GetModeInfo;
	ri.Vid_MenuInit = VID_MenuInit;
	ri.Vid_NewWindow = VID_NewWindow;

	if ( ( GetRefAPI = (void *) dlsym( reflib_library, "GetRefAPI" ) ) == 0 )
		Com_Error( ERR_FATAL, "dlsym failed on %s", name );

	re = GetRefAPI( ri );

	if (re.api_version != API_VERSION)
	{
		VID_FreeReflib ();
		Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
	}
//.........这里部分代码省略.........
开发者ID:qbism,项目名称:Quake2-colored-refsoft,代码行数:101,代码来源:vid_so.c


示例5: dlopen

OMX_ERRORTYPE RKOMXPlugin::AddCore(const char* coreName)
{
   bool isRKCore = false;
   if (!strcmp(coreName, "libOMX_Core.so")) {
       isRKCore = true;
   }
   void* libHandle = dlopen(coreName, RTLD_NOW);

   if (libHandle != NULL) {
        RKOMXCore* core = (RKOMXCore*)calloc(1,sizeof(RKOMXCore));

        if (!core) {
            dlclose(libHandle);
            return OMX_ErrorUndefined;
        }
        // set plugin lib handle and methods
        core->mLibHandle = libHandle;
		if (isRKCore) {
            core->mInit = (RKOMXCore::InitFunc)dlsym(libHandle, "RKOMX_Init");
            core->mDeinit = (RKOMXCore::DeinitFunc)dlsym(libHandle, "RKOMX_DeInit");

            core->mComponentNameEnum =
            (RKOMXCore::ComponentNameEnumFunc)dlsym(libHandle, "RKOMX_ComponentNameEnum");

            core->mGetHandle = (RKOMXCore::GetHandleFunc)dlsym(libHandle, "RKOMX_GetHandle");
            core->mFreeHandle = (RKOMXCore::FreeHandleFunc)dlsym(libHandle, "RKOMX_FreeHandle");

            core->mGetRolesOfComponentHandle =
                (RKOMXCore::GetRolesOfComponentFunc)dlsym(
                        libHandle, "RKOMX_GetRolesOfComponent");

		} else {
            core->mInit = (RKOMXCore::InitFunc)dlsym(libHandle, "OMX_Init");
            core->mDeinit = (RKOMXCore::DeinitFunc)dlsym(libHandle, "OMX_Deinit");

            core->mComponentNameEnum =
            (RKOMXCore::ComponentNameEnumFunc)dlsym(libHandle, "OMX_ComponentNameEnum");

            core->mGetHandle = (RKOMXCore::GetHandleFunc)dlsym(libHandle, "OMX_GetHandle");
            core->mFreeHandle = (RKOMXCore::FreeHandleFunc)dlsym(libHandle, "OMX_FreeHandle");

            core->mGetRolesOfComponentHandle =
                (RKOMXCore::GetRolesOfComponentFunc)dlsym(
                        libHandle, "OMX_GetRolesOfComponent");
		}
        if (core->mInit != NULL) {
            (*(core->mInit))();
        }
        if (core->mComponentNameEnum != NULL) {
            // calculating number of components registered inside given OMX core
            char tmpComponentName[OMX_MAX_STRINGNAME_SIZE] = { 0 };
            OMX_U32 tmpIndex = 0;
            while (OMX_ErrorNone == ((*(core->mComponentNameEnum))(tmpComponentName, OMX_MAX_STRINGNAME_SIZE, tmpIndex))) {
                tmpIndex++;
            ALOGI("OMX IL core %s: declares component %s", coreName, tmpComponentName);
            }
            core->mNumComponents = tmpIndex;
            ALOGI("OMX IL core %s: contains %ld components", coreName, core->mNumComponents);
        }
        // add plugin to the vector
        mCores.push_back(core);
    }
    else {
        ALOGW("OMX IL core %s not found", coreName);
        return OMX_ErrorUndefined; // Do we need to return error message
    }
    return OMX_ErrorNone;
}
开发者ID:denisigo,项目名称:fireprime_hardware_rockchip,代码行数:68,代码来源:RKOMXPlugin.cpp


示例6: ifm_process_unregister_notify

s32 ifm_process_unregister_notify(const s8 * ifname, s32 ifindex)
{
	void *handle;
	s32 (* subif_del_handle)(const s8 *);
	s8 *error;	
    s32 ret = ERROR_SUCCESS;
	struct if_stat *ifstat=NULL;
	ifstat=if_stat_list;
    sqlite3 *db= NULL;
	sqlite3_res res=NULL;
	s8 sqlite_sql_buf[SQLITE_SQL_BUF_SIZE];
	s32 count=0;
    while(ifstat!=NULL)
    {
        if((strcmp(ifstat->name,ifname) == 0)&&(ifstat->use_flag==IFMD_INFO_USE))
        {   
            
            ifstat->use_flag=IFMD_INFO_UN_USE;
			syslogex_syslog_send("ifmd",LOG_NOTICE|LOG_DAEMON,"Interface %s is unregister\n",ifstat->name);
			break;
		}
		else
		{
			ifstat = ifstat->next;
		}
	} 
	if((strncmp(ifname,"eth",3)==0)&&(strchr(ifname,'.') != NULL))
	{
		
		handle = dlopen("/usr/lib/liblogicinterface.so", RTLD_LAZY);
		if(handle)
		{
			return ERROR_SUCCESS;
		}
		dlerror();
		
		subif_del_handle = dlsym(handle, "subInterface_db_delete");
		if ((error = dlerror()) != NULL)  
		{
			return ERROR_SYSTEM;
		}		
		if(ERROR_SUCCESS != if_get_index_by_name(ifname, &ifindex))
		{
			return ERROR_SYSTEM;
		}
		db = sqlite3_open_ex(1,IFMODE_DB);
		if(NULL == db)
		{
			dlclose(handle);
			return ERROR_SYSTEM;
		}
		snprintf(sqlite_sql_buf, SQLITE_SQL_BUF_SIZE,
                "select count(ifindex) as count from (select l3.ifindex from tb_port_l3 as l3 where l3.ifindex = '%d' union all select l2.ifindex from tb_port_l2 as l2 where l2.ifindex = '%d');", ifindex, ifindex);
		 

		 
		ret = sqlite3_exec_query_ex (db, sqlite_sql_buf, &res);
		if (SQLITE_OK != ret)
		{
			sqlite3_close_ex(db);
			dlclose(handle);
			return VLAN_DB_OPT_UNSUCCESS;
		}
		ret = sqlite3_get_u32_ex (res, 0, "count", (u32*) &count);
		if (SQLITE_OK != ret)
		{
			count = VLAN_DB_OPT_UNSUCCESS;	
		}
		sqlite3_res_free_ex(res);
		res = NULL;
		sqlite3_close_ex(db);
		 
		if(count>0)
		{   
			ret = subif_del_handle(ifname);
			if(ret!=ERROR_SUCCESS)
			{
				dlclose(handle);
			    return ret;
			}
		}
		else
		{   
			dlclose(handle);
			return ret;
		}
		
	}
    return ret;
}
开发者ID:millken,项目名称:zhuxianB30,代码行数:90,代码来源:ifmd.c


示例7: logstream

  std::string unity_global::load_toolkit(std::string soname,
                                         std::string module_subpath) {
    // rewrite "local" protocol
    std::string protocol = fileio::get_protocol(soname);
    if (protocol == "local") {
      soname = fileio::remove_protocol(soname);
    }

    so_registration_list regentry;
    regentry.original_soname = soname;
    logstream(LOG_INFO) << "Attempt loading of " << sanitize_url(soname) << std::endl;

    // see if the file exists and whether we need to donwnload it
    if (fileio::try_to_open_file(soname) == false) {
      return "Unable to open file " + sanitize_url(soname);
    }

    if (protocol != "") {
      // there is a protocol associated. We need to copy this file to local
      // issue a copy to copy it to the local temp directory
      std::string tempname = get_temp_name();
      fileio::copy(soname, tempname);
      soname = tempname;
    }
    if (!file_contains_substring(soname, "get_toolkit_function_registration") &&
        !file_contains_substring(soname, "get_toolkit_class_registration")) {
      return soname + " is not a valid extension";
    }



    // get the base name of the shared library (without the .so)
    std::string modulename = fileio::get_filename(regentry.original_soname);
    std::vector<std::string> split_names;
    boost::algorithm::split(split_names, modulename, boost::is_any_of("."));
    if (split_names.size() == 0) return "Invalid filename";
    if (module_subpath.empty()) {
      regentry.modulename = split_names[0];
    } else if (module_subpath == "..") {
      regentry.modulename = "";
    } else {
      regentry.modulename = module_subpath + "." + split_names[0];
    }

    // goody. now for the dl loading
#ifndef _WIN32
    void* dl = dlopen(soname.c_str(), RTLD_NOW | RTLD_LOCAL);
#else
    void *dl = (void *)LoadLibrary(soname.c_str());
#endif
    logstream(LOG_INFO) << "Library load of " << sanitize_url(soname) << std::endl;
    regentry.effective_soname = soname;
    regentry.dl = dl;
    // check for failure
    if (dl == NULL) {
#ifndef _WIN32
      char* err = dlerror();
      // I think we need to copy this out early
      std::string ret = err;
      logstream(LOG_ERROR) << "Unable to load " << sanitize_url(soname) << ": " << ret << std::endl;
      if (err) return ret;
      else return "dlopen failed due to an unknown error";
#else
      std::string ret = get_last_err_str(GetLastError());
      logstream(LOG_ERROR) << "Unable to load " << sanitize_url(soname) << ": " << ret << std::endl;
      if (!ret.empty()) return ret;
      else return "LoadLibrary failed due to an unknown error";
#endif
    }

  /**************************************************************************/
  /*                                                                        */
  /*                         Function Registration                          */
  /*                                                                        */
  /**************************************************************************/
    // get the registration symbols
    std::vector<std::string> toolkit_function_reg_names
                {"get_toolkit_function_registration",
                  "_Z33get_toolkit_function_registrationv",
                  "__Z33get_toolkit_function_registrationv"};

    get_toolkit_function_registration_type get_toolkit_function_registration = nullptr;
    for (auto reg_name : toolkit_function_reg_names) {
      get_toolkit_function_registration =
          reinterpret_cast<get_toolkit_function_registration_type>
          (
#ifndef _WIN32
           dlsym(dl, reg_name.c_str())
#else
           (void *)GetProcAddress((HMODULE)dl, reg_name.c_str())
#endif
           );
      if (get_toolkit_function_registration != nullptr) break;
    }

    // register functions
    if (get_toolkit_function_registration) {
      auto functions = (*get_toolkit_function_registration)();
      for (auto& fn: functions) {
        if (!regentry.modulename.empty()) {
//.........这里部分代码省略.........
开发者ID:FLMao,项目名称:SFrame,代码行数:101,代码来源:unity_global.cpp


示例8: uv__set_process_title

int uv__set_process_title(const char* title) {
#if TARGET_OS_IPHONE
  return uv__pthread_setname_np(title);
#else
  CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
                                            const char*,
                                            CFStringEncoding);
  CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef);
  void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef);
  void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef);
  CFTypeRef (*pLSGetCurrentApplicationASN)(void);
  OSStatus (*pLSSetApplicationInformationItem)(int,
                                               CFTypeRef,
                                               CFStringRef,
                                               CFStringRef,
                                               CFDictionaryRef*);
  void* application_services_handle;
  void* core_foundation_handle;
  CFBundleRef launch_services_bundle;
  CFStringRef* display_name_key;
  CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef);
  CFBundleRef (*pCFBundleGetMainBundle)(void);
  CFBundleRef hi_services_bundle;
  OSStatus (*pSetApplicationIsDaemon)(int);
  CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef);
  void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t,
                                                                void*);
  CFTypeRef asn;
  int err;

  err = UV_ENOENT;
  application_services_handle = dlopen("/System/Library/Frameworks/"
                                       "ApplicationServices.framework/"
                                       "Versions/A/ApplicationServices",
                                       RTLD_LAZY | RTLD_LOCAL);
  core_foundation_handle = dlopen("/System/Library/Frameworks/"
                                  "CoreFoundation.framework/"
                                  "Versions/A/CoreFoundation",
                                  RTLD_LAZY | RTLD_LOCAL);

  if (application_services_handle == NULL || core_foundation_handle == NULL)
    goto out;

  *(void **)(&pCFStringCreateWithCString) =
      dlsym(core_foundation_handle, "CFStringCreateWithCString");
  *(void **)(&pCFBundleGetBundleWithIdentifier) =
      dlsym(core_foundation_handle, "CFBundleGetBundleWithIdentifier");
  *(void **)(&pCFBundleGetDataPointerForName) =
      dlsym(core_foundation_handle, "CFBundleGetDataPointerForName");
  *(void **)(&pCFBundleGetFunctionPointerForName) =
      dlsym(core_foundation_handle, "CFBundleGetFunctionPointerForName");

  if (pCFStringCreateWithCString == NULL ||
      pCFBundleGetBundleWithIdentifier == NULL ||
      pCFBundleGetDataPointerForName == NULL ||
      pCFBundleGetFunctionPointerForName == NULL) {
    goto out;
  }

#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)

  launch_services_bundle =
      pCFBundleGetBundleWithIdentifier(S("com.apple.LaunchServices"));

  if (launch_services_bundle == NULL)
    goto out;

  *(void **)(&pLSGetCurrentApplicationASN) =
      pCFBundleGetFunctionPointerForName(launch_services_bundle,
                                         S("_LSGetCurrentApplicationASN"));

  if (pLSGetCurrentApplicationASN == NULL)
    goto out;

  *(void **)(&pLSSetApplicationInformationItem) =
      pCFBundleGetFunctionPointerForName(launch_services_bundle,
                                         S("_LSSetApplicationInformationItem"));

  if (pLSSetApplicationInformationItem == NULL)
    goto out;

  display_name_key = pCFBundleGetDataPointerForName(launch_services_bundle,
                                                    S("_kLSDisplayNameKey"));

  if (display_name_key == NULL || *display_name_key == NULL)
    goto out;

  *(void **)(&pCFBundleGetInfoDictionary) = dlsym(core_foundation_handle,
                                     "CFBundleGetInfoDictionary");
  *(void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle,
                                 "CFBundleGetMainBundle");
  if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL)
    goto out;

  /* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */
  hi_services_bundle =
      pCFBundleGetBundleWithIdentifier(S("com.apple.HIServices"));
  err = UV_ENOENT;
  if (hi_services_bundle == NULL)
    goto out;
//.........这里部分代码省略.........
开发者ID:hpcc-systems,项目名称:libuv,代码行数:101,代码来源:darwin-proctitle.c


示例9: plugin_load_from_file

plugin_err_t
plugin_load_from_file(plugin_handle_t *p, const char *fq_path)
{
	plugin_handle_t plug;
	int (*init)(void);
	uint32_t *version;
	char *type = NULL;

	*p = PLUGIN_INVALID_HANDLE;

	/*
	 *  Check for file existence and access permissions
	 */
	if (access(fq_path, R_OK) < 0) {
		if (errno == ENOENT)
			return EPLUGIN_NOTFOUND;
		else
			return EPLUGIN_ACCESS_ERROR;
	}

	/*
	 * Try to open the shared object.
	 *
	 * Use RTLD_LAZY to allow plugins to use symbols that may be
	 * defined in only one slurm entity (e.g. srun and not slurmd),
	 * when the use of that symbol is restricted to within the
	 * entity from which it is available. (i.e. srun symbols are only
	 * used in the context of srun, not slurmd.)
	 *
	 */
	plug = dlopen(fq_path, RTLD_LAZY);
	if (plug == NULL) {
		error("plugin_load_from_file: dlopen(%s): %s",
		      fq_path,
		      _dlerror());
		return EPLUGIN_DLOPEN_FAILED;
	}

	/* Now see if our required symbols are defined. */
	if ((dlsym(plug, PLUGIN_NAME) == NULL) ||
	    ((type = dlsym(plug, PLUGIN_TYPE)) == NULL)) {
		dlclose(plug);
		return EPLUGIN_MISSING_NAME;
	}

	version = (uint32_t *) dlsym(plug, PLUGIN_VERSION);
	if (!version) {
		verbose("%s: plugin_version symbol not defined", fq_path);
	} else if ((*version != SLURM_VERSION_NUMBER) && xstrcmp(type,"spank")){
		/* NOTE: We could alternatly test just the MAJOR.MINOR values */
		int plugin_major, plugin_minor, plugin_micro;
		plugin_major = SLURM_VERSION_MAJOR(*version);
		plugin_minor = SLURM_VERSION_MINOR(*version);
		plugin_micro = SLURM_VERSION_MICRO(*version);
		dlclose(plug);
		info("%s: Incompatible Slurm plugin version (%d.%d.%d)",
		     fq_path, plugin_major, plugin_minor, plugin_micro);
		return EPLUGIN_BAD_VERSION;
	}

	/*
	 * Now call its init() function, if present.  If the function
	 * returns nonzero, unload the plugin and signal an error.
	 */
	if ((init = dlsym(plug, "init")) != NULL) {
		if ((*init)() != 0) {
			dlclose(plug);
			return EPLUGIN_INIT_FAILED;
		}
	}

	*p = plug;
	return EPLUGIN_SUCCESS;
}
开发者ID:artpol84,项目名称:slurm,代码行数:74,代码来源:plugin.c


示例10: linuxModInfoDir

/*
 * Function
 *	linuxModInfoDir
 *
 * Description
 *	Retrieve info about the modules whose shared library files are contained in a given directory
 *	(for each shared library, load it, retrieve info about the module (tModInfo struct),
 *	 and finally unload the library).
 *
 * Parameters
 *	dir	(in)     directory to search (relative)
 *	level   (in)     if 1, load any shared library contained in the subdirs of dir
 *	                 and whose name is the same as the containing subdir (ex: bt/bt.so)
 *	                 if 0, load any shared library contained in dir (ignore subdirs)
 *	modlist	(in/out) list of module description structure (may begin empty)
 *
 * Return
 *	>=0	number of modules loaded
 *	-1	error
 *
 * Remarks
 *	The loaded module info structures are added in the list according to each module's priority
 *	(NOT at the head of the list).
 *	
 */
static int
linuxModInfoDir(unsigned int /* gfid */, const char *dir, int level, tModList **modlist)
{
	char		 sopath[256];	/* path of the lib[x].so */
	tSOHandle		 handle;
	DIR			*dp;
	struct dirent	*ep;
	int			 modnb;		/* number on loaded modules */
	tModList		*curMod;
	
	modnb = 0;
	
	/* open the current directory */
	dp = opendir(dir);
	if (dp)
	{
		/* some files in it */
		while ((ep = readdir (dp)) != 0) 
		{
			if (((strlen(ep->d_name) > 4) && 
				 (strcmp(".so", ep->d_name+strlen(ep->d_name)-3) == 0)) /* xxxx.so */
				|| ((level == 1) && (ep->d_name[0] != '.')))
			{
				if (level == 1)
					sprintf(sopath, "%s/%s/%s.so", dir, ep->d_name, ep->d_name);
				else
					sprintf(sopath, "%s/%s", dir, ep->d_name);
				
				/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
				if (!GfModIsInList(sopath, *modlist))
				{
					/* Load the shared library */
					GfLogTrace("Querying module %s\n", sopath);
					handle = dlopen(sopath, RTLD_LAZY);
					if (handle)
					{
						/* Initialize the module */
						if (GfModInitialize(handle, sopath, GfIdAny, &curMod) == 0)
						{
							if (curMod) /* Retained against gfid */
							{
								/* Get associated info */
								modnb++;
								GfModAddInList(curMod, modlist, /* priosort */ 1);
							}
							
							/* Terminate the module */
							GfModTerminate(handle, sopath);
						}
						
						/* Close the shared library */
						dlclose(handle);
					} 
					else 
					{
						GfLogError("linuxModInfoDir: ...  %s\n", dlerror());
					}
				}
			}
		}
		(void)closedir(dp);
	} 
	else 
	{
		GfLogError("linuxModInfoDir: ... Couldn't open the directory %s.\n", dir);
		return -1;
	}
	
	return modnb;
}
开发者ID:702nADOS,项目名称:speed-dreams,代码行数:95,代码来源:linuxspec.cpp


示例11: int


//.........这里部分代码省略.........

		buffer_copy_buffer(srv->tmp_buf, srv->srvconf.modules_dir);

		buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("/"));
		buffer_append_string(srv->tmp_buf, module);
#if defined(__WIN32) || defined(__CYGWIN__)
		buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN(".dll"));
#else
		buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN(".so"));
#endif

		p = plugin_init();
#ifdef __WIN32
		if (NULL == (p->lib = LoadLibrary(srv->tmp_buf->ptr))) {
			LPVOID lpMsgBuf;
			FormatMessage(
				FORMAT_MESSAGE_ALLOCATE_BUFFER |
					FORMAT_MESSAGE_FROM_SYSTEM,
				NULL,
				GetLastError(),
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				(LPTSTR) &lpMsgBuf,
				0, NULL);

			log_error_write(srv, __FILE__, __LINE__, "ssb", "LoadLibrary() failed",
				lpMsgBuf, srv->tmp_buf);

			plugin_free(p);

			return -1;

		}
#else
		if (NULL == (p->lib = dlopen(srv->tmp_buf->ptr, RTLD_NOW|RTLD_GLOBAL))) {
			log_error_write(srv, __FILE__, __LINE__, "sbs", "dlopen() failed for:",
				srv->tmp_buf, dlerror());

			plugin_free(p);

			return -1;
		}

#endif
		buffer_reset(srv->tmp_buf);
		buffer_copy_string(srv->tmp_buf, module);
		buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("_plugin_init"));

#ifdef __WIN32
		init = GetProcAddress(p->lib, srv->tmp_buf->ptr);

		if (init == NULL) {
			LPVOID lpMsgBuf;
			FormatMessage(
				FORMAT_MESSAGE_ALLOCATE_BUFFER |
					FORMAT_MESSAGE_FROM_SYSTEM,
				NULL,
				GetLastError(),
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				(LPTSTR) &lpMsgBuf,
				0, NULL);

			log_error_write(srv, __FILE__, __LINE__, "sbs", "getprocaddress failed:", srv->tmp_buf, lpMsgBuf);

			plugin_free(p);
			return -1;
		}
开发者ID:HiWong,项目名称:lighttpd1.4,代码行数:67,代码来源:plugin.c


示例12: LoadSharedLibrary

/**************************************************************************
 * Name: LoadSharedLibrary
 *
 * Description: Load the library 
 *
 * Inputs:  library name
 *
 * Outputs: pointer to library loaded
 *
 * Returns:	SUUCESS/FAILURE
 ************************************************************************* */
int LoadSharedLibrary(const char* libName, void** libPointer, char* errstr)
{
  char fullLibName[50];
  char errormessage[200]; 
  int flags;
  int ret;
     
  ret = SUCCESS;
  fullLibName[0] = '\0';
  
  #if defined(WIN32) 
    sprintf(fullLibName, "%s.dll", libName);
  #else
    sprintf(fullLibName, "lib%s", libName);
  #endif
      
  #ifndef WIN32
  #if defined(SOLARIS) || defined(OSF1) || defined(_AIX) || defined(LINUX)
     strcat(fullLibName, ".so");
  #elif defined(HPUX)
     strcat(fullLibName, ".sl");
  #endif
  #endif
      
  strcpy(errormessage, "Loading ");
  strcat(errormessage, fullLibName);
  strcat(errormessage, " library FAILED ...");
   
  /* Load the library */
#if defined(WIN32)
  *libPointer = LoadLibrary(fullLibName);
  if (NULL == *libPointer)
    {
      strcpy(errstr, errormessage);
      /* emit(SHLIB_ERRLOC, MPS_GENERIC_DEBUG, errormessage); */
      return FAILURE;
    }
#elif defined(SOLARIS) || defined(OSF1) || defined(HPUX_64) || defined(_AIX) || defined(LINUX)
  *libPointer = dlopen( fullLibName, OPEN_MODE);
  if (NULL == *libPointer)
    {
      strcpy(errstr, errormessage);
      /* emit(SHLIB_ERRLOC, MPS_GENERIC_DEBUG, errormessage); */
      return FAILURE;
    }
#elif defined(HPUX)
  flags = OPEN_MODE;
  flags |= BIND_DEFERRED;
  *libPointer = shl_load( fullLibName, flags, 0L);
  if (NULL == *libPointer)
    {
      strcpy(errstr, errormessage);
      /* emit(SHLIB_ERRLOC, MPS_GENERIC_DEBUG, errormessage);  */
      return FAILURE;
    }
#else
#error SendToTHSlibLoader not defined for this platform you must define it now Load
#endif
    
  return ret;
  
}  
开发者ID:huilang22,项目名称:Projects,代码行数:73,代码来源:shlib_loader.c


示例13: scanForDevices

    //==============================================================================
    void scanForDevices()
    {
        hasScanned = true;
        inputNames.clear();
        inputIds.clear();
        outputNames.clear();
        outputIds.clear();

        if (juce_libjackHandle == nullptr)
        {
            juce_libjackHandle = dlopen ("libjack.so", RTLD_LAZY);

            if (juce_libjackHandle == nullptr)
                return;
        }

        // open a dummy client
        jack_status_t status;
        jack_client_t* client = juce::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);

        if (client == nullptr)
        {
            dumpJackErrorMessage (status);
        }
        else
        {
            // scan for output devices
            const char** ports = juce::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);

            if (ports != nullptr)
            {
                int j = 0;
                while (ports[j] != 0)
                {
                    String clientName (ports[j]);
                    clientName = clientName.upToFirstOccurrenceOf (":", false, false);

                    if (clientName != String (JUCE_JACK_CLIENT_NAME)
                         && ! inputNames.contains (clientName))
                    {
                        inputNames.add (clientName);
                        inputIds.add (ports [j]);
                    }

                    ++j;
                }

                free (ports);
            }

            // scan for input devices
            ports = juce::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);

            if (ports != nullptr)
            {
                int j = 0;
                while (ports[j] != 0)
                {
                    String clientName (ports[j]);
                    clientName = clientName.upToFirstOccurrenceOf (":", false, false);

                    if (clientName != String (JUCE_JACK_CLIENT_NAME)
                         && ! outputNames.contains (clientName))
                    {
                        outputNames.add (clientName);
                        outputIds.add (ports [j]);
                    }

                    ++j;
                }

                free (ports);
            }

            juce::jack_client_close (client);
        }
    }
开发者ID:0x4d52,项目名称:ugen,代码行数:78,代码来源:juce_linux_JackAudio.cpp


示例14: load_opus

int load_opus(char *name){
  void *lib;
  const char *msg;
  int *num=NULL;
  struct coreInfo_t **core;
  SPICEdev **devs;
  Evt_Udn_Info_t  **udns;
  funptr_t fetch;

  lib = dlopen(name,RTLD_NOW);
  if(!lib){
    msg = dlerror();
    printf("%s\n", msg);
    return 1;
  }
  
  fetch = dlsym(lib,"CMdevNum");
  if(fetch){
    num = ((int * (*)(void)) fetch) ();
#ifdef TRACE
    printf("Got %u devices.\n",*num);
#endif
  }else{
    msg = dlerror();
    printf("%s\n", msg);
    return 1;
  }

  fetch = dlsym(lib,"CMdevs");
  if(fetch){
    devs = ((SPICEdev ** (*)(void)) fetch) ();
  }else{
    msg = dlerror();
    printf("%s\n", msg);
    return 1;
  }

  fetch = dlsym(lib,"CMgetCoreItfPtr");
  if(fetch){
    core = ((struct coreInfo_t ** (*)(void)) fetch) ();
    *core = &coreInfo;
  }else{
    msg = dlerror();
    printf("%s\n", msg);
    return 1;
  }
  add_device(*num,devs,1);

  fetch = dlsym(lib,"CMudnNum");
  if(fetch){
    num = ((int * (*)(void)) fetch) ();
#ifdef TRACE
    printf("Got %u udns.\n",*num);
#endif
  }else{
    msg = dlerror();
    printf("%s\n", msg);
    return 1;
  }

  fetch = dlsym(lib,"CMudns");
  if(fetch){
    udns = ((Evt_Udn_Info_t  ** (*)(void)) fetch) ();
  }else{
    msg = dlerror();
    printf("%s\n", msg);
    return 1;
  }

  add_udn(*num,udns);

  return 0;
}
开发者ID:amarnathmhn,项目名称:ngspice,代码行数:73,代码来源:dev.c


示例15: openUdfLibrary

 void UdfHandler::openUdfLibrary(const std::string & s)
 {
   this->M_lib_handle=dlopen(s.c_str(),RTLD_LAZY);
   if (!this->M_lib_handle)
     throw std::invalid_argument("Udf library " + s + " not found");
 }
开发者ID:10341074,项目名称:pacs,代码行数:6,代码来源:udfHandler.cpp


示例16: dlopen

static void *ll_load (lua_State *L, const char *path) {
  void *lib = dlopen(path, RTLD_NOW);
  if (lib == NULL) lua_pushstring(L, dlerror());
  return lib;
}
开发者ID:aronarts,项目名称:FireNET,代码行数:5,代码来源:loadlib.c


示例17: scope

void context::load_module(v8::FunctionCallbackInfo<v8::Value> const& args)
{
	v8::Isolate* isolate = args.GetIsolate();

	v8::EscapableHandleScope scope(isolate);
	v8::Local<v8::Value> result;
	try
	{
		std::string const name = from_v8<std::string>(isolate, args[0], "");
		if (name.empty())
		{
			throw std::runtime_error("load_module: require module name string argument");
		}

		context* ctx = detail::get_external_data<context*>(args.Data());
		context::dynamic_modules::iterator it = ctx->modules_.find(name);

		// check if module is already loaded
		if (it != ctx->modules_.end())
		{
			result = v8::Local<v8::Value>::New(isolate, it->second.exports);
		}
		else
		{
			std::string filename = name;
			if (!ctx->lib_path_.empty())
			{
				filename = ctx->lib_path_ + path_sep + name;
			}
			std::string const suffix = V8PP_PLUGIN_SUFFIX;
			if (filename.size() >= suffix.size()
				&& filename.compare(filename.size() - suffix.size(), suffix.size(), suffix) != 0)
			{
				filename += suffix;
			}

			dynamic_module module;
#if defined(WIN32)
			UINT const prev_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX);
			module.handle = LoadLibraryA(filename.c_str());
			::SetErrorMode(prev_error_mode);
#else
			module.handle = dlopen(filename.c_str(), RTLD_LAZY);
#endif

			if (!module.handle)
			{
				throw std::runtime_error("load_module(" + name + "): could not load shared library " + filename);
			}
#if defined(WIN32)
			void *sym = ::GetProcAddress((HMODULE)module.handle, STRINGIZE(V8PP_PLUGIN_INIT_PROC_NAME));
#else
			void *sym = dlsym(module.handle, STRINGIZE(V8PP_PLUGIN_INIT_PROC_NAME));
#endif
			if (!sym)
			{
				throw std::runtime_error("load_module(" + name + "): initialization function "
					STRINGIZE(V8PP_PLUGIN_INIT_PROC_NAME) " not found in " + filename);
			}

			using module_init_proc = v8::Handle<v8::Value>(*)(v8::Isolate*);
			module_init_proc init_proc = reinterpret_cast<module_init_proc>(sym);
			result = init_proc(isolate);
			module.exports.Reset(isolate, result);
			ctx->modu 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ dlsym函数代码示例发布时间:2022-05-30
下一篇:
C++ dlist_remove函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap