<?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>
</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>
MODES_NAMESPACE_USE;
Mode::Mode()
- : type(MODE_NORMAL)
+ : type(MODE_NORMAL), hidden(false)
{
}
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()
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;
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
#include <dirent.h>
#include <cstring>
+#include <utility>
#include <string>
#include <exception>
#include "mdss.h"
}
}
-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);
return MODES_ERROR_NO_DATA;
}
- string path = found->second;
+ string path = found->second.first;
DBG("applyMode(%s)", path.c_str());
try {
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;
}
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));
}
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());
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);
#pragma once
#include <map>
+#include <utility>
#include <set>
#include "mdss.h"
#include "ModeParser.h"
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;
*/
#pragma once
+#include <utility>
#include "mdss.h"
#include "Mode.h"
#include "RuleManager.h"
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)
#include "ModeXMLParser.h"
#include <cstring>
#include <string>
+#include <utility>
#include <libxml/tree.h>
#include <libxml/xmlschemas.h>
#include "mdss.h"
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)
{
}
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))
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)
{
mode.setName(extractModeName(node));
mode.setModeType(extractModeType(node));
+ mode.setHidden(extractHidden(node));
}
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)
#pragma once
#include <libxml/tree.h>
+#include <utility>
#include "mdss.h"
#include "ModeParser.h"
#include "XMLParser.h"
Mode getMode() override;
std::string getModeName() override;
+ bool isHidden() override;
void validateMode(const std::string &xsd) override;
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
//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";
//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;
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);
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;
}
}
}
TEST_F(ParserTest, getModeName)
{
ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, piMgr);
- string modename = modeparser.getModeName();
EXPECT_EQ("ex1", modeparser.getModeName());
}
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);