summaryrefslogtreecommitdiffstats
path: root/mmss/protocol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mmss/protocol.cpp')
-rw-r--r--mmss/protocol.cpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/mmss/protocol.cpp b/mmss/protocol.cpp
index 246b136..5688525 100644
--- a/mmss/protocol.cpp
+++ b/mmss/protocol.cpp
@@ -24,43 +24,36 @@
*/
+#include "protocol.hpp"
#include "mmss.hpp"
#include <dlfcn.h>
-#include <cstdio>
namespace MMSS {
-class dlcloser {
-private:
- void *handle;
-
-public:
- dlcloser(void *handle0) : handle(handle0) {}
- void operator()(const protocol_t *ptr) const {
- ::dlclose(handle);
- }
-};
+protocol_t::~protocol_t() {
+ ::dlclose(handle);
+}
-std::shared_ptr<const protocol_t> load_protocol(const char *module) {
- void *handle = ::dlopen(module, RTLD_NOW);
+std::shared_ptr<const protocol_t> protocol_t::load(context_t *mmss, const std::string &module) {
+ void *handle = ::dlopen(module.c_str(), RTLD_NOW);
if (!handle) {
- std::fprintf(stderr, "unable to load protocol from `%s': %s\n", module, dlerror());
+ mmss->logf(LOG_ERR, "unable to load protocol from `%s': %s", module.c_str(), dlerror());
return std::shared_ptr<const protocol_t>();
}
::dlerror();
- const protocol_t *proto = reinterpret_cast<const protocol_t*>(::dlsym(handle, "mmss_protocol_info"));
+ const mmss_protocol_t *proto = reinterpret_cast<const mmss_protocol_t*>(::dlsym(handle, "mmss_protocol_info"));
if (!proto) {
- std::fprintf(stderr, "unable to load protocol from `%s': %s\n", module, dlerror());
+ mmss->logf(LOG_ERR, "unable to load protocol from `%s': %s", module.c_str(), dlerror());
::dlclose(handle);
return std::shared_ptr<const protocol_t>();
}
- std::fprintf(stderr, "loaded protocol `%s' version %s\n", proto->get_name(), proto->get_version());
+ mmss->logf(LOG_INFO, "loaded protocol `%s' version %s", proto->get_name(), proto->get_version());
- return std::shared_ptr<const protocol_t>(proto, dlcloser(handle));
+ return std::shared_ptr<const protocol_t>(new protocol_t(handle, proto));
}
}