Пример #1
0
bool InputInterface::configureModules(std::vector<ModulesConfigData>& modulesConfigurations) {

	std::vector<ModulesConfigData>::iterator it;
	ModuleInterface* module;
	bool success = true;

	for (it = modulesConfigurations.begin(); it != modulesConfigurations.end(); ++it) {
		ModulesConfigData& data = *it;
		module = getModuleByName(data.moduleName);
		if (module) {
			for (std::vector<moduleInitCallback>::iterator it1 =
					moduleInitCallbacks.begin(); it1 != moduleInitCallbacks.end(); ++it1) {
				(*it1)(module);
			} // for
			if (!module->loadConfig(data.moduleConfigPath)) {
				printd(ERROR, "InputInterface::configureModules(): failed to load config for module %s!\n", module->getName().c_str());
				success = false;
			} // if
		} // if
		else {
			printd(ERROR, "InputInterface::configureModules(): could not configure Module %s!\n", data.moduleName.c_str());
			success = false;
		} // if
	} // for

	return success;
} // configureModules
Пример #2
0
void ModuleManager::FindAllPlugins(PluginIDList & providers, wxArrayString & paths)
{
   PluginManager & pm = PluginManager::Get();

   wxArrayString modIDs;
   wxArrayString modPaths;
   const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeModule);
   while (plug)
   {
      modIDs.push_back(plug->GetID());
      modPaths.push_back(plug->GetPath());
      plug = pm.GetNextPlugin(PluginTypeModule);
   }

   for (size_t i = 0, cnt = modIDs.size(); i < cnt; i++)
   {
      PluginID providerID = modIDs[i];

      ModuleInterface *module =
         static_cast<ModuleInterface *>(CreateProviderInstance(providerID, modPaths[i]));
      
      wxArrayString newpaths = module->FindPlugins(pm);
      for (size_t i = 0, cnt = newpaths.size(); i < cnt; i++)
      {
         providers.push_back(providerID);
         paths.push_back(newpaths[i]);
      }
   }
}
Пример #3
0
ModuleInterface *ModuleManager::LoadModule(const wxString & path)
{
   wxDynamicLibrary *lib = new wxDynamicLibrary();

   if (lib->Load(path, wxDL_NOW))
   {
      bool success = false;
      ModuleMain audacityMain = (ModuleMain) lib->GetSymbol(wxSTRINGIZE_T(MODULE_ENTRY),
                                                            &success);
      if (success && audacityMain)
      {
         ModuleInterface *module = audacityMain(this, &path);
         if (module)
         {
            if (module->Initialize())
            {

               mDynModules[PluginManager::GetID(module)] = module;
               mLibs[module] = lib;

               return module;
            }
            module->Terminate();
            delete module;
         }
      }

      lib->Unload();
   }

   delete lib;

   return NULL;
}
Пример #4
0
void ModuleManager::InitializeBuiltins()
{
   PluginManager & pm = PluginManager::Get();

   for (auto moduleMain : builtinModuleList())
   {
      ModuleInterfaceHandle module {
         moduleMain(this, NULL), ModuleInterfaceDeleter{}
      };

      if (module->Initialize())
      {
         // Register the provider
         ModuleInterface *pInterface = module.get();
         const PluginID & id = pm.RegisterPlugin(pInterface);

         // Need to remember it 
         mDynModules[id] = std::move(module);

         // Allow the module to auto-register children
         pInterface->AutoRegisterPlugins(pm);
      }
      else
      {
         // Don't leak!  Destructor of module does that.
      }
   }
}
Пример #5
0
bool ModuleManager::DiscoverProviders()
{
   InitializeBuiltins();

   wxArrayString provList;
   wxArrayString pathList;

   // Code from LoadLadspa that might be useful in load modules.
   wxString pathVar = wxString::FromUTF8(getenv("AUDACITY_MODULES_PATH"));

   if (pathVar != wxT(""))
   {
      wxGetApp().AddMultiPathsToPathList(pathVar, pathList);
   }
   else
   {
      wxGetApp().AddUniquePathToPathList(FileNames::ModulesDir(), pathList);
   }

#if defined(__WXMSW__)
   wxGetApp().FindFilesInPathList(wxT("*.dll"), pathList, provList);
#elif defined(__WXMAC__)
   wxGetApp().FindFilesInPathList(wxT("*.dylib"), pathList, provList);
#else
   wxGetApp().FindFilesInPathList(wxT("*.so"), pathList, provList);
#endif

   PluginManager & pm = PluginManager::Get();

   for (int i = 0, cnt = provList.GetCount(); i < cnt; i++)
   {
      ModuleInterface *module = LoadModule(provList[i]);
      if (module)
      {
         // Register the provider
         pm.RegisterPlugin(module);

         // Now, allow the module to auto-register children
         module->AutoRegisterPlugins(pm);
      }
   }

   return true;
}
Пример #6
0
void ModuleManager::InitializeBuiltins()
{
   PluginManager & pm = PluginManager::Get();

   for (size_t i = 0, cnt = pBuiltinModuleList->GetCount(); i < cnt; i++)
   {
      ModuleInterface *module = ((ModuleMain) (*pBuiltinModuleList)[i])(this, NULL);

      if (module->Initialize())
      {
         // Register the provider
         const PluginID & id = pm.RegisterPlugin(module);

         // Need to remember it 
         mDynModules[id] = module;

         // Allow the module to auto-register children
         module->AutoRegisterPlugins(pm);
      }
   }
}
Пример #7
0
bool tweakbukconv::LoadModule(std::string modulename)
{
    bool loaded = false;
    for (unsigned int i = 0; i < modulelist.size(); i++)
    {
        if (modulelist[i] == modulename)
        {
            loaded = true;
        }
    }
    if (!loaded)
    {
        ModuleInterface* mi;
        void* module;
        create_tmi* create_module;
        destroy_tmi* destroy_module;
        std::string modulepath = "./" + moduledir + modulename + ".so";
        // load the library
        module = dlopen(modulepath.c_str(), RTLD_LAZY);
        if (!module) {
            std::cerr << "Cannot load library: " << dlerror() << '\n';
            return false;
			exit(1);
        }

        // load the symbols
        create_module = (create_tmi*) dlsym(module, "create");
        destroy_module = (destroy_tmi*) dlsym(module, "destroy");
        if (!create_module || !destroy_module) {
            cerr << "Cannot load symbols: " << dlerror() << '\n';
            return false;
			exit(1);
        }
        std::cout << "Module " << modulename << " Loaded" << std::endl;
        // create an instance of the class
        mi = create_module();
        mi->BaseInit(reader, groups, users);
        mi->Init();
        modulelist.push_back(modulename);
        modulevector.push_back(module);
        moduleinterfacevector.push_back(mi);
        createvector.push_back(create_module);
        destroyvector.push_back(destroy_module);
        boost::shared_ptr<boost::thread> tmp_thread;
        int modi = -1;
        for (unsigned int i = 0; i < modulelist.size(); i++)
        {
            if (modulelist[i] == modulename)
            {
                modi = i;
            }
        }
        if (modi >= 0)
        {
            assert(!tmp_thread);
            tmp_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&tweakbukconv::LoadThreadLoop, this, modi)));
            module_thread_vector.push_back(tmp_thread);
        }
        return true;
    }
    std::cout << "module " << modulename  << " already loaded" << std::endl;
    return false;
}
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.");
		}
	}


	// the next several chunks of code initialize newMetaInfo:

	// get the dependencies and conflicts from the module, and parse them.
	std::istringstream conflicts(newModule->getConflicts());
	std::istringstream dependencies(newModule->getDependencies());
	std::string token;
	while (conflicts >> token) {
		// the token is one of the conflicts declared by the module
		// make sure it does not yet exist in the set of loaded modules
		// and add it to the list of conflicting modules
		if (_moduleMetaInfoByName.find(token) != _moduleMetaInfoByName.end()) {
			// if the token is found here, that means we have a conflict.
			throw GenericException("Cannot load module \"" + moduleName + "\", because it conflicts with already loaded module \"" + (*_moduleMetaInfoByName.find(token)).second->moduleName);
		}
		newMetaInfo->conflicts.insert(token);
		_moduleConflicts.insert( std::pair<std::string, std::string>(token , moduleName));
	}


	// initialize the simpler data of meta information here
	newMetaInfo->moduleName = moduleName;
	newMetaInfo->module = newModule;
	newMetaInfo->dll = newModuleLib;  // note, this will be NULL for a built-in library.

	newMetaInfo->isLoaded = true;

	// at this point, everything in newMetaInfo should be initialized except for:
	//  - isLoaded is still false until we finish loading below
	//  - isInitialized is still false until we call init() later, outside this function
	//  - list of dependencies is not populated until we load the dependencies
	//  - list of modulesDependentOnThis is initialized at this point, but its contents may change, 
	//    if other modules are loaded that are dependent on this.

	// next, add the newMetaInfo and module to the engine's organizational data structures.
	// _moduleMetaInfoByName is updated earlier
	// _modulesInExecutionOrder is updated after loading all dependencies, so that execution order is maintained
	_moduleMetaInfoByReference[newModule] = newMetaInfo;

	//================
	// everything is loaded except for dependencies; recursively load all dependencies here.
	while (dependencies >> token) {
		ModuleMetaInformation * dependency = _loadModule(token,searchPath);
		dependency->modulesDependentOnThis.insert(newMetaInfo);
		newMetaInfo->dependencies.insert(dependency);
	}

	//================
	// If an entry in the moduleOptionsDatabase did not yet exist, then create one.
	// recall that the [] operator for an STL map will create a new entry if one did not exist by that key already,
	_options->moduleOptionsDatabase[newMetaInfo->moduleName];

	//================
	// if all went well up to this point, the module and its dependencies is loaded, so add it to the end of the list of modules
	// (i.e. it executes after all its dependencies) and return!
	_modulesInExecutionOrder.push_back(newModule);
	std::cout << "loaded module " << newMetaInfo->moduleName << "\n";

	return newMetaInfo;
}