Add hidden attribute in mode element
authorJinWang An <jinwang.an@samsung.com>
Fri, 20 Dec 2019 04:38:48 +0000 (13:38 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
14 files changed:
example/mode/tizen_ex2_mode.xml
schema/tizen_mode.xsd
supervisor/Mode.cpp
supervisor/Mode.h
supervisor/ModeManager.cpp
supervisor/ModeManager.h
supervisor/ModeParser.h
supervisor/ModeXMLParser.cpp
supervisor/ModeXMLParser.h
supervisor/ModesXMLTag.cpp
supervisor/ModesXMLTag.h
supervisor/RequestHandler.cpp
unittest/modes_test_modemgr.cpp
unittest/modes_test_parser.cpp

index bf4d7218153b1aaad618792a063c842aab2b8aad..e062a2169ed7985ebd7ed6fde2c2e2f33da812a6 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="ex2" type="exclusive">
+  <mode name="ex2" type="exclusive" hidden="true">
     <action ID="1" rule="test.printInt" stopOnErr="true" restrict="lock" priority="-100">PRINT_FOUR</action>
     <action ID="wifiOff" rule="test.printBool" restrict="lock" priority="-100">off</action>
   </mode>
index 1762ee7edff204c3d493a2ee0057e385cc6671dd..4a8ecb37a115216a93b22da5ab1c64a04446397b 100644 (file)
@@ -12,6 +12,7 @@
             </xs:sequence>
             <xs:attribute name="name" type="xs:string" use="required" />
             <xs:attribute name="type" type="o:modeTypeT" use="required" />
+            <xs:attribute name="hidden" type="xs:boolean" use="optional" />
           </xs:complexType>
         </xs:element>
       </xs:sequence>
index 62e4bdc3b789125e86a277cc080cb53a7f25b105..bf4da24fa816b84ffd896fdd03bdef80c12c0bf6 100644 (file)
@@ -22,7 +22,7 @@
 MODES_NAMESPACE_USE;
 
 Mode::Mode()
-       : type(MODE_NORMAL)
+       : type(MODE_NORMAL), hidden(false)
 {
 }
 
@@ -50,35 +50,24 @@ const std::string Mode::getName() const
        return name;
 }
 
-void Mode::setModeType(const std::string &val)
+void Mode::setModeType(Mode::ModeType val)
 {
-       if ("normal" == val)
-               type = MODE_NORMAL;
-       else if ("exclusive" == val)
-               type = MODE_EXCLUSIVE;
-       else
-               type = MODE_ONESHOT;
+       type = val;
 }
 
-void Mode::setModeType(int val)
+Mode::ModeType Mode::getModeType() const
 {
-       switch (val) {
-       case MODES_TYPE_MODE_NORMAL:
-               type = MODE_NORMAL;
-               break;
-       // Exclusive mode is not allowed on making by user.
-       //case MODES_TYPE_MODE_EXCLUSIVE:
-       //      type = MODE_EXCLUSIVE;
-       //      break;
-       case MODES_TYPE_MODE_ONESHOT:
-       default:
-               type = MODE_ONESHOT;
-       }
+       return type;
 }
 
-Mode::ModeType Mode::getModeType() const
+void Mode::setHidden(bool val)
 {
-       return type;
+       hidden = val;
+}
+
+bool Mode::isHidden() const
+{
+       return hidden;
 }
 
 int Mode::apply()
index 0a92e6ef0bf3a921afdcbd0cf9778aaedcf1e3eb..f8b15d6000a9be74de5f88cfd5863e3189034f19 100644 (file)
@@ -36,10 +36,12 @@ public:
        void setName(const std::string &data);
        const std::string getName() const;
 
-       void setModeType(const std::string &data);
-       void setModeType(int val);
+       void setModeType(Mode::ModeType val);
        ModeType getModeType() const;
 
+       void setHidden(bool val);
+       bool isHidden() const;
+
        void addAction(Action *action);
        std::list<std::shared_ptr<Action>> getActionList() const;
 
@@ -52,6 +54,7 @@ public:
 private:
        std::string name;
        ModeType type;
+       bool hidden;
        std::list<std::shared_ptr<Action>> actionList;
        std::list<std::shared_ptr<Action>> undoList;
 #ifdef MDS_TEST
index 2b3cd60c54deba4c0bab2ce4ffcf3641d7c03d8f..a79bd10eb52dd7956e9a2b1f0c1d970e25eb0b43 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <dirent.h>
 #include <cstring>
+#include <utility>
 #include <string>
 #include <exception>
 #include "mdss.h"
