revise Undo Info
authorYoungjae Shin <yj99.shin@samsung.com>
Thu, 7 May 2020 10:38:58 +0000 (19:38 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 7 May 2020 10:42:00 +0000 (19:42 +0900)
handle the ignoreUndo value

13 files changed:
supervisor/Action.cpp
supervisor/Action.h
supervisor/ModeCareTaker.cpp
supervisor/ModeCareTaker.h
supervisor/ModeManager.cpp
supervisor/ModeManager.h
supervisor/ModeXMLParser.cpp
supervisor/ModesXMLTag.cpp
supervisor/ModesXMLTag.h
supervisor/TAction.h
supervisor/UndoInfoParser.cpp
supervisor/XMLGenerator.cpp
unittest/modes_test_policy.cpp

index 7f422d5998d1eecd5730c7052e22b148f5a1cce9..4b0cb6de6190fdc33fdf58346b044e7a5c4d41ee 100644 (file)
@@ -25,7 +25,7 @@ std::map<std::string, Action*> Action::subscribedActions;
 
 Action::Action(const std::string &name, std::shared_ptr<PluginAction> pluginAction)
        : ruleName(name), ignoreUndo(false), type(SYNC), life(PERMANENT), piAction(pluginAction),
-       locked(false), stopOnErr(false), subscribed(false), restriction(NONE)
+       locked(false), stopOnErr(false), restriction(NONE)
 {
 }
 
@@ -48,6 +48,16 @@ std::string Action::getRuleName()
        return ruleName;
 }
 
+void Action::setIgnoreUndo(bool ignore)
+{
+       ignoreUndo = ignore;
+}
+
+bool Action::isIgnored()
+{
+       return ignoreUndo;
+}
+
 void Action::setID(const std::string &actionId)
 {
        id = actionId;
@@ -135,6 +145,8 @@ std::string Action::backupUndoInfo()
 
 int Action::restoreUndoInfo(const std::string &info)
 {
+       RETV_IF(ignoreUndo, MODES_ERROR_NONE);
+
        int ret = piAction->setUndoInfo(info);
        if (MODES_ERROR_NONE != ret) {
                ignoreUndo = true;
@@ -157,16 +169,11 @@ void Action::subscribeChanges()
                        WARN("Action(%s), already exists", ruleName.c_str());
                        return;
                }
-               subscribed = true;
        }
 }
 
 void Action::unsubscribeChanges()
 {
-       if (!subscribed)
-               return;
-
-       subscribed = false;
        piAction->unSetChangedCallback(valueChangedCallback);
        subscribedActions.erase(ruleName);
 }
index 262cb05473ca755411113c30a3b62f1c68997e77..3ade714079e76af2cdc01aa383848d0639c3da11 100644 (file)
@@ -49,6 +49,8 @@ public:
        void printInfo();
        void setRuleName(const std::string &data);
        std::string getRuleName();
+       void setIgnoreUndo(bool ignore);
+       bool isIgnored();
        void setID(const std::string &actionId);
        std::string getID();
        void setRestrict(const ActionRestrict &data);
@@ -88,7 +90,6 @@ private:
        std::list<std::string> privileges;
        bool locked; //Another action(same rule) is restricted(LOCK), It is assigned by ConflictManager
        bool stopOnErr;
-       bool subscribed;
        ActionRestrict restriction;
        std::list<ActionObserver*> observers;
        static std::map<std::string, Action*> subscribedActions;
index 53989bba0adc4a353d51e0708adc78d06bbb2ba4..b0b1e81231dc604ff21338eb73bdb6494821d2c5 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "mdss.h"
 #include "XMLGenerator.h"
+#include "UndoInfoParser.h"
 #include "EssentialHandler.h"
 
 MODES_NAMESPACE_USE;
@@ -31,12 +32,25 @@ std::string ModeCareTaker::getUndoInfoDir()
        return undoDir;
 }
 
-void ModeCareTaker::realPushMode(const Mode &mode)
+bool ModeCareTaker::hasUndoInfo(const std::string &modeName)
 {
-       savedModes.insert(std::pair<std::string, Mode>(mode.getName(), mode));
+       std::string file = undoDir + "/tizen_" + modeName + MODES_UNDO_FILE_SUFFIX;
+       return (access(file.c_str(), F_OK) == 0);
+}
 
