void Registry::add(const std::string& id, void *factory){ FactoryMap::iterator entry = m_factories.find(id); if (entry == m_factories.end()) { // this factory was not known yet m_factories.insert(std::make_pair(id, FactoryInfo("unknown", factory))); } else { entry->second.ptr = factory; } }
//------------------------------------------------------------------------ FactoryInfo PluginFactory::info () const noexcept { Steinberg::PFactoryInfo i; factory->getFactoryInfo (&i); return FactoryInfo (std::move (i)); }
Registry::Registry() { #ifdef WIN32 const char* envVar = "PATH"; const char sep = ';'; #else const char* envVar = "LD_LIBRARY_PATH"; const char sep = ':'; #endif char *search_path = ::getenv(envVar); if (search_path) { DEBUGMSG((std::string("searching factories in ") + envVar)) std::string path(search_path); std::string::size_type pos = 0; std::string::size_type newpos = 0; while (pos != std::string::npos) { std::string dirName; // get the next entry in the path newpos = path.find(sep, pos); if (newpos != std::string::npos) { dirName = path.substr(pos, newpos - pos); pos = newpos+1; } else { dirName = path.substr(pos); pos = newpos; } DEBUGMSG((std::string(" looking into ") + dirName)) // look for files called "*.factories" in the directory DIR *dir = opendir(dirName.c_str()); if (dir) { struct dirent * entry; while ((entry = readdir(dir))) { std::string name(entry->d_name); std::string::size_type extpos = name.find(".components"); if ((extpos != std::string::npos) && ((extpos+11) == name.size()) && ((entry->d_type == DT_REG) || (entry->d_type == DT_LNK))) { DEBUGMSG((std::string(" reading ") + name)) std::ifstream factories((dirName + '/' + name).c_str()); std::string lib, fact; #ifndef NDEBUG int factoriesCount = 0; #endif while (!factories.eof()) { std::getline(factories, lib, ':'); if (factories.fail()) break; std::getline(factories, fact); if (factories.fail()) break; m_factories.insert(std::make_pair(fact, FactoryInfo(lib))); #ifndef NDEBUG ++factoriesCount; #endif } #ifndef NDEBUG DEBUGSTRM << " found " << factoriesCount\ << " factories" << std::endl; #endif } } closedir(dir); } } } }