Revise check restrict
authorYoungjae Shin <yj99.shin@samsung.com>
Mon, 6 Jan 2020 04:55:43 +0000 (13:55 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
example/mode/tizen_conflict2_mode.xml
supervisor/Action.cpp
supervisor/Action.h
supervisor/Mode.cpp
supervisor/ModeCareTaker.cpp
supervisor/ModeCareTaker.h

index cb14161b90de636ae2a008aa68e8bc03c2ce037c..0c21e0a941317af7734b24364d8af4bcb5f4998a 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
   <mode name="conflict1" type="normal">
-    <action ID="test" rule="test.printInt" restrict="lock">2</action>
+    <action ID="test" rule="test.printInt" restrict="lock" stopOnErr="true">2</action>
   </mode>
 </tizenModes>
index 89b7e1c09d299e930c945b7333fc7ef2170b5f80..55c4d3615b547e05edc9abb4cca0ad9bdbf5bbe2 100644 (file)
 MODES_NAMESPACE_USE;
 
 Action::Action()
-       : isChanged(false), type(SYNC), plugin(nullptr), piAction(nullptr), stopOnErr(false), restriction(REQ_NONE)
+       : isChanged(false), type(SYNC), plugin(nullptr), piAction(nullptr), stopOnErr(false), restriction(REQ_NONE), locked(false)
 
 {
 }
 
 Action::Action(const std::string &name)
-       : ruleName(name), isChanged(false), type(SYNC), plugin(nullptr), piAction(nullptr), stopOnErr(false), restriction(REQ_NONE)
+       : ruleName(name), isChanged(false), type(SYNC), plugin(nullptr), piAction(nullptr), stopOnErr(false), restriction(REQ_NONE), locked(false)
 {
 }
 
@@ -92,6 +92,16 @@ Action::ActionRestrict Action::getRestrict()
        return restriction;
 }
 
+void Action::setLocked(bool lock)
+{
+       locked = lock;
+}
+
+bool Action::isLocked()
+{
+       return locked;
+}
+
 void Action::setPlugin(Plugin *pi)
 {
        plugin = pi;
index 64abbaba15ad9b61270da68c10faabe43108fc33..8228a0512c57ac821ba6102c3fe6ef00fb95c499 100644 (file)
@@ -45,6 +45,8 @@ public:
        std::string getID();
        void setRestrict(const ActionRestrict &data);
        ActionRestrict getRestrict();
+       void setLocked(bool lock);
+       bool isLocked();
        void setStopOnErr(bool val);
        bool getStopOnErr();
        void setType(ActionType val);
@@ -71,6 +73,7 @@ private:
        std::string privilege;
        bool stopOnErr;
        ActionRestrict restriction;
+       bool locked;
 };
 
 MODES_NAMESPACE_END
index bf4da24fa816b84ffd896fdd03bdef80c12c0bf6..d0cc5a5b3175beca0ce0816ae861b3de90b39273 100644 (file)
@@ -74,6 +74,9 @@ int Mode::apply()
 {
        std::list<std::shared_ptr<Action>>::iterator it;
        for (it = actionList.begin(); it != actionList.end(); it++) {
+               if ((*it)->isLocked()) //It was checked by ConflictManager(isConflict)
+                       continue;
+
                if (Action::ActionType::ASYNC == (*it)->getType()) {
                        std::thread(&Action::apply, *it).detach();
                } else {
@@ -91,6 +94,9 @@ int Mode::applyOneShot()
 {
        std::list<std::shared_ptr<Action>>::iterator it;
        for (it = actionList.begin(); it != actionList.end(); it++) {
+               if ((*it)->isLocked()) //It was checked by ConflictManager(isConflict)
+                       continue;
+
                if (Action::ActionType::ASYNC == (*it)->getType()) {
                        std::thread(&Action::applyOneShot, *it).detach();
                } else {
index acfc1756ef92a5e6f341565dfa3d47730a23a2f0..50884db8fc2da4f25b86cc8cb0472e7ade7a8779 100644 (file)
@@ -84,7 +84,7 @@ bool ModeCareTaker::isExclusive()
        return exclusive;
 }
 
-bool ModeCareTaker::findRestrictAction(const std::string &ruleName)
+bool ModeCareTaker::findLockedAction(const std::string &ruleName)
 {
        for (auto modeIt = savedModes.begin(); modeIt != savedModes.end(); modeIt++) {
                std::list<std::shared_ptr<Action>> actionList = (modeIt->second).getActionList();
@@ -102,10 +102,14 @@ bool ModeCareTaker::findRestrictAction(const std::string &ruleName)
 
 bool ModeCareTaker::checkConflictAction(const Mode &mode)
 {
+       bool stopOnErr = false;
        std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
-       for (auto it = actionList.begin(); it != actionList.end(); it++)
-               if (findRestrictAction((*it)->getRuleName()))
-                       return true;
-
-       return false;
+       for (auto it = actionList.begin(); it != actionList.end(); it++) {
+               if (findLockedAction((*it)->getRuleName())) {
+                       (*it)->setLocked(true);
+                       if ((*it)->getStopOnErr())
+                               stopOnErr = true;
+               }
+       }
+       return stopOnErr;
 }
index e871be2ed099fd7cc31d11a654e8dd0a906520d9..3ac45e24c0f73f218b8c2dbe9267738d1e77ec09 100644 (file)
@@ -35,7 +35,7 @@ public:
        bool isExclusive();
        bool checkConflictAction(const Mode &mode);
 private:
-       bool findRestrictAction(const std::string &ruleName);
+       bool findLockedAction(const std::string &ruleName);
        std::map<std::string, Mode> savedModes;
        std::string undoDir;
        bool exclusive;