-       if (mode.hasEssential())
-               handleEssentialAction(mode);
+void ModeCareTaker::restoreMode(Mode &mode)
+{
+       std::string file = undoDir + "/tizen_" + mode.getName() + MODES_UNDO_FILE_SUFFIX;
+       try {
+               UndoInfoParser undoInfoParser(file);
+               undoInfoParser.putUndoInfo(mode);
+
+               realPushMode(mode);
+       } catch (std::exception &e) {
+               ERR("parser(%s) Fail(%s)", file.c_str(), e.what());
+               if (0 != remove(file.c_str()))
+                       ERR("remove(%s) Fail(%d)", file.c_str(), errno);
+       }
 }
 
 void ModeCareTaker::pushMode(const Mode &mode)
@@ -101,7 +115,7 @@ bool ModeCareTaker::findLockedAction(const std::string &ruleName)
 
                for (auto actionIt = actionList.begin(); actionIt != actionList.end(); actionIt++)
                        if ((*actionIt)->getRuleName() == ruleName
-                                       && (*actionIt)->getRestrict() == Action::LOCK) {
+                               && (*actionIt)->getRestrict() == Action::LOCK) {
                                ERR("%s is Locked", ruleName.c_str());
                                return true;
                        }
@@ -122,6 +136,14 @@ void ModeCareTaker::update(int *key)
        EssentialHandler::undoHandler(found->second);
 }
 
+void ModeCareTaker::realPushMode(const Mode &mode)
+{
+       savedModes.insert(std::pair<std::string, Mode>(mode.getName(), mode));
+
+       if (mode.hasEssential())
+               handleEssentialAction(mode);
+}
+
 bool ModeCareTaker::checkConflictAction(const Mode &mode)
 {
        bool stopOnErr = false;
index 1efa77634713d89fd3d4bc4bfd4b1e345faceb3a..33d0d165634c0f4ae78c66b2d5a4aeefa018549b 100644 (file)
@@ -29,13 +29,15 @@ public:
        ~ModeCareTaker() = default;
 
        std::string getUndoInfoDir();
-       void realPushMode(const Mode &mode);
+       bool hasUndoInfo(const std::string &modeName);
+       void restoreMode(Mode &mode);
        void pushMode(const Mode &mode);
        int popMode(const std::string &name, Mode &mode);
        bool isConflict(const Mode &mode);
        bool isSavedMode(const std::string &name);
        void update(int *key);
 private:
+       void realPushMode(const Mode &mode);
        bool checkConflictAction(const Mode &mode);
        void handleEssentialAction(const Mode &mode);
        bool findLockedAction(const std::string &ruleName);
index 873c663fe21daab84fad2aad1d354f8b355972a9..30f60927a36bccc2ecfeee1ecdb734b36f6246ac 100644 (file)
@@ -25,7 +25,6 @@
 #include "ModeObserver.h"
 #include "XMLGenerator.h"
 #include "ModeXMLParser.h"
-#include "UndoInfoParser.h"
 
 using std::string;
 MODES_NAMESPACE_USE;
@@ -45,7 +44,6 @@ void ModeManager::init()
                makeModeMap(*it);
                DBG("Mode Directory(%s) added", it->c_str());
        }
-       restoreUndoInfo(careTaker.getUndoInfoDir());
 }
 
 // TODO: apply better polymorphism
@@ -68,6 +66,10 @@ void ModeManager::addModeAttributes(ModeParser *parser, const string &path)
        Mode::ModeType type = parser->getModeType();
        modeMap.insert(std::make_pair(modeName, std::make_tuple(path, type, hidden)));
 
+       if (careTaker.hasUndoInfo(modeName)) {
+               Mode mode = parser->getMode();
+               careTaker.restoreMode(mode);
+       }
        DBG("[%zu] modeName : %s, modePath : %s, type : %d, hidden : %s", modeMap.size(), modeName.c_str(), path.c_str(), type, hidden? "true": "false");
 }
 
@@ -286,52 +288,6 @@ bool ModeManager::makeModeMap(const string &dirPath)
        return true;
 }
 
