diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-07-27 21:33:37 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-07-27 21:33:37 +0200 |
commit | 37566202133915d76179e0fd0c7fad654fc4dda0 (patch) | |
tree | 4d9490f02804d7be3b51ca8da8acb3fd7a2e93e3 /mmss/protocol.cpp | |
parent | efabc7a40d74904385d9dd55eb0312aeb538d4ed (diff) | |
download | gmrf-37566202133915d76179e0fd0c7fad654fc4dda0.tar gmrf-37566202133915d76179e0fd0c7fad654fc4dda0.zip |
Encapsulate protocol_t
Diffstat (limited to 'mmss/protocol.cpp')
-rw-r--r-- | mmss/protocol.cpp | 29 |
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)); } } |