@@ -68,16 +69,15 @@ ModeParser* ModeManager::getModeParser(const string &path)
        }
 }
 
-void ModeManager::addModeName(ModeParser *parser, const string &path)
+void ModeManager::addModeAttributes(ModeParser *parser, const string &path)
 {
        string modeName = parser->getModeName();
-       modeMap.insert(std::pair<string, string>(modeName, path));
+       bool hidden = parser->isHidden();
+       modeMap.insert(std::make_pair(modeName, std::make_pair(path, hidden)));
 
-       DBG("[%d] modeName : %s, modePath : %s", modeMap.size(), modeName.c_str(), path.c_str());
+       DBG("[%d] modeName : %s, modePath : %s, hidden : %s", modeMap.size(), modeName.c_str(), path.c_str(), hidden? "true": "false");
 }
 
-
-
 int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool isTest)
 {
        auto found = modeMap.find(modeName);
@@ -86,7 +86,7 @@ int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool i
                return MODES_ERROR_NO_DATA;
        }
 
-       string path = found->second;
+       string path = found->second.first;
        DBG("applyMode(%s)", path.c_str());
 
        try {
@@ -147,8 +147,8 @@ int ModeManager::registerMode(const Mode &mode)
                return MODES_ERROR_INVALID_PARAMETER;
        }
 
-       modeMap.insert(std::pair<string, string>(mode.getName(), filename));
-       DBG("[%d] Register modeName : %s, modePath : %s", modeMap.size(), mode.getName().c_str(), filename.c_str());
+       modeMap.insert(std::make_pair(mode.getName(), std::make_pair(filename, false)));
+       DBG("[%d] Register modeName : %s, modePath : %s, hidden : false", modeMap.size(), mode.getName().c_str(), filename.c_str());
 
        return MODES_ERROR_NONE;
 }
@@ -171,6 +171,9 @@ std::list<std::tuple<string, int>> ModeManager::getModes()
        std::list<std::tuple<string, int>> modeList;
 
        for (auto it = modeMap.begin(); it != modeMap.end(); ++it) {
+                       bool hidden = it->second.second;
+                       if (true == hidden)
+                               continue;
                int state = careTaker.isSavedMode(it->first);
                modeList.push_back(std::tuple<string, int>(it->first, state));
        }
@@ -201,7 +204,7 @@ bool ModeManager::makeModeMap(const string &dirPath)
                try {
                        ModeParser *modeParser = getModeParser(fileFullPath);
                        modeParser->validateMode(modeSyntaxFile);
-                       addModeName(modeParser, fileFullPath);
+                       addModeAttributes(modeParser, fileFullPath);
                        delete modeParser;
                } catch (ModesEx &e) {
                        ERR("parser(%s) Fail(%s)", fileFullPath.c_str(), e.what());
@@ -243,7 +246,7 @@ bool ModeManager::restoreUndoInfo(const string &dirPath)
                                throw ModesEx(ModesEx::NO_DATA);
                        }
 
-                       string path = found->second;
+                       string path = found->second.first;
                        std::unique_ptr<ModeParser> parser(getModeParser(path));
                        Mode mode = parser->getMode();
                        undoInfoParser.putUndoInfo(mode);
index d2f8306fb51131781123b85d88f69cd936e6918c..cc0c14250c4a7d44db892a46a2d4db1d8234c90a 100644 (file)
@@ -16,6 +16,7 @@
 #pragma once
 
 #include <map>
+#include <utility>
 #include <set>
 #include "mdss.h"
 #include "ModeParser.h"
@@ -45,10 +46,10 @@ public:
 private:
        bool makeModeMap(const std::string &dirPath);
        bool restoreUndoInfo(const std::string &dirPath);
-       void addModeName(ModeParser *parser, const std::string &path);
+       void addModeAttributes(ModeParser *parser, const std::string &path);
        ModeParser* getModeParser(const std::string &path);
 
-       std::map<std::string, std::string> modeMap;
+       std::map<std::string, std::pair<std::string, bool>> modeMap;
        std::set<std::string> modeDirList;
        std::string undoDir;
        std::string modeSyntaxFile;
index 43e59b6f5d599ff5d76e83620084147dd6ba49fc..cb234856d0fcad6ed0d425be172c43c166a5ffac 100644 (file)
@@ -15,6 +15,7 @@
  */
 #pragma once
 
+#include <utility>
 #include "mdss.h"
 #include "Mode.h"
 #include "RuleManager.h"
@@ -27,6 +28,7 @@ public:
 
        virtual Mode getMode() = 0;
        virtual std::string getModeName() = 0;