-bool ModeManager::restoreUndoInfo(const string &dirPath)
-{
-       DBG("dirPath : [%s]", dirPath.c_str());
-
-       DIR *dir;
-       if ((dir = opendir(dirPath.c_str())) == NULL) {
-               ERR("opendir(%s) Fail(%d)", dirPath.c_str(), errno);
-               return false;
-       }
-
-       struct dirent *entry;
-       while ((entry = readdir(dir)) != NULL) {
-               string file(entry->d_name);
-               const size_t suffixLen = sizeof(MODES_UNDO_FILE_SUFFIX) - 1;
-               if (file.length() < suffixLen
-                               || file.compare(file.length() - suffixLen, suffixLen, MODES_UNDO_FILE_SUFFIX)) {
-                       continue;
-               }
-
-               string fileFullPath = dirPath + "/" + string(entry->d_name);
-               try {
-                       UndoInfoParser undoInfoParser(fileFullPath);
-                       string modeName = undoInfoParser.getModeName();
-                       auto found = modeMap.find(modeName);
-                       if (modeMap.end() == found) {
-                               ERR("No Mode(%s)", modeName.c_str());
-                               throw ModesEx(ModesEx::NO_DATA);
-                       }
-
-                       string path = std::get<0>(found->second);
-                       std::unique_ptr<ModeParser> parser(getModeParser(path));
-                       Mode mode = parser->getMode();
-                       undoInfoParser.putUndoInfo(mode);
-
-                       careTaker.realPushMode(mode);
-               } catch (std::exception &e) {
-                       ERR("parser(%s) Fail(%s)", fileFullPath.c_str(), e.what());
-                       if (0 != remove(fileFullPath.c_str()))
-                               ERR("remove(%s) Fail(%d)", fileFullPath.c_str(), errno);
-               }
-       }
-
-       closedir(dir);
-       return true;
-}
-
 void ModeManager::addModeDirectory(const string &dirPath)
 {
        auto result = modeDirList.find(dirPath);
index 57af4acf223c744fd1eb100231c702ccfeeaefc9..7953d63cdcdcc229468d1cb8ed81821082d84fcb 100644 (file)
@@ -44,7 +44,6 @@ public:
 private:
        void notifyObservers(const std::string &modeName, ModeObserver::ModeState state);
        bool makeModeMap(const std::string &dirPath);
-       bool restoreUndoInfo(const std::string &dirPath);
        void addModeAttributes(ModeParser *parser, const std::string &path);
        ModeParser* getModeParser(const std::string &path);
 
index 06eb4b52c09bf0dc80b7f4f371356483b14d6e77..16919a274a4ceda92a938d9ad0a2f6aae4a892bb 100644 (file)
@@ -81,8 +81,8 @@ void ModeXMLParser::validateAction(xmlNodePtr node)
 {
        char *actionTypeProp = (char*)xmlGetProp(node, ModesXMLTag::TYPE);
        if (actionTypeProp && MDS_EQUAL == strcmp(actionTypeProp, "async")) {
-               char *stopOnErrProp = (char*)xmlGetProp(node, ModesXMLTag::STOP_ON_ERR);
-               if (stopOnErrProp && MDS_EQUAL == strcmp(stopOnErrProp, "true")) {
+               xmlChar *stopOnErrProp = xmlGetProp(node, ModesXMLTag::STOP_ON_ERR);
+               if (MDS_EQUAL == xmlStrcmp(stopOnErrProp, ModesXMLTag::TRUE)) {
                        xmlFree(stopOnErrProp);
                        xmlFree(actionTypeProp);
                        ERR("Can NOT support stopOnErr in async");
@@ -188,8 +188,8 @@ void ModeXMLParser::parseActionAttr(xmlNodePtr node, Action *action)
                xmlFree(restictProp);
        }
 
-       char *stopOnErrProp = (char*)xmlGetProp(node, ModesXMLTag::STOP_ON_ERR);
-       if (stopOnErrProp && MDS_EQUAL == strcmp(stopOnErrProp, "true"))
+       xmlChar *stopOnErrProp = xmlGetProp(node, ModesXMLTag::STOP_ON_ERR);
+       if (MDS_EQUAL == xmlStrcmp(stopOnErrProp, ModesXMLTag::TRUE))
                action->setStopOnErr(true);
        else
                action->setStopOnErr(false);
index ab45a09e8cdc183ae0eb9cb191cecb939f89b7d6..c535007c97499e3ff470a0d778cbb05e886e2094 100644 (file)
@@ -27,6 +27,8 @@ const xmlChar* const ModesXMLTag::XMLNS_STR = (xmlChar*)"http://www.tizen.org";
 const xmlChar* const ModesXMLTag::VERSION = (xmlChar*)"version";
 const xmlChar* const ModesXMLTag::CUR_VERSION = (xmlChar*)"6.0";
 const xmlChar* const ModesXMLTag::TYPE = (xmlChar*)"type";
+const xmlChar* const ModesXMLTag::TRUE = (xmlChar*)"true";
+const xmlChar* const ModesXMLTag::FALSE = (xmlChar*)"false";
 //Mode
 const xmlChar* const ModesXMLTag::MODE = (xmlChar*)"mode";
 const xmlChar* const ModesXMLTag::NAME = (xmlChar*)"name";
@@ -43,3 +45,4 @@ const xmlChar* const ModesXMLTag::ID = (xmlChar*)"ID";
 //UndoInfo
 const xmlChar* const ModesXMLTag::UNDO_INFO = (xmlChar*)"UndoInfo";
 const xmlChar* const ModesXMLTag::INFO = (xmlChar*)"info";
+const xmlChar* const ModesXMLTag::IGNORE = (xmlChar*)"ignore";
index ee20114c82a09a253da9a046e81b9729312e1304..25e8d2e39046f580982df35c693dd2f63aef7d3b 100644 (file)
@@ -30,6 +30,9 @@ struct ModesXMLTag {
        static const xmlChar* const VERSION;
        static const xmlChar* const CUR_VERSION;
        static const xmlChar* const TYPE;
+       static const xmlChar* const TRUE;
+       static const xmlChar* const FALSE;
+
        //Mode
        static const xmlChar* const MODE;
        static const xmlChar* const NAME;
@@ -46,6 +49,7 @@ struct ModesXMLTag {
        //UndoInfo
        static const xmlChar* const UNDO_INFO;
        static const xmlChar* const INFO;
+       static const xmlChar* const IGNORE;
 };
 
 MODES_NAMESPACE_END
index 31e80f2410542d2e5715e82a82734a170a5bd3f0..ec0e79752e09c5bc710faa1f84b6b08354eb0857 100644 (file)
@@ -31,7 +31,7 @@ template <typename T>
 class TAction : public Action {
 public:
        TAction(const std::string &name, std::shared_ptr<PluginAction> pluginAction)
-               : Action(name, pluginAction), undoing(false)
+               : Action(name, pluginAction)
        {
                if (nullptr == pluginAction)
                        throw ModesEx(ModesEx::INVALID_ARG);
@@ -160,7 +160,6 @@ private:
 
        std::map<std::string, T, CaseIndependentLess> valueAliases;
        std::mutex actionMutex;
-       bool undoing;
        T value{};
 };
 MODES_NAMESPACE_END
index 1a0667116a2a2f4688728cb419c116340dde9a3e..d316f409dd0d6fa13709d8a4f91948726a6f1eed 100644 (file)
@@ -85,6 +85,10 @@ void UndoInfoParser::parseInfo(xmlNodePtr node, const std::list<std::shared_ptr<
                throw ModesEx(ModesEx::PARSER_ERROR, "No Action");
        }
 
+       xmlChar *isIgnored = xmlGetProp(node, ModesXMLTag::IGNORE);
+       if (MDS_EQUAL == xmlStrcmp(isIgnored, ModesXMLTag::TRUE))
+               action->setIgnoreUndo(true);
+
        char *nodeContent = (char*)xmlNodeGetContent(node);
        if (nullptr == nodeContent)
                ERR("No undo Info for Action(%s)", ruleName);
index d4e2298acc3a6906655aa4439bd6939ab9e25b8c..53d862a491ccf697f7e70ab459041666a70fa382 100644 (file)
@@ -83,7 +83,7 @@ void XMLGenerator::makeModeXML(const std::string &filename, const Mode &mode)
        xmlSetProp(modeNode, ModesXMLTag::NAME, (xmlChar*)modeName.c_str());
        xmlSetProp(modeNode, ModesXMLTag::TYPE, (xmlChar*)modeType.c_str());
        if (true == mode.isHidden())
-               xmlSetProp(modeNode, ModesXMLTag::HIDDEN, (xmlChar*)"true");
+               xmlSetProp(modeNode, ModesXMLTag::HIDDEN, ModesXMLTag::TRUE);
        xmlAddChild(rootNode, modeNode);
 
        std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
@@ -133,6 +133,10 @@ void XMLGenerator::makeUndoInfoXML(const std::string &filename, const Mode &mode
 
                xmlNodePtr infoNode = xmlNewNode(NULL, ModesXMLTag::INFO);
                xmlSetProp(infoNode, ModesXMLTag::RULE, (xmlChar*)(*it)->getRuleName().c_str());
+               if ((*it)->isIgnored())
+                       xmlSetProp(infoNode, ModesXMLTag::IGNORE, ModesXMLTag::TRUE);
+               else
+                       xmlSetProp(infoNode, ModesXMLTag::IGNORE, ModesXMLTag::FALSE);
                xmlNodeSetContent(infoNode, (xmlChar*)(*it)->backupUndoInfo().c_str());
                xmlAddChild(undoInfoNode, infoNode);
        }
index d69e5e50b947a8c4a6f179d95c448cc1b5dca075..fa6c19083319bd2362677cd204c08b4bb8d613b6 100644 (file)
@@ -40,7 +40,7 @@ protected:
 
        bool isSubscribed(Action *action)
        {
-               return action->subscribed;
+               return !(action->isIgnored());
        }
 
        Plugin *plugin;