From: Vitaliy Cherepanov/AI Tools Lab /SRR/Engineer/삼성전자 Date: Wed, 6 Jun 2018 07:14:32 +0000 (+0300) Subject: nnc: Fix PluginProxy interface (#309) X-Git-Tag: nncc_backup~2610 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00e1562316ecb222599481b9951cfd836dcac4b9;p=platform%2Fcore%2Fml%2Fnnfw.git nnc: Fix PluginProxy interface (#309) This commit is to fix common plugin interface. There are some problems to return std::shared_ptr by library "C" interface also AbstractPluginInstance and plugin *PluginInstance (like SamplePluginInstance) should be a singleton and std::shared_ptr is unnecessary there. Signed-off-by: Vitaliy Cherepanov --- diff --git a/contrib/nnc/include/module/plugin/PluginProxy.h b/contrib/nnc/include/module/plugin/PluginProxy.h index b836bb0..19b7e02 100644 --- a/contrib/nnc/include/module/plugin/PluginProxy.h +++ b/contrib/nnc/include/module/plugin/PluginProxy.h @@ -28,7 +28,7 @@ public: const std::string &getPluginPath() const; const std::string &getPluginName() const; - std::shared_ptr getPluginInstance(); + contrib::plugin::AbstractPluginInstance &getPluginInstance(); public: static const std::string getInstanceFuncName; @@ -41,9 +41,9 @@ private: friend std::ostream &operator<<(std::ostream &st, const PluginProxy &pl); private: - typedef std::shared_ptr (*get_instance_t)(); + typedef contrib::plugin::AbstractPluginInstance *(*get_instance_t)(); - std::shared_ptr _pluginInstance; + contrib::plugin::AbstractPluginInstance *_pluginInstance; std::shared_ptr _lib; get_instance_t _getInstance; std::string _pluginName; diff --git a/contrib/nnc/src/module/AbstractModule.cpp b/contrib/nnc/src/module/AbstractModule.cpp index e52cb53..b5e20d0 100644 --- a/contrib/nnc/src/module/AbstractModule.cpp +++ b/contrib/nnc/src/module/AbstractModule.cpp @@ -27,18 +27,18 @@ void AbstractModule::configure(std::shared_ptr conf) { _activePlugin = nullptr; for (auto &pl : _plugins) { try { - auto pluginInstance = pl->getPluginInstance(); - auto *session = dynamic_cast(pluginInstance->getSession().get()); + auto &pluginInstance = pl->getPluginInstance(); + auto *session = dynamic_cast(pluginInstance.getSession().get()); auto resParams = config::DataList::intersection(*conf, session->getSupportedParams()); for (auto param : resParams->getElements()) { if (param.second.hasValue()) - pluginInstance->setParam(param.second.getName(), param.second.getValue()); + pluginInstance.setParam(param.second.getName(), param.second.getValue()); else - pluginInstance->setParam(param.second.getName()); + pluginInstance.setParam(param.second.getName()); } - pluginInstance->checkConfig(); + pluginInstance.checkConfig(); _activePlugin = pl; break; } @@ -64,7 +64,7 @@ void *AbstractModule::execute(void *data) { if (_activePlugin == nullptr) throw ConfigException("Module <" + pluginTypeToStr(_moduleType) + "> has not been configured!"); - return _activePlugin->getPluginInstance()->execute(data); + return _activePlugin->getPluginInstance().execute(data); } contrib::plugin::PluginType AbstractModule::getModuleType() const { return _moduleType; } diff --git a/contrib/nnc/src/module/plugin/PluginManager.cpp b/contrib/nnc/src/module/plugin/PluginManager.cpp index 2729cc3..94fbcbb 100644 --- a/contrib/nnc/src/module/plugin/PluginManager.cpp +++ b/contrib/nnc/src/module/plugin/PluginManager.cpp @@ -64,10 +64,10 @@ void PluginManager::loadPlugins(std::vector &modules) { for (const auto &pluginPath : plugins) { try { auto pl = PluginProxy::create(pluginPath); - auto plInst = pl->getPluginInstance(); + auto &plInst = pl->getPluginInstance(); std::shared_ptr session = std::make_shared(); - plInst->setSession(session); - plInst->fillSession(); + plInst.setSession(session); + plInst.fillSession(); if (_showPluginInfo) std::cout << "plugin <" + pluginPath + ">: {" << std::endl @@ -95,7 +95,7 @@ void PluginManager::loadPlugins(std::vector &modules) { for (auto &pl : _plugins) { for (auto m : modules) { auto session = - dynamic_cast(pl->getPluginInstance()->getSession().get()); + dynamic_cast(pl->getPluginInstance().getSession().get()); if (m->getModuleType() == session->getPluginType()) { m->registerPlugin(pl); break; diff --git a/contrib/nnc/src/module/plugin/PluginProxy.cpp b/contrib/nnc/src/module/plugin/PluginProxy.cpp index a5f085f..ace5970 100644 --- a/contrib/nnc/src/module/plugin/PluginProxy.cpp +++ b/contrib/nnc/src/module/plugin/PluginProxy.cpp @@ -64,10 +64,10 @@ const std::string &PluginProxy::getPluginPath() const { return _lib->getPath(); const std::string &PluginProxy::getPluginName() const { return _pluginName; } -std::shared_ptr PluginProxy::getPluginInstance() { +contrib::plugin::AbstractPluginInstance &PluginProxy::getPluginInstance() { if (_pluginInstance == nullptr) throw PluginException(std::string("bad plugin instance <") + getPluginPath() + ">"); - return _pluginInstance; + return *_pluginInstance; } } // namespace plugins