Add action after undo mode.
authorJinWang An <jinwang.an@samsung.com>
Fri, 20 Sep 2019 05:57:28 +0000 (14:57 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
21 files changed:
example/mode/tizen_btAudioConnect_mode.xml
example/mode/tizen_btOff_mode.xml
example/mode/tizen_btOn_mode.xml
example/mode/tizen_conflict1_mode.xml
example/mode/tizen_conflict2_mode.xml
example/mode/tizen_conflict3_mode.xml
example/mode/tizen_ex1_mode.xml
example/mode/tizen_ex2_mode.xml
example/mode/tizen_powerSave_mode.xml
example/mode/tizen_waterlock_mode.xml [new file with mode: 0644]
example/mode/tizen_wifiOn_mode.xml
example/rule/tizen_ex_rule.xml
example/rule/tizen_ex_rule_fail.xml
schema/tizen_mode.xsd
supervisor/Mode.cpp
supervisor/Mode.h
supervisor/ModeTag.cpp
supervisor/ModeTag.h
supervisor/ModeXMLParser.cpp
supervisor/ModeXMLParser.h
unittest/modes_test_client.cpp

index 97404313fb919471700bb69c3eba26f4afa912bd..d45e639333a380a894be622cee556e9459890d76 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="btAudioConnect" type="exclusive">
     <action rule="bluetooth.power">on</action>
     <action rule="bluetooth.audioConnect">08:AE:D6:5E:AE:16</action>
index fcb1c3f6427971bab7d8c63cf1fbab6cafc91a00..0c29375444006d2c6b8eb53ddbe50afeb2904089 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="btOff" type="exclusive">
     <action rule="bluetooth.power">off</action>
   </mode>
index e1cf681e2274a984043316eba970626eb38e93f6..14ee9e299dee4d84d90c9707bcf7e178130cb53e 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="btOn" type="exclusive">
     <action rule="bluetooth.power">on</action>
   </mode>
index 12a81ea31f388ce066b7fb8dc61f220449503342..5da442950b639f045c6268d87d8698c57f8d74c3 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="conflict1" type="normal">
     <action ID="test" rule="test.printInt" restrict="lock">1</action>
   </mode>
index 08b96bb3a84203df1a1376b920a860dd857c2f9b..cb14161b90de636ae2a008aa68e8bc03c2ce037c 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="conflict1" type="normal">
     <action ID="test" rule="test.printInt" restrict="lock">2</action>
   </mode>
index 0bf30665595d211b86857308dc59a0a0aa8cbb71..43cb35b9884b3d1de94984abe9f91af865f14028 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="conflict3" type="exclusive">
     <action ID="test" rule="test.printBool" restrict="lock">true</action>
   </mode>
index c906889b537367a6201abca41df61e3bc7d3d48c..43ee7c1e5db890ce36db650f269d18f482454cd7 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="ex1" type="normal">
     <action ID="wifiOn" rule="wifi.power" priority="-100">on</action>
     <action rule="notification.donotdisturb">on</action>
index 6056c62aff04c6b1c72ea5af85c82b5fd552d6dc..5f2277b4248bc0e3554c65fe290d677966a49091 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="ex2" type="exclusive">
     <action ID="1" rule="vconf.db.setting.psmode" stopOnErr="true" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE</action>
     <action ID="wifiOff" rule="wifi.power" restrict="lock" priority="-100">off</action>
index 423488bc61f78dad61fd486c50e617e6c6938f4f..5ece2f878f07f50e113da09d6950e6d0961eab9b 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="powerSave" type="exclusive">
     <action rule="vconf.db.setting.psmode">SETTING_PSMODE_WEARABLE_ENHANCED</action>
     <action rule="vconf.db.bluetooth.status">VCONFKEY_BT_STATUS_OFF</action>
diff --git a/example/mode/tizen_waterlock_mode.xml b/example/mode/tizen_waterlock_mode.xml
new file mode 100644 (file)
index 0000000..f4bac82
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+  <mode name="waterlock" type="exclusive">
+    <action rule="bluetooth.power">off</action>
+    <action ID="wifiOff" rule="wifi.power" restrict="lock" priority="-100">off</action>
+    <action ID="1" rule="vconf.db.setting.psmode" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE_ENHANCED</action>
+    <undo ID="2" rule="vconf.db.setting.psmode" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE</undo>
+    <undo ID="3" rule="media.player">/opt/usr/data/settings/Alarms/Alarms_on_call.ogg</undo>
+  </mode>
+</tizenModes>
index 085662923cadb6131fdc09910a8a459d927be7e5..0491aad25e4e345b43d05862e24fcb2538163467 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="wifiOn" type="exclusive">
     <action rule="wifi.power">on</action>
   </mode>
index 8bea028eea1b620d41ac692ad6e869852327ff9d..dfebdb7c7831203a0f5241025aa75a4ed351940d 100644 (file)
@@ -1,30 +1,30 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <actionRule>
-    <rule name="sensord.changeAccuracy" type="int" since="5.5" plugin="sensor-fw">
+    <rule name="sensord.changeAccuracy" type="int" since="6.0" plugin="sensor-fw">
       <conflict>sensord.exactness</conflict>
       <desc>Sensor Accuracy</desc>
       <domain>System</domain>
     </rule>
-    <rule name="sensord.exactness" type="int" since="5.5" plugin="sensor-fw">
+    <rule name="sensord.exactness" type="int" since="6.0" plugin="sensor-fw">
       <conflict>sensord.changeAccuracy</conflict>
       <desc>Sensor Exactness</desc>
       <domain>System</domain>
     </rule>
-    <rule name="browser.url" type="string" since="5.5" plugin="web">
+    <rule name="browser.url" type="string" since="6.0" plugin="web">
       <desc>browser</desc>
       <domain>Web Framework</domain>
     </rule>
-    <rule name="display.nightLight" type="int" since="5.5" plugin="display">
+    <rule name="display.nightLight" type="int" since="6.0" plugin="display">
       <conflict>display.autoLight</conflict>
       <desc>It makes the screen color warmer.</desc>
       <domain>System</domain>
     </rule>
-    <rule name="test.printInt" type="int" since="5.5" plugin="test">
+    <rule name="test.printInt" type="int" since="6.0" plugin="test">
       <desc>It prints integerv value</desc>
       <domain>System</domain>
     </rule>
-    <rule name="test.printBool" type="bool" since="5.5" plugin="test">
+    <rule name="test.printBool" type="bool" since="6.0" plugin="test">
       <desc>It prints boolean value</desc>
       <domain>System</domain>
     </rule>
index d48b25c6534aee4e8fbdb96ee1d9990ac94b93ee..9d64a562c809dc19cc7a754dd22011d3199e3e05 100644 (file)
@@ -1,30 +1,30 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<tizenModes xmlns="http://www.tizen.org" version="5.5">
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
   <actionRule>
-    <rule name="sensord.changeAccuracy" type="int" since="5.5" plugin="sensor-fw">
+    <rule name="sensord.changeAccuracy" type="int" since="6.0" plugin="sensor-fw">
       <conflict>sensord.exactness</conflict>
       <desc>Sensor Accuracy</desc>
       <domain>System</domain>
     </rule>
-    <rule name="sensord.exactness" type="int" since="5.5" plugin="sensor-fw">
+    <rule name="sensord.exactness" type="int" since="6.0" plugin="sensor-fw">
       <conflict>sensord.changeAccuracy</conflict>
       <desc>Sensor Exactness</desc>
       <domain>System</domain>
     </rule>
-    <rule name="browser.url" type="string" since="5.5" plugin="web">
+    <rule name="browser.url" type="string" since="6.0" plugin="web">
       <desc>browser</desc>
       <domain>Web Framework</domain>
     </rule>
-    <rule name="display.nightLight" type="int" since="5.5" plugin="display">
+    <rule name="display.nightLight" type="int" since="6.0" plugin="display">
       <conflict>display.autoLight</conflict>
       <desc>It makes the screen color warmer.</desc>
       <domain>System</domain>
     </rule>
-    <rule name="test.printInt" type="int" since="5.5" plugin="test">
+    <rule name="test.printInt" type="int" since="6.0" plugin="test">
       <desc>It prints integerv value</desc>
       <domain>System</domain>
     </rule>
-    <rule name="test.printBool" type="bool" since="5.5" plugin="test">
+    <rule name="test.printBool" type="bool" since="6.0" plugin="test">
       <desc>It prints boolean value</desc>
       <domain>System</domain>
     </rule>
index e8be4b8cc1af35062a4233cf364a8e8c0a9825bd..528e93d8d9a02e67a5a13c8c0fdbe6bdd7e1520b 100644 (file)
               <xs:element maxOccurs="unbounded" name="action">
                 <xs:complexType>
                   <xs:simpleContent>
-                    <xs:extension base="o:valueT">
-                      <xs:attribute name="ID" type="xs:string" use="optional" />
-                      <xs:attribute name="rule" type="xs:string" use="required" />
-                      <xs:attribute name="stopOnErr" type="xs:boolean" use="optional" />
-                      <xs:attribute name="restrict" use="optional">
-                        <xs:simpleType>
-                          <xs:restriction base="xs:string">
-                            <xs:enumeration value="none"/>
-                            <xs:enumeration value="lock"/>
-                          </xs:restriction>
-                        </xs:simpleType>
-                      </xs:attribute>
-                      <xs:attribute name="priority" type="xs:byte" use="optional" />
-                      <xs:attribute name="before" type="xs:string" use="optional" />
-                      <xs:attribute name="after" type="xs:string" use="optional" />
-                    </xs:extension>
+                    <xs:extension base="o:actionT"/>
+                  </xs:simpleContent>
+                </xs:complexType>
+              </xs:element>
+              <xs:element minOccurs="0" maxOccurs="unbounded" name="undo">
+                <xs:complexType>
+                  <xs:simpleContent>
+                    <xs:extension base="o:actionT"/>
                   </xs:simpleContent>
                 </xs:complexType>
               </xs:element>
       <xs:attribute name="version" type="o:versionT" use="required" />
     </xs:complexType>
   </xs:element>
+  <xs:complexType name="actionT">
+    <xs:simpleContent>
+      <xs:extension base="o:valueT">
+        <xs:attribute name="ID" type="xs:string" use="optional" />
+        <xs:attribute name="rule" type="xs:string" use="required" />
+        <xs:attribute name="stopOnErr" type="xs:boolean" use="optional" />
+        <xs:attribute name="restrict" use="optional">
+          <xs:simpleType>
+            <xs:restriction base="xs:string">
+              <xs:enumeration value="none"/>
+              <xs:enumeration value="lock"/>
+            </xs:restriction>
+          </xs:simpleType>
+        </xs:attribute>
+        <xs:attribute name="priority" type="xs:byte" use="optional" />
+        <xs:attribute name="before" type="xs:string" use="optional" />
+        <xs:attribute name="after" type="xs:string" use="optional" />
+      </xs:extension>
+    </xs:simpleContent>
+  </xs:complexType>
   <xs:simpleType name="valueT">
     <xs:restriction base="xs:string">
       <xs:pattern value="\S*"/>
index 84b9d8ca6a10f92611977faadd49c06643505337..875782afff87d37fa516c79bdf05fc6c62cb0113 100644 (file)
@@ -33,6 +33,11 @@ void Mode::addAction(Action *action)
        actionList.push_back(std::shared_ptr<Action>(action));
 }
 