+       virtual bool isHidden() = 0;
        virtual void validateMode(const std::string &syntaxFile) = 0;
 protected:
        ModeParser(RuleManager &rMgr) :ruleMgr(rMgr)
index 3eb7ffc5ea176dc770975832d8cac9599daf74d0..17aba94880d42865cb3d0f75b7209d7547ebd411 100644 (file)
@@ -16,6 +16,7 @@
 #include "ModeXMLParser.h"
 #include <cstring>
 #include <string>
+#include <utility>
 #include <libxml/tree.h>
 #include <libxml/xmlschemas.h>
 #include "mdss.h"
@@ -28,7 +29,7 @@
 MODES_NAMESPACE_USE;
 
 ModeXMLParser::ModeXMLParser(const std::string &modeFile, RuleManager &rMgr, PluginManager &pMgr)
-       : ModeParser(rMgr), XMLParser(modeFile), pluginManager(pMgr)
+       : ModeParser(rMgr), XMLParser(modeFile), pluginManager(pMgr), isParsedModeAttr(false)
 {
 }
 
@@ -40,9 +41,24 @@ Mode ModeXMLParser::getMode()
 
 std::string ModeXMLParser::getModeName()
 {
-       if (!mode.getName().empty())
-               return mode.getName();
+       if (false == isParsedModeAttr) {
+               parseModeAttr();
+               isParsedModeAttr = true;
+       }
+       return mode.getName();
+}
+
+bool ModeXMLParser::isHidden()
+{
+       if (false == isParsedModeAttr) {
+               parseModeAttr();
+               isParsedModeAttr = true;
+       }
+       return mode.isHidden();
+}
 
+void ModeXMLParser::parseModeAttr()
+{
        xmlNodePtr root = getRoot();
        for (xmlNodePtr cur = root->children; cur; cur = cur->next) {
                if (xmlIsBlankNode(cur))
@@ -50,11 +66,10 @@ std::string ModeXMLParser::getModeName()
 
                if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::MODE)) {
                        mode.setName(extractModeName(cur));
+                       mode.setHidden(extractHidden(cur));
                        break;
                }
        }
-
-       return mode.getName();
 }
 
 void ModeXMLParser::validateMode(const std::string &xsd)
@@ -96,6 +111,7 @@ void ModeXMLParser::parseMode(xmlNodePtr node)
 {
        mode.setName(extractModeName(node));
        mode.setModeType(extractModeType(node));
+       mode.setHidden(extractHidden(node));
 }
 
 std::string ModeXMLParser::extractModeName(xmlNodePtr node)
@@ -103,9 +119,26 @@ std::string ModeXMLParser::extractModeName(xmlNodePtr node)
        return extractValueOfTag(node, ModesXMLTag::NAME);
 }
 
-std::string ModeXMLParser::extractModeType(xmlNodePtr node)
+Mode::ModeType ModeXMLParser::extractModeType(xmlNodePtr node)
 {
-       return extractValueOfTag(node, ModesXMLTag::TYPE);
+       std::string val = extractValueOfTag(node, ModesXMLTag::TYPE);
+       Mode::ModeType type;
+       if ("normal" == val)
+               type = Mode::MODE_NORMAL;
+       else if ("exclusive" == val)
+               type = Mode::MODE_EXCLUSIVE;
+       else
+               type = Mode::MODE_ONESHOT;
+       return type;
+}
+
+bool ModeXMLParser::extractHidden(xmlNodePtr node)
+{
+       std::string hidden = extractValueOfTag(node, ModesXMLTag::HIDDEN);
+       if ("true" == hidden)
+               return true;
+       else
+               return false;
 }
 
 void ModeXMLParser::parseUndo(xmlNodePtr node)
index 9d792cf84dc62468f9bfeaf46585b566015be443..cc5db70c45d6cb72dbae84aff161118a238fd4be 100644 (file)
@@ -16,6 +16,7 @@
 #pragma once
 
 #include <libxml/tree.h>
+#include <utility>
 #include "mdss.h"
 #include "ModeParser.h"
 #include "XMLParser.h"
@@ -30,6 +31,7 @@ public:
 
        Mode getMode() override;
        std::string getModeName() override;
+       bool isHidden() override;
        void validateMode(const std::string &xsd) override;
 
 private:
@@ -37,16 +39,19 @@ private:
        void parseElement(xmlNodePtr node);
        void parseMode(xmlNodePtr node);
        std::string extractModeName(xmlNodePtr node);
-       std::string extractModeType(xmlNodePtr node);
+       Mode::ModeType extractModeType(xmlNodePtr node);
+       bool extractHidden(xmlNodePtr node);
        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);
