Esempio n. 1
0
PluginManager::PluginManager(int argc, const char** argv)
{
    const bool help = containsString(argc, argv, "--help");

    for (int i = 0; i < argc; ++i)
    {
        if (std::strcmp(argv[i], "--plugin") != 0)
            continue;
        if (++i == argc || argv[i][0] == '\0' || argv[i][0] == '-')
        {
            // Do not print anything here, errors will be reported later
            // during option parsing
            continue;
        }

        std::string str(argv[i]);
        boost::trim(str);
        std::vector<std::string> words;
        boost::split(words, str, boost::is_any_of(" "),
                     boost::token_compress_on);
        if (help)
            words.push_back("--help");

        const char* name = words.front().c_str();
        std::vector<const char*> args;
        for (const auto& w : words)
            args.push_back(w.c_str());

        _loadPlugin(name, args.size(), args.data());
    }
}
Esempio n. 2
0
AIEngineLib_APtr
hoxAIPluginMgr::CreateDefaultAIEngineLib()
{
    // --- Unload the previous (loaded) plugin.
    if ( !m_lastPluginName.empty() && m_lastPluginName != m_defaultPluginName )
    {
        wxLogDebug("%s: Unload the last Plugin [%s].", __FUNCTION__, m_lastPluginName.c_str());
        hoxAIPlugin_SPtr pPlugin = m_aiPlugins[m_lastPluginName];
        if ( pPlugin )
        {
            pPlugin->Unload();
        }
    }

    // --- Load the new plugin.
    
    AIEngineLib_APtr apEngine;

    const wxString sName = m_defaultPluginName;
    if ( sName.empty() )
    {
        ::wxMessageBox( _("There is no AI Engine available."),
                        _("AI Creation"),
                        wxOK | wxICON_EXCLAMATION );
        return apEngine;
    }

    hoxAIPlugin_SPtr pPlugin = _loadPlugin( sName );

    if ( !pPlugin || !pPlugin->IsLoaded() )
    {
        wxLogWarning("%s: The AI Engine [%s] could not be loaded.", __FUNCTION__, sName.c_str());
        return apEngine;
    }

    m_lastPluginName = sName;

    return pPlugin->CreateAIEngineLib();
}
Esempio n. 3
0
bool PluginRegistry::addPlugin( const std::string& filename )
{
    Plugin* plugin = _loadPlugin( filename, impl_->directories );
    if( !plugin )
        return false;

    const CompressorInfos& infos = plugin->getInfos();
    for( PluginsCIter i = impl_->plugins.begin(); i != impl_->plugins.end(); ++i)
    {
        const CompressorInfos& infos2 = (*i)->getInfos();

        // Simple test to avoid loading the same dll twice
        if( infos.front().name == infos2.front().name )
        {
            delete plugin;
            return true;
        }
    }

    impl_->plugins.push_back( plugin );
    LBLOG( LOG_PLUGIN ) << "Found " << plugin->getInfos().size()
                        << " compression engines in " << filename << std::endl;
    return true;
}