clean up code and revise example
authorYoungjae Shin <yj99.shin@samsung.com>
Tue, 29 Oct 2019 09:49:37 +0000 (18:49 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
example/mode/tizen_ex1_mode.xml
packaging/modes.spec
supervisor/Action.cpp
supervisor/RequestHandler.cpp
supervisor/RuleManager.cpp
supervisor/RuleManager.h
supervisor/XMLParser.h

index 9887d3a..9de72ed 100644 (file)
@@ -8,5 +8,6 @@
     <action rule="test.player" after="BMJ">beatles-yesterday.mp3</action>
     <action ID="1" rule="test.printInt" priority="-100"
          >PRINT_TWO</action>
+    <undo ID="undo1" rule="test.printBool">true</undo>
   </mode>
 </tizenModes>
index f413f62..4076a9a 100644 (file)
@@ -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
index 0b1f6a9..c4e6d6d 100644 (file)
@@ -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()
index ce2f727..8cf7a54 100644 (file)
@@ -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<std::tuple<std::string, int>> 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;
 }
 
index f12a5a2..5a56c9d 100644 (file)
@@ -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;
        }
 
index 7b82a7d..15c80eb 100644 (file)
@@ -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);
index a64a2ce..a7dbb2b 100644 (file)
@@ -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;