diff options
Diffstat (limited to 'libtransport/src/core/io_module.cc')
-rw-r--r-- | libtransport/src/core/io_module.cc | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/libtransport/src/core/io_module.cc b/libtransport/src/core/io_module.cc index a751eabf5..0fdb735c4 100644 --- a/libtransport/src/core/io_module.cc +++ b/libtransport/src/core/io_module.cc @@ -16,11 +16,14 @@ #ifndef _WIN32 #include <dlfcn.h> #endif +#include <core/global_module_manager.h> #include <glog/logging.h> #include <hicn/transport/core/io_module.h> +#include <iostream> + #ifdef ANDROID -#include <io_modules/udp/hicn_forwarder_module.h> +#include <io_modules/hicn-light/hicn_forwarder_module.h> #elif _WIN32 #include <hicn/util/windows/windows_utils.h> #endif @@ -36,53 +39,28 @@ IoModule *IoModule::load(const char *module_name) { #ifdef ANDROID return new HicnForwarderModule(); #else - void *handle = 0; - IoModule *module = 0; - IoModule *(*creator)(void) = 0; - const char *error = 0; + IoModule *iomodule = nullptr; + IoModule *(*creator)(void) = nullptr; + const char *error = nullptr; - // open module - handle = dlopen(module_name, RTLD_NOW); - if (!handle) { - if ((error = dlerror()) != 0) { - LOG(ERROR) << error; - } - return 0; - } + auto handle = GlobalModuleManager::getInstance().loadModule(module_name); // get factory method creator = (IoModule * (*)(void)) dlsym(handle, "create_module"); if (!creator) { - if ((error = dlerror()) != 0) { - LOG(ERROR) << error; - return 0; + if ((error = dlerror()) != nullptr) { + LOG(ERROR) << error << ": " << module_name; } + + return nullptr; } // create object and return it - module = (*creator)(); - module->handle_ = handle; - - return module; -#endif -} - -bool IoModule::unload(IoModule *module) { - if (!module) { - return false; - } + iomodule = (*creator)(); -#ifdef ANDROID - delete module; -#else - // destroy object and close module - void *handle = module->handle_; - delete module; - dlclose(handle); + return iomodule; #endif - - return true; } } // namespace core -} // namespace transport
\ No newline at end of file +} // namespace transport |