From: Youngjae Shin Date: Tue, 7 Jan 2020 23:25:35 +0000 (+0900) Subject: revise arch between actionRule and action X-Git-Tag: submit/tizen/20200319.043412~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=555b72c60bb0d17f787b8419c35d2db2525a2392;p=platform%2Fcore%2Fsystem%2Fmodes.git revise arch between actionRule and action --- diff --git a/supervisor/ActionRule.cpp b/supervisor/ActionRule.cpp index 92e8357..cac2de1 100644 --- a/supervisor/ActionRule.cpp +++ b/supervisor/ActionRule.cpp @@ -25,12 +25,12 @@ std::string ActionRule::getName() return ruleName; } -void ActionRule::setPlugin(const std::string &pi) +void ActionRule::setPlugin(Plugin *pi) { plugin = pi; } -std::string ActionRule::getPlugin() +Plugin* ActionRule::getPlugin() { return plugin; } diff --git a/supervisor/ActionRule.h b/supervisor/ActionRule.h index 8fbb9b3..e0808c4 100644 --- a/supervisor/ActionRule.h +++ b/supervisor/ActionRule.h @@ -26,16 +26,16 @@ public: virtual ~ActionRule() = default; std::string getName(); - std::string getPlugin(); - void setPlugin(const std::string &pi); + Plugin* getPlugin(); + void setPlugin(Plugin *pi); void setPrivilege(const std::string &priv); virtual Action* makeAction() = 0; virtual int addAlias(const std::string &alias, const std::string &value) = 0; protected: std::string ruleName; std::string privilege; + Plugin *plugin; private: - std::string plugin; // TODO:: handle conflict List, since, description, version //std::list conflictActionList; //std::string description; diff --git a/supervisor/ModeManager.cpp b/supervisor/ModeManager.cpp index a79bd10..033be02 100644 --- a/supervisor/ModeManager.cpp +++ b/supervisor/ModeManager.cpp @@ -30,8 +30,8 @@ using std::string; MODES_NAMESPACE_USE; -ModeManager::ModeManager(RuleManager &rMgr, PluginManager &pMgr) - : ruleMgr(rMgr), pluginMgr(pMgr) +ModeManager::ModeManager(RuleManager &rMgr) + : ruleMgr(rMgr) { } @@ -62,7 +62,7 @@ ModeParser* ModeManager::getModeParser(const string &path) const size_t suffixLen = sizeof("xml") - 1; if (suffixLen < path.length() || path.compare(path.length() - suffixLen, suffixLen, "xml")) { - return new ModeXMLParser(path, ruleMgr, pluginMgr); + return new ModeXMLParser(path, ruleMgr); } else { ERR("Wrong path(%s)", path.c_str()); throw std::invalid_argument("Wrong path"); diff --git a/supervisor/ModeManager.h b/supervisor/ModeManager.h index cc0c142..4b71db6 100644 --- a/supervisor/ModeManager.h +++ b/supervisor/ModeManager.h @@ -20,7 +20,6 @@ #include #include "mdss.h" #include "ModeParser.h" -#include "PluginManager.h" #include "RuleManager.h" #include "ModeCareTaker.h" #include "ClientPrivilege.h" @@ -34,7 +33,7 @@ MODES_NAMESPACE_BEGIN class ModeManager { public: - ModeManager(RuleManager &rMgr, PluginManager &pMgr); + ModeManager(RuleManager &rMgr); void setOptions(const std::set &modeDirs, const std::string &xsdFile, const std::string &undoInfoDir); void init(); @@ -54,7 +53,6 @@ private: std::string undoDir; std::string modeSyntaxFile; RuleManager &ruleMgr; - PluginManager &pluginMgr; ModeCareTaker careTaker; #ifdef MDS_TEST diff --git a/supervisor/ModeXMLParser.cpp b/supervisor/ModeXMLParser.cpp index 17aba94..59e361e 100644 --- a/supervisor/ModeXMLParser.cpp +++ b/supervisor/ModeXMLParser.cpp @@ -28,8 +28,8 @@ MODES_NAMESPACE_USE; -ModeXMLParser::ModeXMLParser(const std::string &modeFile, RuleManager &rMgr, PluginManager &pMgr) - : ModeParser(rMgr), XMLParser(modeFile), pluginManager(pMgr), isParsedModeAttr(false) +ModeXMLParser::ModeXMLParser(const std::string &modeFile, RuleManager &rMgr) + : ModeParser(rMgr), XMLParser(modeFile), isParsedModeAttr(false) { } @@ -179,21 +179,19 @@ void ModeXMLParser::parseAction(xmlNodePtr node) Action* ModeXMLParser::parseActionInfo(xmlNodePtr node) { - char *ruleProp = (char*)xmlGetProp(node, ModesXMLTag::RULE); - if (ruleProp == NULL) { + char *ruleName = (char*)xmlGetProp(node, ModesXMLTag::RULE); + if (ruleName == NULL) { ERR("rule attribute is null! [%s]", ModesXMLTag::RULE); throw ModesEx(ModesEx::PARSER_ERROR, "rule attribute is null!"); } - Action *action = ruleMgr.createAction(ruleProp); + Action *action = ruleMgr.createAction(ruleName); if (action == nullptr) { - ERR("ruleMgr createAction(%s) Fail", ruleProp); - xmlFree(ruleProp); + ERR("ruleMgr createAction(%s) Fail", ruleName); + xmlFree(ruleName); throw ModesEx(ModesEx::PARSER_ERROR, "Action is null!"); } - - bindPlugin(ruleProp, action); - xmlFree(ruleProp); + xmlFree(ruleName); parseActionAttr(node, action); @@ -212,11 +210,3 @@ Action* ModeXMLParser::parseActionInfo(xmlNodePtr node) action->printInfo(); return action; } - -void ModeXMLParser::bindPlugin(const std::string &name, Action *action) -{ - std::string pluginName; - int pos = name.find_first_of("."); - pluginName = name.substr(0, pos); - action->setPlugin(pluginManager.getPlugin(pluginName)); -} diff --git a/supervisor/ModeXMLParser.h b/supervisor/ModeXMLParser.h index cc5db70..24518b1 100644 --- a/supervisor/ModeXMLParser.h +++ b/supervisor/ModeXMLParser.h @@ -20,13 +20,12 @@ #include "mdss.h" #include "ModeParser.h" #include "XMLParser.h" -#include "PluginManager.h" MODES_NAMESPACE_BEGIN class ModeXMLParser : public ModeParser, public XMLParser { public: - ModeXMLParser(const std::string &modeFile, RuleManager &mgr, PluginManager &pluginMgr); + ModeXMLParser(const std::string &modeFile, RuleManager &mgr); ~ModeXMLParser() = default; Mode getMode() override; @@ -45,10 +44,8 @@ private: void parseAction(xmlNodePtr node); void parseUndo(xmlNodePtr node); Action *parseActionInfo(xmlNodePtr node); - void bindPlugin(const std::string &name, Action *action); void parseModeAttr(); - PluginManager &pluginManager; Mode mode; std::string filePath; bool isParsedModeAttr; diff --git a/supervisor/PluginManager.cpp b/supervisor/PluginManager.cpp deleted file mode 100644 index 867f497..0000000 --- a/supervisor/PluginManager.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "PluginManager.h" - -#include -#include -#include -#include -#include -#include "mdss.h" -#include "ModesEx.h" - -MODES_NAMESPACE_USE; - -#define EMPTY_PLUGIN_PAIR std::make_pair(nullptr, nullptr) - -void PluginManager::setPluginDir(const std::string &dir) -{ - pluginDir = dir; -} - -int PluginManager::loadPlugins() -{ - DIR *dir; - if ((dir = opendir(pluginDir.c_str())) == NULL) { - ERR("opendir(%s) Fail(%s)", pluginDir.c_str(), strerror(errno)); - throw ModesEx(ModesEx::SYSTEM_ERROR); - } - - struct dirent *entry; - while ((entry = readdir(dir)) != NULL) { - std::string file(entry->d_name); - if (std::string::npos == file.find(MODES_PLUGIN_LIB_PREFIX)) //library validation - continue; - - std::string fileFullPath = pluginDir + "/" + file; - try { - PluginPair pluginPair = loadClass(fileFullPath); - DBG("loadClass(%s) OK", pluginPair.second->getName().c_str()); - - pluginMap[pluginPair.second->getName()] = pluginPair; - } - catch (ModesEx &e) { - ERR("loadClass(%s) Fail", fileFullPath.c_str()); - } - } - - closedir(dir); - - if (pluginMap.empty()) - return MODES_ERROR_NO_DATA; - - return MODES_ERROR_NONE; -} - -PluginManager::PluginPair PluginManager::loadClass(const std::string &pluginFile) -{ - void *handle = dlopen(pluginFile.c_str(), RTLD_LAZY); - if (NULL == handle) { - ERR("dlopen(%s) Fail(%s)", pluginFile.c_str(), dlerror()); - throw ModesEx(ModesEx::SYSTEM_ERROR); - } - - /* load the symbols */ - create_t *create_object_func = (create_t *) dlsym(handle, "objectCreate"); - if (NULL == create_object_func) { - ERR("dlsym(objectCreate) Fail(Plugin[%s] error[%s])", pluginFile.c_str(), dlerror()); - dlclose(handle); - throw ModesEx(ModesEx::SYSTEM_ERROR); - } - - /* create an instance of the class */ - Plugin *object = create_object_func(); - if (NULL == object) { - ERR("create_object_func(%s) Fail", pluginFile.c_str()); - dlclose(handle); - throw ModesEx(ModesEx::SYSTEM_ERROR); - } - - return std::make_pair(handle, object); -} - -int PluginManager::unloadClass(const PluginPair &pluginPair) -{ - void *handle = pluginPair.first; - Plugin *object = pluginPair.second; - std::string pluginName = object->getName(); - - RETVM_IF(NULL == handle, MODES_ERROR_SYSTEM, "handle(%s) is null", pluginName.c_str()); - - destroy_t *delete_object_func = (destroy_t *)dlsym(handle, "objectDelete"); - if (NULL == delete_object_func) { - ERR("dlsym(objectDelete) Fail(plugin[%s] error[%s])", pluginName.c_str(), dlerror()); - dlclose(handle); - return MODES_ERROR_SYSTEM; - } - - delete_object_func(object); - dlclose(handle); - - return MODES_ERROR_NONE; -} - - -int PluginManager::unloadPlugins() -{ - int ret = MODES_ERROR_NONE; - - for (auto it = pluginMap.begin(); it != pluginMap.end(); ++it) { - int rc = unloadClass(it->second); - if (rc != MODES_ERROR_NONE) { - ERR("unloadClass(%s) Fail", (it->first).c_str()); - ret = MODES_ERROR_SYSTEM; - } - } - pluginMap.clear(); - - return ret; -} - -std::list PluginManager::getPluginList() -{ - std::list list; - for (auto it = pluginMap.begin(); it != pluginMap.end(); ++it) { - list.push_back(it->first); - } - - return list; -} - -Plugin *PluginManager::getPlugin(std::string name) -{ - return pluginMap[name].second; -} diff --git a/supervisor/PluginManager.h b/supervisor/PluginManager.h deleted file mode 100644 index 15950bb..0000000 --- a/supervisor/PluginManager.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include -#include -#include -#include -#include -#include "mdss.h" -#include "Plugin.h" - -MODES_NAMESPACE_BEGIN - -class PluginManager { -public: - void setPluginDir(const std::string &dir_path); - int loadPlugins(); - int unloadPlugins(); - - std::list getPluginList(); - Plugin* getPlugin(std::string name); - - /*addDirChangeNotifier(); */ - /*dirChangeNotifierCallBack(); */ -private: - typedef std::pair PluginPair; - - PluginPair loadClass(const std::string &pluginFile); - int unloadClass(const PluginPair &pluginPair); - - std::string pluginDir; - std::unordered_map pluginMap; - -#ifdef MDS_TEST - friend class TestPluginBroker; -#endif -}; - -MODES_NAMESPACE_END diff --git a/supervisor/PluginMapper.cpp b/supervisor/PluginMapper.cpp new file mode 100644 index 0000000..fd0956a --- /dev/null +++ b/supervisor/PluginMapper.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "PluginMapper.h" + +#include +#include +#include +#include +#include +#include "mdss.h" +#include "ModesEx.h" + +MODES_NAMESPACE_USE; + +#define EMPTY_PLUGIN_PAIR std::make_pair(nullptr, nullptr) + +void PluginMapper::setPluginDir(const std::string &dir) +{ + pluginDir = dir; +} + +int PluginMapper::loadPlugins() +{ + DIR *dir; + if ((dir = opendir(pluginDir.c_str())) == NULL) { + ERR("opendir(%s) Fail(%s)", pluginDir.c_str(), strerror(errno)); + throw ModesEx(ModesEx::SYSTEM_ERROR); + } + + struct dirent *entry; + while ((entry = readdir(dir)) != NULL) { + std::string file(entry->d_name); + if (std::string::npos == file.find(MODES_PLUGIN_LIB_PREFIX)) //library validation + continue; + + std::string fileFullPath = pluginDir + "/" + file; + try { + PluginPair pluginPair = loadClass(fileFullPath); + DBG("loadClass(%s) OK", pluginPair.second->getName().c_str()); + + pluginMap[pluginPair.second->getName()] = pluginPair; + } + catch (ModesEx &e) { + ERR("loadClass(%s) Fail", fileFullPath.c_str()); + } + } + + closedir(dir); + + if (pluginMap.empty()) + return MODES_ERROR_NO_DATA; + + return MODES_ERROR_NONE; +} + +PluginMapper::PluginPair PluginMapper::loadClass(const std::string &pluginFile) +{ + void *handle = dlopen(pluginFile.c_str(), RTLD_LAZY); + if (NULL == handle) { + ERR("dlopen(%s) Fail(%s)", pluginFile.c_str(), dlerror()); + throw ModesEx(ModesEx::SYSTEM_ERROR); + } + + /* load the symbols */ + create_t *create_object_func = (create_t *) dlsym(handle, "objectCreate"); + if (NULL == create_object_func) { + ERR("dlsym(objectCreate) Fail(Plugin[%s] error[%s])", pluginFile.c_str(), dlerror()); + dlclose(handle); + throw ModesEx(ModesEx::SYSTEM_ERROR); + } + + /* create an instance of the class */ + Plugin *object = create_object_func(); + if (NULL == object) { + ERR("create_object_func(%s) Fail", pluginFile.c_str()); + dlclose(handle); + throw ModesEx(ModesEx::SYSTEM_ERROR); + } + + return std::make_pair(handle, object); +} + +int PluginMapper::unloadClass(const PluginPair &pluginPair) +{ + void *handle = pluginPair.first; + Plugin *object = pluginPair.second; + std::string pluginName = object->getName(); + + RETVM_IF(NULL == handle, MODES_ERROR_SYSTEM, "handle(%s) is null", pluginName.c_str()); + + destroy_t *delete_object_func = (destroy_t *)dlsym(handle, "objectDelete"); + if (NULL == delete_object_func) { + ERR("dlsym(objectDelete) Fail(plugin[%s] error[%s])", pluginName.c_str(), dlerror()); + dlclose(handle); + return MODES_ERROR_SYSTEM; + } + + delete_object_func(object); + dlclose(handle); + + return MODES_ERROR_NONE; +} + + +int PluginMapper::unloadPlugins() +{ + int ret = MODES_ERROR_NONE; + + for (auto it = pluginMap.begin(); it != pluginMap.end(); ++it) { + int rc = unloadClass(it->second); + if (rc != MODES_ERROR_NONE) { + ERR("unloadClass(%s) Fail", (it->first).c_str()); + ret = MODES_ERROR_SYSTEM; + } + } + pluginMap.clear(); + + return ret; +} + +std::list PluginMapper::getPluginList() +{ + std::list list; + for (auto it = pluginMap.begin(); it != pluginMap.end(); ++it) { + list.push_back(it->first); + } + + return list; +} + +Plugin *PluginMapper::getPlugin(std::string name) +{ + return pluginMap[name].second; +} diff --git a/supervisor/PluginMapper.h b/supervisor/PluginMapper.h new file mode 100644 index 0000000..98fe50c --- /dev/null +++ b/supervisor/PluginMapper.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include +#include +#include +#include +#include "mdss.h" +#include "Plugin.h" + +MODES_NAMESPACE_BEGIN + +class PluginMapper { +public: + void setPluginDir(const std::string &dir_path); + int loadPlugins(); + int unloadPlugins(); + + std::list getPluginList(); + Plugin* getPlugin(std::string name); + + /*addDirChangeNotifier(); */ + /*dirChangeNotifierCallBack(); */ +private: + typedef std::pair PluginPair; + + PluginPair loadClass(const std::string &pluginFile); + int unloadClass(const PluginPair &pluginPair); + + std::string pluginDir; + std::unordered_map pluginMap; + +#ifdef MDS_TEST + friend class TestPluginBroker; +#endif +}; + +MODES_NAMESPACE_END diff --git a/supervisor/RequestHandler.cpp b/supervisor/RequestHandler.cpp index 2f4d847..0c1c029 100644 --- a/supervisor/RequestHandler.cpp +++ b/supervisor/RequestHandler.cpp @@ -23,7 +23,6 @@ MODES_NAMESPACE_USE; ModeManager* RequestHandler::modeMgr = NULL; RuleManager *RequestHandler::ruleMgr = NULL; -PluginManager *RequestHandler::pluginMgr = NULL; void RequestHandler::setModeManager(ModeManager *mgr) { diff --git a/supervisor/RequestHandler.h b/supervisor/RequestHandler.h index 363e562..da5e061 100644 --- a/supervisor/RequestHandler.h +++ b/supervisor/RequestHandler.h @@ -44,7 +44,6 @@ private: static ModeManager *modeMgr; static RuleManager *ruleMgr; - static PluginManager *pluginMgr; }; MODES_NAMESPACE_END diff --git a/supervisor/RuleManager.cpp b/supervisor/RuleManager.cpp index 6047f47..b5f0d00 100644 --- a/supervisor/RuleManager.cpp +++ b/supervisor/RuleManager.cpp @@ -35,6 +35,18 @@ const xmlChar* const RuleManager::RULE_TAGS[] = { (xmlChar*)"privilege", }; +void RuleManager::start() +{ + piMapper.loadPlugins(); + makeRuleMap(); +} + +void RuleManager::stop() +{ + freeRuleMap(); + piMapper.unloadPlugins(); +} + void RuleManager::makeRuleMap() { if (ruleDir.empty()) { @@ -128,10 +140,11 @@ Action* RuleManager::createAction(const string &ruleName) } } -void RuleManager::setOptions(const string &actionRuleDir, const string &actionRuleXsd) +void RuleManager::setOptions(const string &actionRuleDir, const string &actionRuleXsd, const std::string &pluginDir) { ruleDir = actionRuleDir; ruleXsd = actionRuleXsd; + piMapper.setPluginDir(pluginDir); } void RuleManager::addBoolAlias(ActionRule *actionRule) @@ -142,13 +155,13 @@ void RuleManager::addBoolAlias(ActionRule *actionRule) ActionRule* RuleManager::makeRule(xmlNodePtr node) { - string type, name, plugin; + string type, name, pluginName; ActionRule *actionRule = NULL; try { name = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttName]); type = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttType]); - plugin = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttPlugin]); + pluginName = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttPlugin]); } catch (ModesEx &e) { ERR("extractValueOfTag() Fail(%s)", e.what()); throw; @@ -164,7 +177,7 @@ ActionRule* RuleManager::makeRule(xmlNodePtr node) } else { actionRule = new TActionRule(name); } - actionRule->setPlugin(plugin); + actionRule->setPlugin(piMapper.getPlugin(pluginName)); for (xmlNode *cur = node->children; cur; cur = cur->next) { if (xmlIsBlankNode(cur)) continue; diff --git a/supervisor/RuleManager.h b/supervisor/RuleManager.h index 50035f7..809a495 100644 --- a/supervisor/RuleManager.h +++ b/supervisor/RuleManager.h @@ -22,6 +22,7 @@ #include "ActionRule.h" #include "Action.h" #include "XMLParser.h" +#include "PluginMapper.h" MODES_NAMESPACE_BEGIN @@ -37,15 +38,17 @@ public: TagMax }; - void setOptions(const std::string &actionRuleDir, const std::string &actionRuleXsd); - void makeRuleMap(); - void freeRuleMap(); + void start(); + void stop(); + void setOptions(const std::string &actionRuleDir, const std::string &actionRuleXsd, const std::string &pluginDir); Action* createAction(const std::string &actionName); private: static const xmlChar* const ACTION_RULE_TAG; static const xmlChar* const ACTION_RULE_TAG_RULE; static const xmlChar* const RULE_TAGS[]; + void makeRuleMap(); + void freeRuleMap(); ActionRule* makeRule(xmlNodePtr node); void parseRule(xmlNodePtr node); void addBoolAlias(ActionRule * actionRule); @@ -55,7 +58,7 @@ private: std::map ruleMap; std::string ruleDir; std::string ruleXsd; - + PluginMapper piMapper; #ifdef MDS_TEST friend class RuleManagerTest; friend class ParserTest; diff --git a/supervisor/Supervisor.cpp b/supervisor/Supervisor.cpp index 92c4de2..79159e3 100644 --- a/supervisor/Supervisor.cpp +++ b/supervisor/Supervisor.cpp @@ -23,8 +23,8 @@ MODES_NAMESPACE_USE; -ModeSupervisorNamespace::Supervisor::Supervisor() - :modeMgr(ruleMgr, pluginMgr) +Supervisor::Supervisor() + : modeMgr(ruleMgr) { } @@ -35,8 +35,7 @@ void Supervisor::init() try { clientConn.startDbus(); - ruleMgr.makeRuleMap(); - pluginMgr.loadPlugins(); + ruleMgr.start(); modeMgr.init(); } catch (ModesEx &e) { @@ -46,8 +45,7 @@ void Supervisor::init() void Supervisor::deInit() { - pluginMgr.unloadPlugins(); - ruleMgr.freeRuleMap(); + ruleMgr.stop(); clientConn.stopDbus(); RequestHandler::setModeManager(NULL); RequestHandler::setRuleManager(NULL); @@ -56,8 +54,7 @@ void Supervisor::deInit() void Supervisor::setOptions(const ModesConfig &config) { modeMgr.setOptions(config.modeXMLDirs, config.modeXsdFile, config.undoInfoDir); - pluginMgr.setPluginDir(config.pluginDir); - ruleMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile); + ruleMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile, config.pluginDir); } void Supervisor::registerHandler() diff --git a/supervisor/Supervisor.h b/supervisor/Supervisor.h index 75dd23d..17424ac 100644 --- a/supervisor/Supervisor.h +++ b/supervisor/Supervisor.h @@ -19,7 +19,6 @@ #include "mdss.h" #include "ModeManager.h" #include "ModesConfig.h" -#include "PluginManager.h" #include "ClientConnection.h" #include "RuleManager.h" @@ -36,7 +35,6 @@ public: private: ClientConnection clientConn; RuleManager ruleMgr; - PluginManager pluginMgr; ModeManager modeMgr; }; diff --git a/supervisor/TActionRule.h b/supervisor/TActionRule.h index 6dea12c..a96625a 100644 --- a/supervisor/TActionRule.h +++ b/supervisor/TActionRule.h @@ -38,6 +38,7 @@ public: TAction *action = new TAction(ruleName); action->setValueAliases(valueAliasList); action->setPrivilege(privilege); + action->setPlugin(plugin); return action; } diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 14b5d25..88d3d5b 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -49,10 +49,10 @@ FILE(GLOB GTEST_MODEMGR_SRCS ${SUPERVISOR_DIR}/Action.cpp ${SUPERVISOR_DIR}/ActionRule.cpp ${SUPERVISOR_DIR}/RuleManager.cpp + ${SUPERVISOR_DIR}/PluginMapper.cpp ${SUPERVISOR_DIR}/ClientPrivilege.cpp ${SUPERVISOR_DIR}/Mode.cpp ${SUPERVISOR_DIR}/ModesEx.cpp - ${SUPERVISOR_DIR}/PluginManager.cpp ${SUPERVISOR_DIR}/ValueChecker.cpp modes_test_modemgr.cpp ) @@ -64,7 +64,7 @@ INSTALL(TARGETS ${GTEST_MODEMGR} DESTINATION ${TEST_INSTALL_DIR}) #=======================================================================================# SET(GTEST_PLUGIN "modes-gtest-plugin") FILE(GLOB GTEST_PLUGIN_SRCS - ${SUPERVISOR_DIR}/PluginManager.cpp + ${SUPERVISOR_DIR}/PluginMapper.cpp ${SUPERVISOR_DIR}/ModesEx.cpp modes_test_plugin.cpp ) @@ -76,11 +76,11 @@ INSTALL(TARGETS ${GTEST_PLUGIN} DESTINATION ${TEST_INSTALL_DIR}) SET(GTEST_PARSER "modes-gtest-parser") FILE(GLOB GTEST_PARSER_SRCS ${SUPERVISOR_DIR}/XMLParser.cpp - ${SUPERVISOR_DIR}/PluginManager.cpp ${SUPERVISOR_DIR}/ClientPrivilege.cpp ${SUPERVISOR_DIR}/Action.cpp ${SUPERVISOR_DIR}/ActionRule.cpp ${SUPERVISOR_DIR}/RuleManager.cpp + ${SUPERVISOR_DIR}/PluginMapper.cpp ${SUPERVISOR_DIR}/ModeXMLParser.cpp ${SUPERVISOR_DIR}/ModesEx.cpp ${SUPERVISOR_DIR}/Mode.cpp @@ -102,9 +102,9 @@ FILE(GLOB GTEST_GENERATOR_SRCS ${SUPERVISOR_DIR}/Mode.cpp ${SUPERVISOR_DIR}/Action.cpp ${SUPERVISOR_DIR}/ModesEx.cpp - ${SUPERVISOR_DIR}/PluginManager.cpp ${SUPERVISOR_DIR}/ClientPrivilege.cpp ${SUPERVISOR_DIR}/RuleManager.cpp + ${SUPERVISOR_DIR}/PluginMapper.cpp ${SUPERVISOR_DIR}/ActionRule.cpp ${SUPERVISOR_DIR}/ValueChecker.cpp "modes_test_generator.cpp" @@ -127,8 +127,8 @@ FILE(GLOB GTEST_CONFLICT_SRCS ${SUPERVISOR_DIR}/ModesEx.cpp ${SUPERVISOR_DIR}/ClientPrivilege.cpp ${SUPERVISOR_DIR}/ModesXMLTag.cpp - ${SUPERVISOR_DIR}/PluginManager.cpp ${SUPERVISOR_DIR}/RuleManager.cpp + ${SUPERVISOR_DIR}/PluginMapper.cpp ${SUPERVISOR_DIR}/ActionRule.cpp ${SUPERVISOR_DIR}/ValueChecker.cpp modes_test_conflict.cpp @@ -141,6 +141,7 @@ INSTALL(TARGETS ${GTEST_CONFLICT} DESTINATION ${TEST_INSTALL_DIR}) SET(GTEST_RULEMGR "modes-gtest-rulemgr") FILE(GLOB GTEST_RULE_SRCS ${SUPERVISOR_DIR}/RuleManager.cpp + ${SUPERVISOR_DIR}/PluginMapper.cpp ${SUPERVISOR_DIR}/XMLParser.cpp ${SUPERVISOR_DIR}/ActionRule.cpp ${SUPERVISOR_DIR}/ModesEx.cpp @@ -152,5 +153,5 @@ FILE(GLOB GTEST_RULE_SRCS ) ADD_EXECUTABLE(${GTEST_RULEMGR} ${SRC} ${GTEST_RULE_SRCS}) ADD_DEPENDENCIES(${GTEST_RULEMGR} GENERATED_DBUS_CODE) -TARGET_LINK_LIBRARIES(${GTEST_RULEMGR} ${gtest_pkgs_LIBRARIES}) +TARGET_LINK_LIBRARIES(${GTEST_RULEMGR} ${gtest_pkgs_LIBRARIES} dl) INSTALL(TARGETS ${GTEST_RULEMGR} DESTINATION ${TEST_INSTALL_DIR}) diff --git a/unittest/modes_test_conflict.cpp b/unittest/modes_test_conflict.cpp index 91e56a6..d0e83ef 100644 --- a/unittest/modes_test_conflict.cpp +++ b/unittest/modes_test_conflict.cpp @@ -27,7 +27,7 @@ public: protected: void SetUp() override { - ModeXMLParser modeparser("tizen_conflict1_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_conflict1_mode.xml", ruleMgr); careTaker.pushMode(modeparser.getMode()); } @@ -37,7 +37,6 @@ protected: careTaker.popMode("conflict1", mode); } - PluginManager piMgr; RuleManager ruleMgr; ModeCareTaker careTaker; }; @@ -48,23 +47,24 @@ ConflictTest::ConflictTest() config.actionRuleDir = "."; config.actionRuleXsdFile = "./" MODES_ACTIONRULE_DEFAULT_XSD_FILE; config.undoInfoDir = "."; + config.undoInfoDir = "."; - ruleMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile); - ruleMgr.makeRuleMap(); + ruleMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile, "."); + ruleMgr.start(); careTaker.setOptions(config.undoInfoDir); } TEST_F(ConflictTest, isSavedMode) { - ModeXMLParser modeparser("tizen_conflict1_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_conflict1_mode.xml", ruleMgr); EXPECT_TRUE(careTaker.isSavedMode(modeparser.getModeName())); } TEST_F(ConflictTest, isExcluded) { - ModeXMLParser modeparser("tizen_conflict3_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_conflict3_mode.xml", ruleMgr); careTaker.pushMode(modeparser.getMode()); EXPECT_TRUE(careTaker.isExclusive()); @@ -76,7 +76,7 @@ TEST_F(ConflictTest, isExcluded) TEST_F(ConflictTest, checkConflictAction) { - ModeXMLParser modeparser("tizen_conflict2_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_conflict2_mode.xml", ruleMgr); Mode mode = modeparser.getMode(); EXPECT_TRUE(careTaker.checkConflictAction(mode)); @@ -86,6 +86,6 @@ TEST_F(ConflictTest, isConflict) { ConflictManager conflMgr(careTaker); - ModeXMLParser modeparser("tizen_conflict2_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_conflict2_mode.xml", ruleMgr); EXPECT_TRUE(conflMgr.isConflict(modeparser.getMode())); } diff --git a/unittest/modes_test_generator.cpp b/unittest/modes_test_generator.cpp index cf4e509..3fd35d1 100644 --- a/unittest/modes_test_generator.cpp +++ b/unittest/modes_test_generator.cpp @@ -31,7 +31,6 @@ class GeneratorTest { public: GeneratorTest(); RuleManager ruleMgr; - PluginManager piMgr; }; MODES_NAMESPACE_END @@ -40,16 +39,17 @@ GeneratorTest::GeneratorTest() ModesConfig config; config.actionRuleDir = "."; config.actionRuleXsdFile = "./" MODES_ACTIONRULE_DEFAULT_XSD_FILE; + config.pluginDir = "."; - ruleMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile); - ruleMgr.makeRuleMap(); + ruleMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile, config.pluginDir); + ruleMgr.start(); } TEST(XMLGenerator, makeModeXML) { GeneratorTest broker; - ModeXMLParser modeparser("tizen_ex1_mode.xml", broker.ruleMgr, broker.piMgr); + ModeXMLParser modeparser("tizen_ex1_mode.xml", broker.ruleMgr); Mode mode = modeparser.getMode(); try { @@ -60,7 +60,7 @@ TEST(XMLGenerator, makeModeXML) FAIL(); } - ModeXMLParser genmodeparser("tizen_gen_ex1_mode.xml", broker.ruleMgr, broker.piMgr); + ModeXMLParser genmodeparser("tizen_gen_ex1_mode.xml", broker.ruleMgr); Mode genMode = genmodeparser.getMode(); EXPECT_EQ("ex1", genmodeparser.getModeName()); @@ -78,7 +78,7 @@ TEST(XMLGenerator, exFileName) { GeneratorTest broker; - ModeXMLParser modeparser("tizen_ex1_mode.xml", broker.ruleMgr, broker.piMgr); + ModeXMLParser modeparser("tizen_ex1_mode.xml", broker.ruleMgr); Mode mode = modeparser.getMode(); EXPECT_THROW({ diff --git a/unittest/modes_test_modemgr.cpp b/unittest/modes_test_modemgr.cpp index a437392..872f2bf 100644 --- a/unittest/modes_test_modemgr.cpp +++ b/unittest/modes_test_modemgr.cpp @@ -27,7 +27,7 @@ class ModeManagerTest { public: ModeManagerTest(); RuleManager rMgr; - PluginManager pMgr; + PluginMapper pMgr; ModeManager mdMgr; set getDirectories(); @@ -37,7 +37,7 @@ public: MODES_NAMESPACE_END ModeManagerTest::ModeManagerTest() - : mdMgr(rMgr, pMgr) + : mdMgr(rMgr) { ModesConfig config; config.modeXMLDirs.insert("."); diff --git a/unittest/modes_test_parser.cpp b/unittest/modes_test_parser.cpp index ea4fece..28248b8 100644 --- a/unittest/modes_test_parser.cpp +++ b/unittest/modes_test_parser.cpp @@ -42,7 +42,6 @@ protected: { } - PluginManager piMgr; RuleManager ruleMgr; }; MODES_NAMESPACE_END @@ -52,8 +51,9 @@ ParserTest::ParserTest() ModesConfig config; config.actionRuleDir = "."; config.actionRuleXsdFile = "./" MODES_ACTIONRULE_DEFAULT_XSD_FILE; + config.pluginDir = "."; - ruleMgr.setOptions(std::string(), config.actionRuleXsdFile); + ruleMgr.setOptions(std::string(), config.actionRuleXsdFile, config.pluginDir); ruleMgr.parseActionRule("./tizen_ex_rule.xml"); } @@ -64,42 +64,42 @@ list> ParserTest::getActionList(Mode& m) TEST_F(ParserTest, getModeName) { - ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr); EXPECT_EQ("ex1", modeparser.getModeName()); } TEST_F(ParserTest, modeGetName) { - ModeXMLParser modeparser("tizen_ex2_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_ex2_mode.xml", ruleMgr); Mode mode = modeparser.getMode(); EXPECT_EQ("ex2", mode.getName()); } TEST_F(ParserTest, isHiddenTrue) { - ModeXMLParser modeparser("tizen_ex2_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_ex2_mode.xml", ruleMgr); EXPECT_EQ(true, modeparser.isHidden()); } TEST_F(ParserTest, isHiddenFalse) { - ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr); EXPECT_EQ(false, modeparser.isHidden()); } TEST_F(ParserTest, getModeType) { - ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr); Mode mode = modeparser.getMode(); EXPECT_EQ(Mode::MODE_NORMAL, mode.getModeType()); } TEST_F(ParserTest, printAction) { - ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr); Mode mode = modeparser.getMode(); list> actionList = getActionList(mode); @@ -114,10 +114,10 @@ TEST_F(ParserTest, printAction) TEST_F(ParserTest, invalidActionValue) { - ModeXMLParser modeparser1("tizen_invalid1_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser1("tizen_invalid1_mode.xml", ruleMgr); EXPECT_THROW(modeparser1.getMode(), ModesEx); - ModeXMLParser modeparser2("tizen_invalid2_mode.xml", ruleMgr, piMgr); + ModeXMLParser modeparser2("tizen_invalid2_mode.xml", ruleMgr); EXPECT_THROW(modeparser2.getMode(), ModesEx); } diff --git a/unittest/modes_test_plugin.cpp b/unittest/modes_test_plugin.cpp index bc1b59c..6af5d73 100644 --- a/unittest/modes_test_plugin.cpp +++ b/unittest/modes_test_plugin.cpp @@ -15,7 +15,7 @@ */ #include #include -#include "supervisor/PluginManager.h" +#include "supervisor/PluginMapper.h" #include "supervisor/ModesEx.h" using namespace std; @@ -26,7 +26,7 @@ public: bool emptyPluginMap(); string getpluginDir(); - PluginManager pMgr; + PluginMapper piMapper; }; MODES_NAMESPACE_END @@ -34,30 +34,30 @@ MODES_NAMESPACE_USE; bool TestPluginBroker::emptyPluginMap() { - return pMgr.pluginMap.empty(); + return piMapper.pluginMap.empty(); } string TestPluginBroker::getpluginDir() { - return pMgr.pluginDir; + return piMapper.pluginDir; } -TEST(PluginManager, readLibraryList) +TEST(PluginMapper, readLibraryList) { TestPluginBroker broker; - broker.pMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR); + broker.piMapper.setPluginDir(MODES_PLUGIN_DEFAULT_DIR); try { - broker.pMgr.loadPlugins(); + broker.piMapper.loadPlugins(); } catch (ModesEx &e) { - broker.pMgr.setPluginDir("../plugin"); - EXPECT_NO_THROW(broker.pMgr.loadPlugins()); + broker.piMapper.setPluginDir("../plugin"); + EXPECT_NO_THROW(broker.piMapper.loadPlugins()); } EXPECT_FALSE(broker.emptyPluginMap()); - list pluginList = broker.pMgr.getPluginList(); + list pluginList = broker.piMapper.getPluginList(); if (pluginList.empty()) { FAIL() << "getPluginList() Fail:This should never be reached"; } else { @@ -66,42 +66,42 @@ TEST(PluginManager, readLibraryList) } } -TEST(PluginManager, setPluginDir) +TEST(PluginMapper, setPluginDir) { TestPluginBroker broker; string path = "../plugin"; - broker.pMgr.setPluginDir(path); + broker.piMapper.setPluginDir(path); EXPECT_EQ(path, broker.getpluginDir()); } -TEST(PluginManager, unloadClassMap) +TEST(PluginMapper, unloadClassMap) { TestPluginBroker broker; - int ret = broker.pMgr.unloadPlugins(); + int ret = broker.piMapper.unloadPlugins(); EXPECT_EQ(ret, MODES_ERROR_NONE); EXPECT_TRUE(broker.emptyPluginMap()); } -TEST(PluginManager, getPluginTest) +TEST(PluginMapper, getPluginTest) { int ret; TestPluginBroker broker; - broker.pMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR); + broker.piMapper.setPluginDir(MODES_PLUGIN_DEFAULT_DIR); try { - broker.pMgr.loadPlugins(); + broker.piMapper.loadPlugins(); } catch (ModesEx &e) { - broker.pMgr.setPluginDir("../plugin"); - EXPECT_NO_THROW(broker.pMgr.loadPlugins()); + broker.piMapper.setPluginDir("../plugin"); + EXPECT_NO_THROW(broker.piMapper.loadPlugins()); } EXPECT_FALSE(broker.emptyPluginMap()); - Plugin *plugin = broker.pMgr.getPlugin("test"); + Plugin *plugin = broker.piMapper.getPlugin("test"); ASSERT_TRUE(plugin != NULL); ret = plugin->set("testSetInt", 0, nullptr); @@ -128,7 +128,7 @@ TEST(PluginManager, getPluginTest) string strVal = plugin->getString("testGetString"); EXPECT_EQ(strVal, "test"); - ret = broker.pMgr.unloadPlugins(); + ret = broker.piMapper.unloadPlugins(); EXPECT_EQ(ret, MODES_ERROR_NONE); EXPECT_TRUE(broker.emptyPluginMap()); } diff --git a/unittest/modes_test_rulemgr.cpp b/unittest/modes_test_rulemgr.cpp index ed67672..a5c25ba 100644 --- a/unittest/modes_test_rulemgr.cpp +++ b/unittest/modes_test_rulemgr.cpp @@ -44,14 +44,15 @@ RuleManagerTest::RuleManagerTest() ModesConfig config; config.actionRuleDir = "."; config.actionRuleXsdFile = "./" MODES_ACTIONRULE_DEFAULT_XSD_FILE; + config.pluginDir = "."; - rMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile); + rMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile, config.pluginDir); } TEST(RuleManagerTest, makeRuleMapP) { RuleManagerTest testBroker; - EXPECT_NO_THROW(testBroker.rMgr.makeRuleMap()); + EXPECT_NO_THROW(testBroker.rMgr.start()); } TEST(RuleManagerTest, parseActionRuleP)