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;
}
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<std::string> conflictActionList;
//std::string description;
using std::string;
MODES_NAMESPACE_USE;
-ModeManager::ModeManager(RuleManager &rMgr, PluginManager &pMgr)
- : ruleMgr(rMgr), pluginMgr(pMgr)
+ModeManager::ModeManager(RuleManager &rMgr)
+ : ruleMgr(rMgr)
{
}
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");
#include <set>
#include "mdss.h"
#include "ModeParser.h"
-#include "PluginManager.h"
#include "RuleManager.h"
#include "ModeCareTaker.h"
#include "ClientPrivilege.h"
class ModeManager {
public:
- ModeManager(RuleManager &rMgr, PluginManager &pMgr);
+ ModeManager(RuleManager &rMgr);
void setOptions(const std::set<std::string> &modeDirs, const std::string &xsdFile, const std::string &undoInfoDir);
void init();
std::string undoDir;
std::string modeSyntaxFile;
RuleManager &ruleMgr;
- PluginManager &pluginMgr;
ModeCareTaker careTaker;
#ifdef MDS_TEST
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)
{
}
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);
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));
-}
#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;
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;
+++ /dev/null
-/*
- * 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 <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-#include <dlfcn.h>
-#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<std::string> PluginManager::getPluginList()
-{
- std::list<std::string> 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;
-}
+++ /dev/null
-/*
- * 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 <iostream>
-#include <new>
-#include <list>
-#include <utility>
-#include <unordered_map>
-#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<std::string> getPluginList();
- Plugin* getPlugin(std::string name);
-
- /*addDirChangeNotifier(); */
- /*dirChangeNotifierCallBack(); */
-private:
- typedef std::pair<void*, Plugin*> PluginPair;
-
- PluginPair loadClass(const std::string &pluginFile);
- int unloadClass(const PluginPair &pluginPair);
-
- std::string pluginDir;
- std::unordered_map<std::string, PluginPair> pluginMap;
-
-#ifdef MDS_TEST
- friend class TestPluginBroker;
-#endif
-};
-
-MODES_NAMESPACE_END
--- /dev/null
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <errno.h>
+#include <dlfcn.h>
+#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<std::string> PluginMapper::getPluginList()
+{
+ std::list<std::string> 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;
+}
--- /dev/null
+/*
+ * 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 <iostream>
+#include <new>
+#include <list>
+#include <utility>
+#include <unordered_map>
+#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<std::string> getPluginList();
+ Plugin* getPlugin(std::string name);
+
+ /*addDirChangeNotifier(); */
+ /*dirChangeNotifierCallBack(); */
+private:
+ typedef std::pair<void*, Plugin*> PluginPair;
+
+ PluginPair loadClass(const std::string &pluginFile);
+ int unloadClass(const PluginPair &pluginPair);
+
+ std::string pluginDir;
+ std::unordered_map<std::string, PluginPair> pluginMap;
+
+#ifdef MDS_TEST
+ friend class TestPluginBroker;
+#endif
+};
+
+MODES_NAMESPACE_END
ModeManager* RequestHandler::modeMgr = NULL;
RuleManager *RequestHandler::ruleMgr = NULL;
-PluginManager *RequestHandler::pluginMgr = NULL;
void RequestHandler::setModeManager(ModeManager *mgr)
{
static ModeManager *modeMgr;
static RuleManager *ruleMgr;
- static PluginManager *pluginMgr;
};
MODES_NAMESPACE_END
(xmlChar*)"privilege",
};
+void RuleManager::start()
+{
+ piMapper.loadPlugins();
+ makeRuleMap();
+}
+
+void RuleManager::stop()
+{
+ freeRuleMap();
+ piMapper.unloadPlugins();
+}
+
void RuleManager::makeRuleMap()
{
if (ruleDir.empty()) {
}
}
-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)
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;
} else {
actionRule = new TActionRule<string>(name);
}
- actionRule->setPlugin(plugin);
+ actionRule->setPlugin(piMapper.getPlugin(pluginName));
for (xmlNode *cur = node->children; cur; cur = cur->next) {
if (xmlIsBlankNode(cur))
continue;
#include "ActionRule.h"
#include "Action.h"
#include "XMLParser.h"
+#include "PluginMapper.h"
MODES_NAMESPACE_BEGIN
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);
std::map<std::string, ActionRule*> ruleMap;
std::string ruleDir;
std::string ruleXsd;
-
+ PluginMapper piMapper;
#ifdef MDS_TEST
friend class RuleManagerTest;
friend class ParserTest;
MODES_NAMESPACE_USE;
-ModeSupervisorNamespace::Supervisor::Supervisor()
- :modeMgr(ruleMgr, pluginMgr)
+Supervisor::Supervisor()
+ : modeMgr(ruleMgr)
{
}
try {
clientConn.startDbus();
- ruleMgr.makeRuleMap();
- pluginMgr.loadPlugins();
+ ruleMgr.start();
modeMgr.init();
}
catch (ModesEx &e) {
void Supervisor::deInit()
{
- pluginMgr.unloadPlugins();
- ruleMgr.freeRuleMap();
+ ruleMgr.stop();
clientConn.stopDbus();
RequestHandler::setModeManager(NULL);
RequestHandler::setRuleManager(NULL);
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()
#include "mdss.h"
#include "ModeManager.h"
#include "ModesConfig.h"
-#include "PluginManager.h"
#include "ClientConnection.h"
#include "RuleManager.h"
private:
ClientConnection clientConn;
RuleManager ruleMgr;
- PluginManager pluginMgr;
ModeManager modeMgr;
};
TAction<T> *action = new TAction<T>(ruleName);
action->setValueAliases(valueAliasList);
action->setPrivilege(privilege);
+ action->setPlugin(plugin);
return action;
}
${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
)
#=======================================================================================#
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
)
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
${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"
${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
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
)
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})
protected:
void SetUp() override
{
- ModeXMLParser modeparser("tizen_conflict1_mode.xml", ruleMgr, piMgr);
+ ModeXMLParser modeparser("tizen_conflict1_mode.xml", ruleMgr);
careTaker.pushMode(modeparser.getMode());
}
careTaker.popMode("conflict1", mode);
}
- PluginManager piMgr;
RuleManager ruleMgr;
ModeCareTaker careTaker;
};
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());
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));
{
ConflictManager conflMgr(careTaker);
- ModeXMLParser modeparser("tizen_conflict2_mode.xml", ruleMgr, piMgr);
+ ModeXMLParser modeparser("tizen_conflict2_mode.xml", ruleMgr);
EXPECT_TRUE(conflMgr.isConflict(modeparser.getMode()));
}
public:
GeneratorTest();
RuleManager ruleMgr;
- PluginManager piMgr;
};
MODES_NAMESPACE_END
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 {
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());
{
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({
public:
ModeManagerTest();
RuleManager rMgr;
- PluginManager pMgr;
+ PluginMapper pMgr;
ModeManager mdMgr;
set<string> getDirectories();
MODES_NAMESPACE_END
ModeManagerTest::ModeManagerTest()
- : mdMgr(rMgr, pMgr)
+ : mdMgr(rMgr)
{
ModesConfig config;
config.modeXMLDirs.insert(".");
{
}
- PluginManager piMgr;
RuleManager ruleMgr;
};
MODES_NAMESPACE_END
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");
}
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<std::shared_ptr<Action>> actionList = getActionList(mode);
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);
}
*/
#include <iostream>
#include <gtest/gtest.h>
-#include "supervisor/PluginManager.h"
+#include "supervisor/PluginMapper.h"
#include "supervisor/ModesEx.h"
using namespace std;
bool emptyPluginMap();
string getpluginDir();
- PluginManager pMgr;
+ PluginMapper piMapper;
};
MODES_NAMESPACE_END
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<string> pluginList = broker.pMgr.getPluginList();
+ list<string> pluginList = broker.piMapper.getPluginList();
if (pluginList.empty()) {
FAIL() << "getPluginList() Fail:This should never be reached";
} else {
}
}
-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);
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());
}
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)