当前位置: 首页>>代码示例>>C++>>正文


C++ DynamicLibrary::getSymbol方法代码示例

本文整理汇总了C++中DynamicLibrary::getSymbol方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicLibrary::getSymbol方法的具体用法?C++ DynamicLibrary::getSymbol怎么用?C++ DynamicLibrary::getSymbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DynamicLibrary的用法示例。


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

示例1: loadDynamicPlugins

void PluginManager::loadDynamicPlugins(std::string& plugins_path)
{
    LOG_DEBUG("Loading dynamic plugins");
    Poco::Path plugin_directory = Poco::Path::forDirectory(plugins_path);
    plugin_directory.popDirectory();
    plugin_directory.pushDirectory("plugins");
    LOG_DEBUG("Plugin directory: " << plugin_directory.toString());
    std::set<std::string> dll_files;
    Poco::Glob::glob(plugin_directory.append(DynamicLibrary::DL_PREFIX+
                                             "*."+
                                             DynamicLibrary::DL_SUFFIX), 
                     dll_files);

    for (std::set<std::string>::iterator it = dll_files.begin(); 
         it!=dll_files.end(); 
         ++it)
    {
        std::string plugin_file = *it;
        LOG_DEBUG("Loading library " << plugin_file);
        DynamicLibrary* dl = DynamicLibrary::load(plugin_file);
        registerPluginFunction registerPlugin = 
            (registerPluginFunction)dl->getSymbol("registerPlugin");
        if (registerPlugin)
        {
            LOG_DEBUG("Initialize Plugin " << *it);
            registerPlugin(this);
        } else
        {
            LOG_WARN("Couldn't find registerPlugin for " << *it);
        }
    }

}
开发者ID:Jokymon,项目名称:anthaxia,代码行数:33,代码来源:PluginManager.cpp

示例2: RunTests

void DynamicLibraryTest::RunTests()
{
  DynamicLibrary * d = NULL;

  // Try to load "empty" library
  {
    string errorString;
    d = DynamicLibrary::load("", errorString);
    TEST2("Shouldn't be able to load \"\" library", d == NULL); 
    TEST2("Should have non-empty error string", errorString.size() != 0);
  }
   
  // Try to load non-existent library
  string s("non_exisiting_file");
  Path path(s);
  
  TEST2("Make sure file doesn't exist", !path.exists());
 
  { 
    string errorString;
    d = DynamicLibrary::load(s, errorString);
  }

  TEST2("Shouldn't be able to load non-existent library", d == NULL);
  delete d; // just to satisfy coverity, not really needed, but harmless

  // Try to load corrupt library (this source file)
#ifdef WIN32
  s = "lib\\cpp_region.dll";
  path = getPath(s);
#else
  s = "share/test/data/fake.dynamic.library";
  path = getPath(s);
  TEST2("Make sure \"corrupt\" file exists", path.exists());  

  {
    string errorString;
    d = DynamicLibrary::load(std::string(path), errorString);
  }
  TEST2("Shouldn't be able to load corrupt library", d == NULL);

  // Load good library (very inelegant way to handle different suffix on mac and linux)
  s = "lib/libcpp_region.dylib";
  path = getPath(s);
  if (!path.exists())
  {
    s = "lib/libcpp_region.so";
    path = getPath(s);
  }
#endif

  std::cout << "Looking for path '" << path << "'\n";
  TEST2("Make sure file exists", path.exists());
  {
    string errorString;
    d = DynamicLibrary::load(std::string(path), errorString);
    TEST2("Should be able to load good library", d != NULL);
    TEST2("Should have empty error string", errorString.empty());
    if (!errorString.empty())
    {
      std::cout << "Error String: " << errorString << "\n";
    }
  }
  
  
  if (d) {
    // Get existing symbol
    void * sym = d->getSymbol("NTA_initPython");
    TEST2("Should be able to get 'NTA_initPython' symbol", sym != NULL);
    
    // Get non-existing symbol
    sym = d->getSymbol("non exisitng symbol");
    TEST2("Should NOT be able to get 'non exisitng symbol' symbol", sym == NULL);
    delete d;    
  }
}
开发者ID:DarkyMago,项目名称:nupic,代码行数:76,代码来源:DynamicLibraryTest.cpp

示例3: GenericException

