Example #1
0
dynamic_loader::dynamic_loader(const std::string& path)
    : handle_(0) {
  void* handle = NULL;
  std::string loaded_path;
  if (is_absolute_or_relative_path(path)) {
    // Load the plugin with the given path
    handle = ::dlopen(path.c_str(), RTLD_LAZY);
    loaded_path = path;

  } else {
    // Try to load the plugin from the plugin path environment
    const char* plugin_dir = get_plugin_path();
    if (plugin_dir) {
      const std::string plugin_path =
          std::string(plugin_dir) + "/" + path;
      handle = ::dlopen(plugin_path.c_str(), RTLD_LAZY);
      loaded_path = plugin_path;
    }

    // If failed, try to load it from the plugin directory specified on
    // configure.
    if (!handle) {
      const std::string plugin_path =
          std::string(JUBATUS_PLUGIN_DIR) + "/" + path;
      handle = ::dlopen(plugin_path.c_str(), RTLD_LAZY);
      loaded_path = plugin_path;
    }
  }

  handle_ = handle;

  if (!handle_) {
    char* error = dlerror();
    throw JUBATUS_EXCEPTION(
        converter_exception(
            "cannot load dynamic library: " + path + ": " + error)
        << jubatus::core::common::exception::error_api_func("dlopen")
        << jubatus::core::common::exception::error_file_name(path)
        << jubatus::core::common::exception::error_message(error));
  } else {
    try {
      typedef std::string (*func_t)(void);
      func_t version = reinterpret_cast<func_t>(load_symbol("version"));
      LOG(INFO) << "plugin loaded: " << common::real_path(loaded_path)
                << " version: " << version();
    } catch (converter_exception) {
      LOG(WARN) << "plugin loaded: " << common::real_path(loaded_path)
                << " but version information is unavailable";
    }
  }
}
Example #2
0
dynamic_loader::dynamic_loader(const std::string& path)
    : handle_(0) {

  void* handle = NULL;
  std::string loaded_path;

  if (is_absolute_or_relative_path(path)) {
    // If the path contains "/", load the plugin with the given path.
    handle = ::dlopen(path.c_str(), RTLD_LAZY);
    loaded_path = path;
  } else {
    // Try to load the plugin from the plugin path environment.
    const char* plugin_dir = get_plugin_path();
    if (plugin_dir) {
      const std::string plugin_path =
          std::string(plugin_dir) + "/" + path;
      handle = ::dlopen(plugin_path.c_str(), RTLD_LAZY);
      loaded_path = plugin_path;
    }

    // If failed, try to load it from the plugin directory specified on
    // configure.
    if (!handle) {
      const std::string plugin_path =
          std::string(JUBATUS_PLUGIN_DIR) + "/" + path;
      handle = ::dlopen(plugin_path.c_str(), RTLD_LAZY);
      loaded_path = plugin_path;
    }
  }

  if (!handle) {
    char* error = dlerror();
    throw JUBATUS_EXCEPTION(
        converter_exception(
            "cannot load dynamic library: " + path + ": " + error)
        << jubatus::core::common::exception::error_api_func("dlopen")
        << jubatus::core::common::exception::error_file_name(path)
        << jubatus::core::common::exception::error_message(error));
  }

  handle_ = handle;
}