From 1c3bdef81ad8f821fb5ddc82ec266e993668465c Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Tue, 29 Oct 2019 18:49:37 +0900 Subject: [PATCH] clean up code and revise example --- example/mode/tizen_ex1_mode.xml | 1 + packaging/modes.spec | 6 ++---- supervisor/Action.cpp | 8 ++++---- supervisor/RequestHandler.cpp | 7 ++++--- supervisor/RuleManager.cpp | 25 ++++--------------------- supervisor/RuleManager.h | 1 - supervisor/XMLParser.h | 5 ++--- 7 files changed, 17 insertions(+), 36 deletions(-) diff --git a/example/mode/tizen_ex1_mode.xml b/example/mode/tizen_ex1_mode.xml index 9887d3a..9de72ed 100644 --- a/example/mode/tizen_ex1_mode.xml +++ b/example/mode/tizen_ex1_mode.xml @@ -8,5 +8,6 @@ beatles-yesterday.mp3 PRINT_TWO + true diff --git a/packaging/modes.spec b/packaging/modes.spec index f413f62..4076a9a 100644 --- a/packaging/modes.spec +++ b/packaging/modes.spec @@ -137,10 +137,8 @@ systemctl restart %{name}.service %{modes_data_dir}/schema/* %dir %{modes_data_dir}/mode %dir %{modes_data_dir}/rule -%dir %{modes_info_dir}/undo-info -%attr(0755,system_fw,system_fw) %{modes_info_dir}/undo-info -%dir %{modes_data_dir}/custom-mode -%attr(0755,system_fw,system_fw) %{modes_data_dir}/custom-mode +%dir %attr(0755,system_fw,system_fw) %{modes_info_dir}/undo-info +%dir %attr(0755,system_fw,system_fw) %{modes_data_dir}/custom-mode %license LICENSE.APLv2 %files lib diff --git a/supervisor/Action.cpp b/supervisor/Action.cpp index 0b1f6a9..c4e6d6d 100644 --- a/supervisor/Action.cpp +++ b/supervisor/Action.cpp @@ -23,10 +23,10 @@ MODES_NAMESPACE_USE; void Action::valueChangedCallback(const std::string &key, void *userData) { Action *action = (Action*)userData; - if (action->getRuleName() == key) { - action->setIsChanged(); - DBG("Action(%s) Changed", key.c_str()); - } + RET_IF(NULL == action); + + action->setIsChanged(); + DBG("Action(%s) Changed", key.c_str()); } Action::Action() diff --git a/supervisor/RequestHandler.cpp b/supervisor/RequestHandler.cpp index ce2f727..8cf7a54 100644 --- a/supervisor/RequestHandler.cpp +++ b/supervisor/RequestHandler.cpp @@ -88,13 +88,14 @@ gboolean RequestHandler::registerModeHandler(mdsDbus *object, GDBusMethodInvocat gboolean RequestHandler::getModesHandler(mdsDbus *object, GDBusMethodInvocation *invocation, gpointer userData) { + int ret = MODES_ERROR_NONE; + RETV_IF(NULL == modeMgr, FALSE); std::list> modeList = modeMgr->getModes(); if (modeList.empty()) { ERR("getModes() : No Data"); - mds_dbus_complete_get_modes(object, invocation, NULL, MODES_ERROR_NO_DATA); - return TRUE; + ret = MODES_ERROR_NO_DATA; } GVariantBuilder *modeListBuilder = g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_GET_MODES_SIG)); @@ -108,7 +109,7 @@ gboolean RequestHandler::getModesHandler(mdsDbus *object, GDBusMethodInvocation GVariant *outList = g_variant_new(MODES_DBUS_GET_MODES_SIG, modeListBuilder); g_variant_builder_unref(modeListBuilder); - mds_dbus_complete_get_modes(object, invocation, outList, MODES_ERROR_NONE); + mds_dbus_complete_get_modes(object, invocation, outList, ret); return TRUE; } diff --git a/supervisor/RuleManager.cpp b/supervisor/RuleManager.cpp index f12a5a2..5a56c9d 100644 --- a/supervisor/RuleManager.cpp +++ b/supervisor/RuleManager.cpp @@ -126,23 +126,6 @@ void RuleManager::setOptions(const string &actionRuleDir, const string &actionRu ruleXsd = actionRuleXsd; } -string RuleManager::getProp(xmlNodePtr node, int att) -{ - char *tmp; - string returnStr; - - tmp = (char*)xmlGetProp(node, RULE_TAGS[att]); - if (tmp) { - returnStr = tmp; - xmlFree(tmp); - } else { - ERR("Rule : No %s", RULE_TAGS[att]); - throw ModesEx(ModesEx::NO_DATA); - } - - return returnStr; -} - void RuleManager::addBoolAlias(ActionRule *actionRule) { actionRule->addAlias("true", "1"); @@ -155,11 +138,11 @@ ActionRule* RuleManager::makeRule(xmlNodePtr node) ActionRule *actionRule = NULL; try { - name = getProp(node, TagAttName); - type = getProp(node, TagAttType); - plugin = getProp(node, TagAttPlugin); + name = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttName]); + type = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttType]); + plugin = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttPlugin]); } catch (ModesEx &e) { - ERR("getProp() Fail(%s)", e.what()); + ERR("extractValueOfTag() Fail(%s)", e.what()); throw; } diff --git a/supervisor/RuleManager.h b/supervisor/RuleManager.h index 7b82a7d..15c80eb 100644 --- a/supervisor/RuleManager.h +++ b/supervisor/RuleManager.h @@ -47,7 +47,6 @@ private: ActionRule* makeRule(xmlNodePtr node); void parseRule(xmlNodePtr node); - std::string getProp(xmlNodePtr node, int att); void addBoolAlias(ActionRule * actionRule); void parseActionRule(const std::string &xmlFile); void parseElement(xmlNodePtr node, ActionRule *actionRule); diff --git a/supervisor/XMLParser.h b/supervisor/XMLParser.h index a64a2ce..a7dbb2b 100644 --- a/supervisor/XMLParser.h +++ b/supervisor/XMLParser.h @@ -26,10 +26,9 @@ public: XMLParser(const std::string &xmlFile); ~XMLParser(); - void validate(const std::string &xsd); - std::string extractValueOfTag(xmlNodePtr node, const xmlChar * tag); xmlNodePtr getRoot(); - + void validate(const std::string &xsd); + static std::string extractValueOfTag(xmlNodePtr node, const xmlChar *tag); private: xmlDocPtr doc; xmlNodePtr root; -- 2.7.4