SteerLib::ModuleMetaInformation * SimulationEngine::_loadModule(const std::string & moduleName, const std::string & searchPath)
{
	// check that the requested moduleName is not already "blacklisted" as a conflict from some other loaded module.
	if (_moduleConflicts.find(moduleName) != _moduleConflicts.end()) {
		std::stringstream conflictingNames;
		std::multimap<std::string, std::string>::iterator iter;
		pair< std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator > bounds;
		bounds = _moduleConflicts.equal_range(moduleName);
		for ( iter = bounds.first; iter != bounds.second; ++iter ) {
			conflictingNames << "  " << (*iter).second << "\n";
		}
		throw GenericException("Cannot load module \"" + moduleName + "\", because it conflicts with the following modules:\n" + conflictingNames.str());
	}

	ModuleMetaInformation * newMetaInfo = NULL;
	std::map<std::string, ModuleMetaInformation*>::iterator iter;

	// THREE POSSIBLE STATES OF THE MODULE when we are trying to load it:
	//  1. metaInfo not allocated
	//  2. metaInfo allocated, but module not loaded
	//  3. metaInfo allocated and module loaded.
	iter = _moduleMetaInfoByName.find(moduleName);
	if (iter == _moduleMetaInfoByName.end()) {
		// CASE #1: module was not allocated yet.
		// This is the usual case, and module loading can proceed normally.
		// action: go ahead and allocate it here, and then finish loading it below.
		newMetaInfo = new ModuleMetaInformation;
		newMetaInfo->isLoaded = false;
		newMetaInfo->isInitialized = false;
		// note, this syntax inserts the newMetaInfo when it does not already exist (which is the case here).
		_moduleMetaInfoByName[moduleName] = newMetaInfo;
	}
	else {
		newMetaInfo = ((*iter).second);
		if (!newMetaInfo->isLoaded) {
			// CASE #2: module is allocated, not loaded.
			// That means the module was recursively loading dependencies, and somehow 
			// ended up trying to re-load itself. In other words, it is a cyclic dependency.
			// action: throw an exception.
			/// @todo make a more informative error message here.
			throw GenericException("Detected a cyclic dependency while loading a module.  Please examine a stack trace to see more details.");
		}
		else {
			// CASE #4: module is already loaded.
			// action: just return.
			return newMetaInfo;
		}
	}


	// at this point we are ready to "load" the module.
	// "loading" the module means that we can initialize everything in the ModuleMetaInformation struct
	// and update all the engine's data structures that have knowledge of the module.  Essentially,
	// everything except establishing execution order and calling init().

	ModuleInterface * newModule = NULL;
	DynamicLibrary * newModuleLib = NULL;

	// first, check if the requested module is built-in, and create it if it was built in.
	newModule = _createBuiltInModule(moduleName);

	if (newModule == NULL) {
		// In this case, the module was not built-in.
#ifdef _WIN32
		std::string extension = ".dll";
#else
		std::string extension = ".o";
#endif

		std::string moduleFileName = searchPath + moduleName + extension;
		if (!isExistingFile(moduleFileName)) {
			moduleFileName = _options->engineOptions.moduleSearchPath + moduleName + extension;  // if module wasn't found in the searchPath directory, try with the default search path.
			if (!isExistingFile(moduleFileName)) {
				moduleFileName = moduleName + extension;  // if it still wasnt found, try without the search path
				if (!isExistingFile(moduleFileName)) {
					// if it still didn't work, then cause an error.
					throw GenericException("Could not find the module named \"" + moduleName + "\".\n" +
						"  tried user-specified search path: " + searchPath + moduleName + extension +"\n" +
						"  tried engine's search path: " + _options->engineOptions.moduleSearchPath + moduleName + extension +"\n" +
						"  tried the current directory: " + moduleName + extension +"\n");
				}
			}
		}


		// load the dynamic library
		newModuleLib = new DynamicLibrary(moduleFileName);

		// get the "createModule" function from the dynamic library
		typedef ModuleInterface* (*createModuleFuncPtr)();
		createModuleFuncPtr createModule = (createModuleFuncPtr) newModuleLib->getSymbol("createModule", true);

		// create the module itself
		newModule = createModule();
		if (newModule == NULL) {
			throw GenericException("Could not create module \"" + moduleName + "\", createModule() returned NULL.");
		}
	}


//.........这里部分代码省略.........
开发者ID:CG-F15-12-Rutgers,项目名称:SteerLite,代码行数:101,代码来源:SimulationEngine.cpp


注:本文中的DynamicLibrary::getSymbol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。