+void Mode::addUndo(Action *action)
+{
+       undoList.push_back(std::shared_ptr<Action>(action));
+}
+
 void Mode::setName(const std::string &data)
 {
        name = data;
@@ -115,9 +120,17 @@ void Mode::undo()
        std::list<std::shared_ptr<Action>>::iterator it;
        for (it = actionList.begin(); it != actionList.end(); it++)
                (*it)->undo();
+
+       for (it = undoList.begin(); it != undoList.end(); it++)
+               (*it)->applyOneShot();
 }
 
 std::list<std::shared_ptr<Action>> Mode::getActionList() const
 {
        return actionList;
 }
+
+std::list<std::shared_ptr<Action>> Mode::getUndoList() const
+{
+       return undoList;
+}
index be93091d1c6c951e37dcc5b87a79623917bcb121..104df15c42eaf1c874c0d95d88eee0c0024a8041 100644 (file)
@@ -45,6 +45,10 @@ public:
 
        void addAction(Action *action);
        std::list<std::shared_ptr<Action>> getActionList() const;
+
+       void addUndo(Action *action);
+       std::list<std::shared_ptr<Action>> getUndoList() const;
+
        int apply();
        int applyOneShot();
        void undo();
@@ -53,6 +57,7 @@ private:
        std::string name;
        ModeType type;
        std::list<std::shared_ptr<Action>> actionList;
