当前位置: 首页>>代码示例>>C++>>正文


C++ PluginLoader::load方法代码示例

本文整理汇总了C++中PluginLoader::load方法的典型用法代码示例。如果您正苦于以下问题:C++ PluginLoader::load方法的具体用法?C++ PluginLoader::load怎么用?C++ PluginLoader::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PluginLoader的用法示例。


在下文中一共展示了PluginLoader::load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ModuleDL

/** The main test program.
 * @param argc the number of arguments
 * @param argv the arguments
 * @return 0 on success
 */
int
main(int argc, char **argv)
{
  // Load just the test module

  bool success = true;

  cout << "Running plain module tests" << endl;
  ModuleDL *m = new ModuleDL(PLUGINDIR"/test_splugin.so");
  try {
    m->open();
  } catch (Exception &e) {
    e.print_trace();
    throw;
  }
  success = test_module(m);
  m->close();
  delete m;
  if ( success ) {
    cout << "SUCCESSFULLY tested plain module" << endl;
  } else {
    cout << "FAILED plain module tests, aborting further tests" << endl;
    return -1;
  }

  success = true;
  cout << endl << endl << "Running ModuleManagerTemplate tests" << endl;
  ModuleManagerTemplate<ModuleDL> mm(PLUGINDIR);
  Module *mod = mm.open_module("test_plugin.so");
  if ( mod == NULL ) {
    cout << "Failed to retrieve module from manager" << endl;
    success = false;
  } else {
    cout << "Retrieved module from module manager" << endl;
  }

  success = test_module(mod);

  cout << "Testing ref count" << endl;
  cout << "RefCount (should be 1): " << mod->get_ref_count() << endl;
  cout << "Retrieving module twice, again" << endl;
  mm.open_module("test_plugin.so");
  mm.open_module("test_plugin.so");
  cout << "RefCount (should be 3): " << mod->get_ref_count() << endl;
  cout << "Closing module twice" << endl;
  mm.close_module(mod);
  mm.close_module(mod);
  cout << "RefCount (should be 1): " << mod->get_ref_count() << endl;
  cout << "Finally closing module" << endl;
  mm.close_module(mod);
  if ( mm.module_opened("test_plugin.so") ) {
    cout << "Plugin still opened, bug!" << endl;
    success = false;
  } else {
    cout << "Plugin has been unloaded from module manager" << endl;
  }


  if ( success ) {
    cout << "SUCCESSFULLY tested module manager" << endl;
  } else {
    cout << "FAILED module manager tests, aborting further tests" << endl;
    return 2;
  }


  success = true;
  cout << endl << endl << "Running PluginLoader tests" << endl;
  PluginLoader *pl = new PluginLoader(PLUGINDIR, NULL);

  Plugin *p;
  try {
    p = pl->load("test_plugin");
    success = test_plugin(p);
    pl->unload(p);
    success = true;
  } catch (PluginLoadException &e) {
    cout << "Could not load plugin" << endl;
    e.print_trace();
    success = false;
  }

  delete pl;
  if ( success ) {
    cout << "SUCCESSFULLY tested PluginLoader" << endl;
  } else {
    cout << "FAILED module manager tests, aborting further tests" << endl;
    return 3;
  }

  return 0;
}
开发者ID:fuxiang90,项目名称:fawkes,代码行数:97,代码来源:plugin.cpp


注:本文中的PluginLoader::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。