Permalink
Browse files

Fixed issue with missing loaded plugins from cache

  • Loading branch information...
1 parent 23aca27 commit 24b96b8b5081b44371271b7e9355a2cefdefa23d @mickem committed Dec 13, 2016
@@ -541,4 +541,10 @@ bool NSCPlugin::is_duplicate(boost::filesystem::path file, std::string alias) {
if (alias.empty() || alias_.empty())
return false;
return module_.get_file() == dll::dll_impl::fix_module_name(file) && alias == alias_;
-}
+}
+
+std::string NSCPlugin::get_version() {
+ int major, minor, revision;
+ getVersion(&major, &minor, &revision);
+ return strEx::s::xtos(major) + "." + strEx::s::xtos(minor) + "." + strEx::s::xtos(revision);
+}
View
@@ -238,6 +238,7 @@ class NSCPlugin : public boost::noncopyable, public nsclient::logging::logging_s
void on_log_message(std::string &payload) {
handleMessage(payload.c_str(), static_cast<unsigned int>(payload.size()));
}
+ std::string get_version();
private:
bool getName_(char* buf, unsigned int buflen);
@@ -850,6 +850,7 @@ NSClientT::plugin_type NSClientT::addPlugin(boost::filesystem::path file, std::s
routers_.add_plugin(plugin);
settings_manager::get_core()->register_key(0xffff, MAIN_MODULES_SECTION, plugin->getModule(), settings::settings_core::key_string, plugin->getName(), plugin->getDescription(), "0", false, false);
}
+ plugin_cache_.add_plugin(plugin);
return plugin;
}
@@ -3,6 +3,9 @@
#include <boost/thread/locks.hpp>
#include <boost/foreach.hpp>
+#include <strEx.h>
+
+
void nsclient::core::plugin_cache::add_plugins(const plugin_cache_list_type & item) {
boost::unique_lock<boost::shared_mutex> writeLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(5));
if (!writeLock.owns_lock()) {
@@ -72,8 +75,26 @@ boost::optional<nsclient::core::plugin_cache_item> nsclient::core::plugin_cache:
std::string nsclient::core::plugin_cache::find_plugin_alias(unsigned int plugin_id) {
boost::optional<plugin_cache_item> info = find_plugin_info(plugin_id);
if (!info) {
- return "TODO";
+ return "Failed to find plugin: " + strEx::s::xtos(plugin_id);
}
return info->alias;
}
+void nsclient::core::plugin_cache::add_plugin(nsclient::core::plugin_type plugin) {
+ boost::unique_lock<boost::shared_mutex> writeLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(5));
+ if (!writeLock.owns_lock()) {
+ LOG_ERROR_CORE("FATAL ERROR: Could not get write-mutex.");
+ return;
+ }
+ plugin_cache_.push_back(plugin_cache_item(plugin));
+}
+
+nsclient::core::plugin_cache_item::plugin_cache_item(const nsclient::core::plugin_type& plugin)
+ : id(plugin->get_id())
+ , dll(plugin->getModule())
+ , alias(plugin->get_alias_or_name())
+ , name(plugin->getModule())
+ , title(plugin->getName())
+ , desc(plugin->getDescription())
+ , version(plugin->get_version())
+ , is_loaded(true) {}
@@ -1,5 +1,7 @@
#pragma once
+#include "NSCPlugin.h"
+
#include <nsclient/logger/logger.hpp>
#include <boost/thread/shared_mutex.hpp>
@@ -10,6 +12,9 @@
namespace nsclient {
namespace core {
+
+ typedef boost::shared_ptr<NSCPlugin> plugin_type;
+
struct plugin_cache_item {
unsigned int id;
std::string dll;
@@ -21,6 +26,7 @@ namespace nsclient {
bool is_loaded;
plugin_cache_item() : id(0), is_loaded(false) {}
+ plugin_cache_item(const plugin_type& other);
plugin_cache_item(const plugin_cache_item& other)
: id(other.id)
, dll(other.dll)
@@ -64,12 +70,12 @@ namespace nsclient {
boost::optional<unsigned int> find_plugin(const ::std::string& name);
std::string find_plugin_alias(unsigned int plugin_id);
+ void add_plugin(plugin_type plugin);
private:
nsclient::logging::logger_instance get_logger() {
return logger_;
}
-
};
}
}
@@ -171,6 +171,7 @@ namespace nsclient {
itm.dll = plugin->getModule();
itm.name = plugin->getName();
itm.desc = plugin->getDescription();
+ itm.id = plugin->get_id();
itm.is_loaded = false;
tmp_list.push_back(itm);
plugin->unload_dll();

0 comments on commit 24b96b8

Please sign in to comment.