+       std::list<std::shared_ptr<Action>> undoList;
 #ifdef MDS_TEST
        friend class TestParser;
 #endif
index 6ce1a2f57f3fb58a4c9cf5e1657bad95e20be0c1..4902a7d6963f3955091b0ff0efe8978d308661f5 100644 (file)
@@ -30,6 +30,7 @@ const xmlChar* const ModeTag::NAME = (xmlChar*)"name";
 const xmlChar* const ModeTag::TYPE = (xmlChar*)"type";
 const xmlChar* const ModeTag::CUSTOM = (xmlChar*)"custom";
 const xmlChar* const ModeTag::ACTION = (xmlChar*)"action";
+const xmlChar* const ModeTag::UNDO = (xmlChar*)"undo";
 const xmlChar* const ModeTag::RULE = (xmlChar*)"rule";
 const xmlChar* const ModeTag::STOP_ON_ERR = (xmlChar*)"stopOnErr";
 const xmlChar* const ModeTag::RESTICT = (xmlChar*)"restrict";
index 77171d848fe0cc46c481b6bc7e138a9633070f27..22b48b9c112827af9454393744b157341770a702 100644 (file)
@@ -33,6 +33,7 @@ struct ModeTag {
        static const xmlChar* const TYPE;
        static const xmlChar* const CUSTOM;
        static const xmlChar* const ACTION;
+       static const xmlChar* const UNDO;
        static const xmlChar* const RULE;
        static const xmlChar* const STOP_ON_ERR;
        static const xmlChar* const RESTICT;
index de32f3525b5f04faf41ffe9f91bf07d6126cf07b..9890c32ed7f6a9ad84fda5c3c4a1b1fb562aee04 100644 (file)
@@ -92,6 +92,8 @@ void ModeXMLParser::getDatafromNode(xmlNodePtr node)
                parseMode(node);
        } else if (MDS_EQUAL == xmlStrcmp(node->name, ModeTag::ACTION)) {
                parseAction(node);
+       } else if (MDS_EQUAL == xmlStrcmp(node->name, ModeTag::UNDO)) {
+               parseUndo(node);
        } else {
                DBG("Unhandled node : %s", node->name);
        }
