From d80b1801433e3041d5a3da4bf86d249f0e94bbb0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vitaliy=20Cherepanov/AI=20Tools=20Lab/Engineer/=EC=82=BC?= =?utf8?q?=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 1 Jun 2018 10:36:36 +0300 Subject: [PATCH] nnc: Implement AbstractPluginInstance class (#266) nnc: implement AbstractPluginInstance class Virtual plugin instance class. Provides basic API for communication between plugin and nnc Signed-off-by: Vitaliy Cherepanov --- contrib/nnc/libs/plugin/include/PluginInstance.h | 48 ++++++++++++++++++++++++ contrib/nnc/libs/plugin/src/PluginInstance.cpp | 40 ++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 contrib/nnc/libs/plugin/include/PluginInstance.h create mode 100644 contrib/nnc/libs/plugin/src/PluginInstance.cpp diff --git a/contrib/nnc/libs/plugin/include/PluginInstance.h b/contrib/nnc/libs/plugin/include/PluginInstance.h new file mode 100644 index 0000000..558d59b --- /dev/null +++ b/contrib/nnc/libs/plugin/include/PluginInstance.h @@ -0,0 +1,48 @@ +#ifndef __PLUGIN_INSTANCE_H__ +#define __PLUGIN_INSTANCE_H__ + +#include +#include +#include "AbstractSession.h" + +namespace nncc +{ +namespace contrib +{ +namespace plugin +{ + +// +// This class and its methods are NOT thread safe +// +class AbstractPluginInstance +{ +public: + static const std::string paramPluginVersion; + static const std::string paramPluginName; + +public: + AbstractPluginInstance(); + virtual ~AbstractPluginInstance(); + + virtual void fillSessionBase(PluginType type, const std::string &ver, + const std::string &pluginName); + + virtual void fillSession() = 0; + virtual void setParam(const std::string &name) = 0; + virtual void setParam(const std::string &name, const std::string &value) = 0; + virtual void checkConfig() = 0; + virtual void *execute(void *data) = 0; + + virtual void setSession(std::shared_ptr &session); + virtual std::shared_ptr getSession() const; + +private: + std::shared_ptr _session; +}; + +} // namespace plugin +} // namespace contrib +} // namespace nncc + +#endif // __PLUGIN_INSTANCE_H__ diff --git a/contrib/nnc/libs/plugin/src/PluginInstance.cpp b/contrib/nnc/libs/plugin/src/PluginInstance.cpp new file mode 100644 index 0000000..f1688c3 --- /dev/null +++ b/contrib/nnc/libs/plugin/src/PluginInstance.cpp @@ -0,0 +1,40 @@ +#include +#include "PluginInstance.h" +#include "PluginException.h" + +namespace nncc +{ +namespace contrib +{ +namespace plugin +{ + +const std::string AbstractPluginInstance::paramPluginVersion = "version"; +const std::string AbstractPluginInstance::paramPluginName = "plugin name"; + +void AbstractPluginInstance::fillSessionBase(PluginType type, const std::string &ver, + const std::string &pluginName) +{ + getSession()->setPluginType(type); + getSession()->addInfo(paramPluginVersion, ver); + getSession()->addInfo(paramPluginName, pluginName); +} + +void AbstractPluginInstance::setSession(std::shared_ptr &session) +{ + _session = session; +} + +std::shared_ptr AbstractPluginInstance::getSession() const +{ + if (_session == nullptr) + throw nncc::contrib::PluginException("session not set!"); + return _session; +} + +AbstractPluginInstance::AbstractPluginInstance() : _session(nullptr) {} +AbstractPluginInstance::~AbstractPluginInstance() {} + +} // namespace plugin +} // namespace contrib +} // namespace nncc -- 2.7.4