+       void parseModeAttr();
 
        PluginManager &pluginManager;
        Mode mode;
        std::string filePath;
+       bool isParsedModeAttr;
 };
 
 MODES_NAMESPACE_END
index 20968003cec3efb5294313b7791c906758e93c00..2de630369249e410689afbb369933c5a36ae14a2 100644 (file)
@@ -30,6 +30,7 @@ const xmlChar* const ModesXMLTag::TYPE = (xmlChar*)"type";
 //Mode
 const xmlChar* const ModesXMLTag::MODE = (xmlChar*)"mode";
 const xmlChar* const ModesXMLTag::NAME = (xmlChar*)"name";
+const xmlChar* const ModesXMLTag::HIDDEN = (xmlChar*)"hidden";
 //Action
 const xmlChar* const ModesXMLTag::ACTION = (xmlChar*)"action";
 const xmlChar* const ModesXMLTag::UNDO = (xmlChar*)"undo";
index 27bb7079501ee75c5dafb014b768d592fd65e559..5f2faa2dedc52f0d879bba94d5ccbea1532de795 100644 (file)
@@ -33,6 +33,7 @@ struct ModesXMLTag {
        //Mode
        static const xmlChar* const MODE;
        static const xmlChar* const NAME;
+       static const xmlChar* const HIDDEN;
        //Action
        static const xmlChar* const ACTION;
        static const xmlChar* const UNDO;
index f5edffa0b6531c63118f463ac9192a3710a7425f..6b0f2716e3eea6921b3f26ffca5bec9902887b9d 100644 (file)
@@ -138,12 +138,26 @@ Mode RequestHandler::getModefromData(GVariant *inData)
        gint32 type;
        GVariantIter *iter;
        Mode mode;
+       Mode::ModeType modeType;
 
        g_variant_get(inData, MODES_DBUS_MODE_SIG, &modeName, &type, &actionList);
        DBG("mode_name : %s // type : %d", modeName, type);
 
+       switch (type) {
+       case MODES_TYPE_MODE_NORMAL:
+               modeType = Mode::MODE_NORMAL;
+               break;
+       // Exclusive mode is not allowed on making by user.
+       //case MODES_TYPE_MODE_EXCLUSIVE:
+       //      type = MODE_EXCLUSIVE;
+       //      break;
+       case MODES_TYPE_MODE_ONESHOT:
+       default:
+               modeType = Mode::MODE_ONESHOT;
+       }
+
        mode.setName(modeName);
-       mode.setModeType(type);
+       mode.setModeType(modeType);
        g_free(modeName);
 
        g_variant_get(actionList, MODES_DBUS_ACTION_LIST_SIG, &iter);
index 39457a8e6aa8d918a6f43f473ebbbffaf40e2c93..a437392adf999a6efce81973a42dd478c65d76fa 100644 (file)
@@ -64,7 +64,12 @@ void ModeManagerTest::printModeMap()
                cout << "| "; cout.width(15); cout << "Mode Name" << " | " << "ModeXML file Path" << endl;
 
                for (auto it = mdMgr.modeMap.begin(); it != mdMgr.modeMap.end(); it++) {
-                       cout << "| ";  cout.width(15); cout << it->first.c_str() << " | " << it->second.c_str() << endl;
+                       cout << "| ";  cout.width(15); cout << it->first.c_str() << " | " << it->second.first.c_str() << " | ";
+                       if (it->second.second)
+                               cout << "hidden";
+                       else
+                               cout << "Not hidden";
+                       cout << endl;
                }
        }
 }
index d526341704bbf4ed8ded00520cd40509284d8aa7..ea4fece73a066b6441c83d1d9cfff7d44f82f9b1 100644 (file)
@@ -65,7 +65,6 @@ list<shared_ptr<Action>> ParserTest::getActionList(Mode& m)
 TEST_F(ParserTest, getModeName)
 {
        ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, piMgr);
-       string modename = modeparser.getModeName();
 
        EXPECT_EQ("ex1", modeparser.getModeName());
 }
@@ -77,6 +76,20 @@ TEST_F(ParserTest, modeGetName)
        EXPECT_EQ("ex2", mode.getName());
 }
 
+TEST_F(ParserTest, isHiddenTrue)
+{
+       ModeXMLParser modeparser("tizen_ex2_mode.xml", ruleMgr, piMgr);
+
+       EXPECT_EQ(true, modeparser.isHidden());
+}
+
+TEST_F(ParserTest, isHiddenFalse)
+{
+       ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, piMgr);
+
+       EXPECT_EQ(false, modeparser.isHidden());
+}
+
 TEST_F(ParserTest, getModeType)
 {
        ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, piMgr);