@@ -137,6 +139,12 @@ std::string ModeXMLParser::getXmlTagStringValue(xmlNodePtr node, const xmlChar*
        return xmlTagString;
 }
 
+void ModeXMLParser::parseUndo(xmlNodePtr node)
+{
+       Action *action = parseActionInfo(node);
+       mode.addUndo(action);
+}
+
 void ModeXMLParser::parseActionAttr(xmlNodePtr node, Action *action)
 {
        char *restictProp = (char*)xmlGetProp(node, ModeTag::RESTICT);
@@ -155,6 +163,12 @@ void ModeXMLParser::parseActionAttr(xmlNodePtr node, Action *action)
 }
 
 void ModeXMLParser::parseAction(xmlNodePtr node)
+{
+       Action *action = parseActionInfo(node);
+       mode.addAction(action);
+}
+
+Action *ModeXMLParser::parseActionInfo(xmlNodePtr node)
 {
        char *ruleProp = (char*)xmlGetProp(node, ModeTag::RULE);
        if (ruleProp == NULL) {
@@ -186,8 +200,7 @@ void ModeXMLParser::parseAction(xmlNodePtr node)
        xmlFree(nodeContent);
 
        action->printInfo();
-
-       mode.addAction(action);
+       return action;
 }
 
 void ModeXMLParser::bindPlugin(const std::string &name, Action *action)
@@ -197,4 +210,3 @@ void ModeXMLParser::bindPlugin(const std::string &name, Action *action)
        pluginName = name.substr(0, pos);
        action->setPlugin(pluginManager.getPlugin(pluginName));
 }
-
index 9613698e197fd5b094d95a55da3ce8da09dd4d17..5ef9a772aba03511f2596097c2a5bf618546fe5e 100644 (file)
@@ -41,6 +41,8 @@ private:
        std::string getXmlTagStringValue(xmlNodePtr node, const xmlChar *tag);
        void parseActionAttr(xmlNodePtr node, Action *action);
        void parseAction(xmlNodePtr node);
+       void parseUndo(xmlNodePtr node);
+       Action *parseActionInfo(xmlNodePtr node);
        void bindPlugin(const std::string &name, Action *action);
 
        PluginManager &pluginManager;
index 4aa66c2e8e48c164e9d57f24e477cc74a2cad5f6..6a8de99f043292c3a7f5a32f52797f560c44bc29 100644 (file)
@@ -102,3 +102,10 @@ TEST_F(ClientTest, undoModeWifiOn)
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NONE, result);
 }
+
+TEST_F(ClientTest, undoModePsMode)
+{
+       g_idle_add(undo_mode_idler, (gpointer)"waterlock");
+       g_main_loop_run(loop);
+       EXPECT_EQ(MODES_ERROR_NONE, result);
+}