示例#1
0
bool PluginManager::unloadPlugin(std::string &pluginPath, std::ostream *errlog)
{
    PluginMap::iterator iter;
    iter = m_pluginMap.find(pluginPath);
    if( iter == m_pluginMap.end() )
    {
        if (sofa::helper::system::SetDirectory::GetParentDir(pluginPath.c_str()).empty() &&
            sofa::helper::system::SetDirectory::GetExtension(pluginPath.c_str()).empty())
        {
            // no path and extension -> automatically add suffix and OS-specific extension
#ifdef SOFA_LIBSUFFIX
            pluginPath += sofa_tostring(SOFA_LIBSUFFIX);
#endif
#if defined (WIN32)
            pluginPath = pluginPath + std::string(".dll");
#elif defined (__APPLE__)
            pluginPath = std::string("lib") + pluginPath + std::string(".dylib");
#else
            pluginPath = std::string("lib") + pluginPath + std::string(".so");
#endif
        }
        PluginRepository.findFile(pluginPath,"",errlog);
        iter = m_pluginMap.find(pluginPath);
    }
    if( iter == m_pluginMap.end() )
    {
        if(errlog) (*errlog) << "Plugin " << pluginPath << "not in PluginManager" << std::endl;
        return false;
    }
    else
    {
        m_pluginMap.erase(iter);
        return true;
    }
}
示例#2
0
bool PluginManager::loadPlugin(std::string& pluginPath, std::ostream* errlog)
{
    if (sofa::helper::system::SetDirectory::GetParentDir(pluginPath.c_str()).empty() &&
        sofa::helper::system::SetDirectory::GetExtension(pluginPath.c_str()).empty())
    {
        // no path and extension -> automatically add suffix and OS-specific extension
#ifdef SOFA_LIBSUFFIX
        pluginPath += sofa_tostring(SOFA_LIBSUFFIX);
#endif
#if defined (WIN32)
        pluginPath = pluginPath + std::string(".dll");
#elif defined (__APPLE__)
        pluginPath = std::string("lib") + pluginPath + std::string(".dylib");
#else
        pluginPath = std::string("lib") + pluginPath + std::string(".so");
#endif
        //std::cout << "System-specific plugin filename: " << pluginPath << std::endl;
    }

    if( !PluginRepository.findFile(pluginPath,"",errlog) )
    {
        if (errlog) (*errlog) << "Plugin " << pluginPath << " NOT FOUND in: " << PluginRepository << std::endl;
        return false;
    }
    if(m_pluginMap.find(pluginPath) != m_pluginMap.end() )
    {
        if(errlog) (*errlog) << "Plugin " << pluginPath << " already in PluginManager" << std::endl;
        return false;
    }
    DynamicLibrary::Handle d  = DynamicLibrary::load(pluginPath);
    Plugin p;
    if( ! d.isValid() )
    {
        if (errlog) (*errlog) << "Plugin " << pluginPath << " loading FAILED with error: " << DynamicLibrary::getLastError() << std::endl;
        return false;
    }
    else
    {
        if(! getPluginEntry(p.initExternalModule,d))
        {
            if (errlog) (*errlog) << "Plugin " << pluginPath << " method initExternalModule() NOT FOUND" << std::endl;
            return false;
        }
        getPluginEntry(p.getModuleName,d);
        getPluginEntry(p.getModuleDescription,d);
        getPluginEntry(p.getModuleLicense,d);
        getPluginEntry(p.getModuleComponentList,d);
        getPluginEntry(p.getModuleVersion,d);
    }

    p.dynamicLibrary = d;
    m_pluginMap[pluginPath] = p;

    return true;
}
示例#3
0
const char* getModuleComponentList()
{
     /// string containing the names of the classes provided by the plugin
     static std::string classes = sofa::core::ObjectFactory::getInstance()->listClassesFromTarget(sofa_tostring(SOFA_TARGET));
     return classes.c_str();
}