예제 #1
0
    void PluginContainer::load(PluginPtr plugin, system::Library library) throw(PluginLoadException) {
      if (plugin->getCompilerInfo() != BFT_COMPILER_INFO) {
        // TODO more information in the exception.
        throw PluginLoadException("Compiler mis-match.");
      }

      if (!common::isCompatible(application.getVersion(), plugin->getEngineVersion())) {
        // TODO more information in the exception.
        throw PluginLoadException("Version mis-match.");
      }

      plugins.emplace_back(std::move(library), std::move(plugin));
    }
예제 #2
0
    void PluginContainer::loadFromFile(char const *path) throw(PluginLoadException) {
      try {
        system::Library library(path);

        auto createPluginFunction = reinterpret_cast<CreatePluginFunction>(library.getSymbolAddress("createPlugin"));
        if (!createPluginFunction) {
          throw PluginLoadException("Plugin does not export 'createPlugin' function.");
        }

        auto plugin = std::unique_ptr<Plugin>((*createPluginFunction)(application));
        if (!plugin) {
          throw PluginLoadException("Failed to create plugin.");
        }

        load(std::move(plugin), std::move(library));
      } catch (system::Library::LibraryLoadFailedException&) {
        throw PluginLoadException();
      }
    }
예제 #3
0
파일: loader.cpp 프로젝트: fuxiang90/fawkes
Module *
PluginLoader::open_module(const char *plugin_name)
{
  std::string module_name = std::string(plugin_name) + "." + d->mm->get_module_file_extension();

  try {
    return d->mm->open_module(module_name.c_str());
  } catch (ModuleOpenException &e) {
    throw PluginLoadException(plugin_name, "failed to open module", e);
  }
}
예제 #4
0
파일: loader.cpp 프로젝트: fuxiang90/fawkes
Plugin *
PluginLoader::create_instance(const char *plugin_name, Module *module)
{
  if ( ! module->has_symbol("plugin_factory") ) {
    throw PluginLoadException(plugin_name, "Symbol 'plugin_factory' not found. Forgot EXPORT_PLUGIN?");
  }
  if ( ! module->has_symbol("plugin_description") ) {
    throw PluginLoadException(plugin_name, "Symbol 'plugin_description' not found. Forgot PLUGIN_DESCRIPTION?");
  }

  PluginFactoryFunc pff = (PluginFactoryFunc)module->get_symbol("plugin_factory");
  Plugin *p = NULL;

  p = pff(__config);
  if ( p == NULL ) {
    throw PluginLoadException(plugin_name, "Plugin could not be instantiated");
  } else {
    p->set_name(plugin_name);
  }

  return p;
}
예제 #5
0
파일: loader.cpp 프로젝트: fuxiang90/fawkes
/** Get plugin description.
 * @param plugin_name name of the plugin
 * @return plugin description tring
 * @throw PluginLoadException thrown if opening the plugin fails
 */
std::string
PluginLoader::get_description(const char *plugin_name)
{
  Module *module = open_module(plugin_name);

  if ( ! module->has_symbol("plugin_description") ) {
    throw PluginLoadException(plugin_name, "Symbol 'plugin_description' not found. Forgot PLUGIN_DESCRIPTION?");
  }

  PluginDescriptionFunc pdf = (PluginDescriptionFunc)module->get_symbol("plugin_description");
  std::string rv = pdf();
  d->mm->close_module(module);

  return rv;
}
예제 #6
0
    PluginContainer::PluginContainer(Application &application, std::string pluginDir)
      throw(PluginLoadException) :
      application(application),
      pluginDir(std::move(pluginDir))
    {
      if (io::path::exists(this->pluginDir.c_str())) {
        loadFromDirectory(this->pluginDir.c_str());
      }

      for (auto &plugin : plugins) {
        try {
          plugin.second->load();
        } catch (Plugin::PluginLoadException&) {
          throw PluginLoadException();
        }
      }
    }