SET(MODES_XSD_DEFAULT_DIR "/usr/share/modes/schema")
ENDIF(NOT DEFINED MODES_XSD_DEFAULT_DIR)
ADD_DEFINITIONS("-DMODES_XSD_DEFAULT_DIR=\"${MODES_XSD_DEFAULT_DIR}\"")
+
+IF(NOT DEFINED MODES_UNDO_INFO_DEFAULT_DIR)
+ MESSAGE("No MODES_UNDO_INFO_DEFAULT_DIR. Check build system")
+ SET(MODES_UNDO_INFO_DEFAULT_DIR "/var/lib/modes/undo-info")
+ENDIF(NOT DEFINED MODES_UNDO_INFO_DEFAULT_DIR)
+ADD_DEFINITIONS("-DMODES_UNDO_INFO_DEFAULT_DIR=\"${MODES_UNDO_INFO_DEFAULT_DIR}\"")
#warning "MODES_XSD_DEFAULT_DIR is redefined"
#endif
+#ifndef MODES_UNDO_INFO_DEFAULT_DIR
+#define MODES_UNDO_INFO_DEFAULT_DIR "/var/lib/modes/undo-info"
+#warning "MODES_UNDO_INFO_DEFAULT_DIR is redefined"
+#endif
+
#define MODES_MODE_DEFAULT_XSD_FILE "tizen_mode.xsd"
#define MODES_ACTIONRULE_DEFAULT_XSD_FILE "tizen_action_rule.xsd"
#define MODES_MODE_DEFAULT_XSD MODES_XSD_DEFAULT_DIR "/" MODES_MODE_DEFAULT_XSD_FILE
#define MODES_PLUGIN_LIB_PREFIX "libmodes-plugin"
#define MODES_ACTIONRULE_FILE_SUFFIX "_rule.xml"
#define MODES_MODE_FILE_SUFFIX "_mode.xml"
+
+#define MODES_UNDO_FILE_SUFFIX "_undo.xml"
return ret;
}
+ virtual PluginAction* getUndoAction(const std::string &key, const std::string &info)
+ {
+ return nullptr;
+ }
+ virtual int serializeAction(PluginAction *pluginAction, std::string *output)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
void freeAction(PluginAction *pluginAction)
{
delete pluginAction;
{
return MODES_ERROR_NOT_SUPPORTED;
}
+ virtual int serialize(std::string *output)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ virtual int parse(const std::string &data)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
protected:
void setName(const std::string &actionName)
{
%define modes_plugin_dir %{_libdir}/modes-plugins
%define modes_data_dir %{_datadir}/%{name}
%define modes_test_dir %{_bindir}/%{name}
+%define modes_info_dir /var/lib/%{name}
%prep
%setup -q
-DSYSTEMD_DIR:PATH=%{_unitdir} \
-DSYSCONF_DIR:PATH=%{_sysconfdir} \
-DMODES_MODE_DEFAULT_DIR:PATH=%{modes_data_dir}/mode \
+ -DMODES_UNDO_INFO_DEFAULT_DIR:PATH=%{modes_info_dir}/undo-info \
-DMODES_CUSTOM_MODE_DEFAULT_DIR:PATH=%{modes_data_dir}/custom-mode \
-DMODES_ACTIONRULE_DEFAULT_DIR:PATH=%{modes_data_dir}/rule \
-DMODES_XSD_DEFAULT_DIR:PATH=%{modes_data_dir}/schema \
install -d -m 755 %{buildroot}%{modes_data_dir}/mode
install -d -m 755 %{buildroot}%{modes_data_dir}/rule
install -d -m 755 %{buildroot}%{modes_data_dir}/custom-mode
+install -d -m 755 %{buildroot}%{modes_info_dir}/undo-info
install -m 0644 example/mode/*ex*_mode.xml %{buildroot}%{modes_data_dir}/mode/
install -m 0644 example/rule/*ex*_rule.xml %{buildroot}%{modes_data_dir}/rule/
install -m 0644 example/mode/*conflict*_mode.xml %{buildroot}%{modes_test_dir}/
systemctl restart %{name}.service
%files
-%attr(0755,system_fw,system_fw) %{modes_data_dir}/custom-mode
%manifest %{name}.manifest
%{_bindir}/mode-supervisor
%{_unitdir}/%{name}.service
%{modes_data_dir}/schema/*
%dir %{modes_data_dir}/mode
%dir %{modes_data_dir}/rule
+%dir %{modes_info_dir}/undo-info
+%attr(0755,system_fw,system_fw) %{modes_info_dir}/undo-info
%dir %{modes_data_dir}/custom-mode
+%attr(0755,system_fw,system_fw) %{modes_data_dir}/custom-mode
%license LICENSE.APLv2
%files lib
int set(const std::string &key, const std::string &val, PluginAction **pluginAction) override;
int undo(PluginAction *pluginAction) override;
+ PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+ int serializeAction(PluginAction *pluginAction, std::string *output) override;
int getInt(const std::string &key) override;
double getDouble(const std::string &key) override;
return MODES_ERROR_NONE;
}
+PluginAction* TestPlugin::getUndoAction(const std::string &key, const std::string &info)
+{
+ // parse the key for making PluginAction
+ TestPluginAction *piAction = new TestPluginAction();
+ piAction->parse(info);
+
+ return piAction;
+}
+
+int TestPlugin::serializeAction(PluginAction *piAction, std::string *output)
+{
+ RETV_IF(nullptr == piAction, MODES_ERROR_INVALID_PARAMETER);
+
+ int ret = piAction->serialize(output);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("serialize() Fail(%d)", ret);
+ return ret;
+ }
+
+ return MODES_ERROR_NONE;
+}
+
int TestPlugin::getInt(const std::string &key)
{
DBG("TestPlugin::getInt(%s)", key.c_str());
#include "TestPluginAction.h"
#include "modes_errors.h"
+#include "common/log.h"
#include "common/definitions.h"
MODES_NAMESPACE_USE;
int TestPluginAction::undo()
{
+ DBG("TestPluginAction::undo() is Called");
+ return MODES_ERROR_NONE;
+}
+
+int TestPluginAction::serialize(std::string *output)
+{
+ *output = "testAction";
+ return MODES_ERROR_NONE;
+}
+
+int TestPluginAction::parse(const std::string &info)
+{
+ DBG("serialized info(%s)", info.c_str());
return MODES_ERROR_NONE;
}
~TestPluginAction() override;
int undo() override;
+ int serialize(std::string *output) override;
+ int parse(const std::string &data) override;
};
MODES_NAMESPACE_END
void Action::printInfo()
{
- DBG("Action(%s):ID(%s), Restrict(%d)", getRuleName().c_str(), getID().c_str(), getRestrict());
+ DBG("Action(%s):ID(%s), Restrict(%d) piAction(%p)", getRuleName().c_str(), getID().c_str(), getRestrict(), piAction);
}
void Action::setRuleName(const std::string &data)
virtual int apply() = 0;
virtual int applyOneShot() = 0;
virtual void undo() = 0;
-
+ virtual int restoreUndoInfo(const std::string &info) = 0;
+ virtual std::string backupUndoInfo() = 0;
protected:
std::string ruleName;
Plugin *plugin;
char ArgumentParser::args_doc[] =
"modeXMLDirPath1 [modeXMLDirPath2] [--pluginDir=../plugin]"
" [--modeXsdFilePath=..example/tizen_mode.xsd] [--ruleXsdFilePath=..example/tizen_rule.xsd]"
- " [--ruleDir=../example] [--[--help]";
+ " [--ruleDir=../example] [--undoInfoDir=../example] [--[--help]";
struct argp_option ArgumentParser::options[] = {
{"pluginDir", 'p', "pluginDirPath", OPTION_ARG_OPTIONAL, "Set directory of plugin"},
{"modeXsdFilePath", 'm', "modeXsdFilePath", OPTION_ARG_OPTIONAL, "Set mode xsd(schema) file path"},
{"ruleXsdFilePath", 'a', "actionRuleXsdFilePath", OPTION_ARG_OPTIONAL, "Set action rule xsd(schema) file path"},
{"ruleDir", 's', "actionRuleDirPath", OPTION_ARG_OPTIONAL, "Set directory of Action Rule file"},
+ {"undoInfoDir", 'u', "UndoInfoDirPath", OPTION_ARG_OPTIONAL, "Set directory of Undo Information file"},
{ 0 }
};
state->next++;
}
break;
+ case 'u':
+ nextArg = state->argv[state->next];
+ if (nextArg && *nextArg != '-') {
+ parser->undoInfoDir = nextArg;
+ state->next++;
+ }
+ break;
case ARGP_KEY_NO_ARGS:
if (parser->modeDirCount == 0)
argp_usage(state);
ArgumentParser::ArgumentParser()
:modeDirCount(0), modeXMLDirList(NULL), modeXsdFile(NULL),
- actionRuleDir(NULL), actionRuleXsdFile(NULL), pluginDir(NULL)
+ actionRuleDir(NULL), actionRuleXsdFile(NULL), pluginDir(NULL), undoInfoDir(NULL)
{
}
config.pluginDir = MODES_PLUGIN_DEFAULT_DIR;
}
+ if (this->undoInfoDir) {
+ DBG("undoInfo dir path : %s", this->undoInfoDir);
+ config.undoInfoDir = this->undoInfoDir;
+ } else {
+ config.undoInfoDir = MODES_UNDO_INFO_DEFAULT_DIR;
+ }
+
return config;
}
char *actionRuleDir;
char *actionRuleXsdFile;
char *pluginDir;
+ char *undoInfoDir;
static char argp_doc[];
static char args_doc[];
void addUndo(Action *action);
std::list<std::shared_ptr<Action>> getUndoList() const;
+ void addUndoInfo(const std::string &rule, const std::string &info);
+
int apply();
int applyOneShot();
void undo();
#include "ModeCareTaker.h"
#include "mdss.h"
+#include "XMLGenerator.h"
MODES_NAMESPACE_USE;
ModeCareTaker::ModeCareTaker()
- : exclusive(false)
+ : undoDir(MODES_UNDO_INFO_DEFAULT_DIR), exclusive(false)
{
}
-void ModeCareTaker::saveMode(const Mode &mode)
+void ModeCareTaker::setOptions(const std::string &undoInfoDir)
+{
+ undoDir = undoInfoDir;
+}
+
+void ModeCareTaker::restoreMode(const Mode &mode)
+{
+ savedModes.insert(std::pair<std::string, Mode>(mode.getName(), mode));
+ exclusive = (Mode::MODE_EXCLUSIVE == mode.getModeType());
+}
+
+void ModeCareTaker::pushMode(const Mode &mode)
{
savedModes.insert(std::pair<std::string, Mode>(mode.getName(), mode));
exclusive = (Mode::MODE_EXCLUSIVE == mode.getModeType());
+
+ XMLGenerator gen;
+ gen.makeUndoInfoXML(undoDir + "/tizen_" + mode.getName() + MODES_UNDO_FILE_SUFFIX, mode);
}
-int ModeCareTaker::undoMode(const std::string &name)
+int ModeCareTaker::popMode(const std::string &name, Mode &mode)
{
auto found = savedModes.find(name);
if (savedModes.end() == found) {
return MODES_ERROR_NO_DATA;
}
- Mode &mode = found->second;
+ std::string filePath = undoDir + "/tizen_" + name + MODES_UNDO_FILE_SUFFIX;
+ if (0 != remove(filePath.c_str()))
+ ERR("remove(%s) Fail(%s)", filePath.c_str(), strerror(errno));
+
+ mode = found->second;
if (Mode::MODE_EXCLUSIVE == mode.getModeType())
exclusive = false;
- mode.undo();
savedModes.erase(found);
ModeCareTaker();
~ModeCareTaker() = default;
- void saveMode(const Mode &mode);
- int undoMode(const std::string &name);
+ void setOptions(const std::string &undoInfoDir);
+ void restoreMode(const Mode &mode);
+ void pushMode(const Mode &mode);
+ int popMode(const std::string &name, Mode &mode);
bool isSavedMode(const std::string &name);
bool isExclusive();
bool checkConflictAction(const Mode &mode);
private:
bool findRestrictAction(const std::string &ruleName);
std::map<std::string, Mode> savedModes;
+ std::string undoDir;
bool exclusive;
};
#include "mdss.h"
#include "ModesEx.h"
#include "ModeXMLParser.h"
+#include "UndoInfoParser.h"
#include "XMLGenerator.h"
#include "ConflictManager.h"
{
}
+//it should be called before init()
+void ModeManager::setOptions(const std::set<string> &modeDirs, const string &xsdFile, const string &undoInfoDir)
+{
+ modeDirList = modeDirs;
+ modeSyntaxFile = xsdFile;
+ undoDir = undoInfoDir;
+ careTaker.setOptions(undoDir);
+}
+
//it should be called after setOption()
void ModeManager::init()
{
makeModeMap(*it);
DBG("Mode Directory(%s) added", it->c_str());
}
+ restoreUndoInfo(undoDir);
}
// TODO: apply better polymorphism
ModeParser* ModeManager::getModeParser(const string &path)
{
- int pos = path.find_last_of(".");
- if (MDS_EQUAL == path.substr(pos + 1).compare("xml")) {
+ const size_t suffixLen = sizeof("xml") - 1;
+ if (suffixLen < path.length()
+ || path.compare(path.length() - suffixLen, suffixLen, "xml")) {
return new ModeXMLParser(path, ruleMgr, pluginMgr);
} else {
ERR("Wrong path(%s)", path.c_str());
}
}
-void ModeManager::addModeName(ModeParser *parser, string &path)
+void ModeManager::addModeName(ModeParser *parser, const string &path)
{
string modeName = parser->getModeName();
modeMap.insert(std::pair<string, string>(modeName, path));
mode.undo();
return ret;
}
- careTaker.saveMode(mode);
+ careTaker.pushMode(mode);
}
} catch (ModesEx &e) {
ERR("apply Fail(%s)", e.what());
int ModeManager::registerMode(const Mode &mode)
{
- std::string filename;
+ string filename;
XMLGenerator xmlWriter;
try {
return MODES_ERROR_NONE;
}
-int ModeManager::undoMode(const std::string & modeName)
+int ModeManager::undoMode(const string &modeName)
{
- return careTaker.undoMode(modeName);
+ Mode mode;
+ int ret = careTaker.popMode(modeName, mode);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("popMode() Fail(%d)", ret);
+ return ret;
+ }
+ mode.undo();
+
+ return MODES_ERROR_NONE;
}
-std::list<std::tuple<std::string, int>> ModeManager::getModes()
+std::list<std::tuple<string, int>> ModeManager::getModes()
{
- std::list<std::tuple<std::string, int>> modeList;
+ std::list<std::tuple<string, int>> modeList;
for (auto it = modeMap.begin(); it != modeMap.end(); ++it) {
int state = careTaker.isSavedMode(it->first);
- modeList.push_back(std::tuple<std::string, int>(it->first, state));
+ modeList.push_back(std::tuple<string, int>(it->first, state));
}
return modeList;
}
-//it should be called before init()
-void ModeManager::setOptions(const std::set<string> &modeDirs, const string &xsdFile)
-{
- modeDirList = modeDirs;
- modeSyntaxFile = xsdFile;
-}
-
bool ModeManager::makeModeMap(const string &dirPath)
{
DBG("dirPath : [%s]", dirPath.c_str());
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
string file(entry->d_name);
- size_t pos = file.find_last_of("_");
- if (string::npos == pos
- || file.compare(pos, sizeof(MODES_MODE_FILE_SUFFIX) - 1, MODES_MODE_FILE_SUFFIX)) {
+ const size_t suffixLen = sizeof(MODES_MODE_FILE_SUFFIX) - 1;
+ if (file.length() < suffixLen
+ || file.compare(file.length() - suffixLen, suffixLen, MODES_MODE_FILE_SUFFIX)) {
continue;
}
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(%s)", dirPath.c_str(), strerror(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 = found->second;
+ std::unique_ptr<ModeParser> parser(getModeParser(path));
+ Mode mode = parser->getMode();
+ undoInfoParser.putUndoInfo(mode);
+
+ careTaker.restoreMode(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(%s)", fileFullPath.c_str(), strerror(errno));
+ }
+ }
+
+ closedir(dir);
+ return true;
+}
+
void ModeManager::addModeDirectory(const string &dirPath)
{
auto result = modeDirList.find(dirPath);
public:
ModeManager(RuleManager &rMgr, PluginManager &pMgr);
- void setOptions(const std::set<std::string> &modeDirs, const std::string &xsdFile);
+ void setOptions(const std::set<std::string> &modeDirs, const std::string &xsdFile, const std::string &undoInfoDir);
void init();
void addModeDirectory(const std::string &dirPath);
int applyMode(const std::string &modeName);
std::list<std::tuple<std::string, int>> getModes();
private:
bool makeModeMap(const std::string &dirPath);
- void addModeName(ModeParser *parser, std::string &path);
+ bool restoreUndoInfo(const std::string &dirPath);
+ void addModeName(ModeParser *parser, const std::string &path);
ModeParser* getModeParser(const std::string &path);
std::map<std::string, std::string> modeMap;
std::set<std::string> modeDirList;
+ std::string undoDir;
std::string modeSyntaxFile;
RuleManager &ruleMgr;
PluginManager &pluginMgr;
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ModeTag.h"
-
-MODES_NAMESPACE_USE;
-
-const xmlChar* const ModeTag::XML_VERSION = (xmlChar*)"1.0";
-const xmlChar* const ModeTag::XML_ENCODING = (xmlChar*)"utf-8";
-const xmlChar* const ModeTag::TIZENMODES = (xmlChar*)"tizenModes";
-const xmlChar* const ModeTag::XMLNS = (xmlChar*)"xmlns";
-const xmlChar* const ModeTag::XMLNS_STR = (xmlChar*)"http://www.tizen.org";
-const xmlChar* const ModeTag::VERSION = (xmlChar*)"version";
-const xmlChar* const ModeTag::CUR_VERSION = (xmlChar*)"6.0";
-const xmlChar* const ModeTag::MODE = (xmlChar*)"mode";
-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";
-const xmlChar* const ModeTag::ID = (xmlChar*)"ID";
-const char* const ModeTag::RESTICT_LOCK = "lock";
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <libxml/tree.h>
-#include "mdss.h"
-
-MODES_NAMESPACE_BEGIN
-
-struct ModeTag {
- static const xmlChar* const XML_VERSION;
- static const xmlChar* const XML_ENCODING;
- static const xmlChar* const TIZENMODES;
- static const xmlChar* const XMLNS;
- static const xmlChar* const XMLNS_STR;
- static const xmlChar* const VERSION;
- static const xmlChar* const CUR_VERSION;
- static const xmlChar* const MODE;
- static const xmlChar* const NAME;
- 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;
- static const xmlChar* const ID;
- static const xmlChar* const PRIORITY;
- static const xmlChar* const BEFORE;
- static const xmlChar* const AFTER;
- static const char* const RESTICT_LOCK;
-};
-
-MODES_NAMESPACE_END
#include "ModesEx.h"
#include "TAction.h"
#include "XMLParser.h"
-#include "ModeTag.h"
+#include "ModesXMLTag.h"
MODES_NAMESPACE_USE;
ModeXMLParser::ModeXMLParser(const std::string &modeFile, RuleManager &rMgr, PluginManager &pMgr)
- : ModeParser(rMgr), pluginManager(pMgr)
+ : ModeParser(rMgr), XMLParser(modeFile), pluginManager(pMgr)
{
- this->modeFile = modeFile;
}
Mode ModeXMLParser::getMode()
{
- XMLParser parser(modeFile);
- iterateElement(parser.getRoot());
+ iterateElement(getRoot());
return mode;
}
std::string ModeXMLParser::getModeName()
{
- if (!mode.getName().empty()) {
+ if (!mode.getName().empty())
return mode.getName();
- }
-
- XMLParser parser(modeFile);
- xmlNodePtr cur, root;
- root = parser.getRoot();
- for (cur = root->children; cur; cur = cur->next) {
+ xmlNodePtr root = getRoot();
+ for (xmlNodePtr cur = root->children; cur; cur = cur->next) {
if (xmlIsBlankNode(cur))
continue;
- if (MDS_EQUAL == xmlStrcmp(cur->name, ModeTag::MODE)) {
- mode.setName(getModeName(cur));
+ if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::MODE)) {
+ mode.setName(extractModeName(cur));
break;
}
}
void ModeXMLParser::validateMode(const std::string &xsd)
{
- XMLParser parser = XMLParser(modeFile);
try {
- parser.validate(xsd);
+ validate(xsd);
} catch (ModesEx &e) {
ERR("validate() Fail(%s)", e.what());
throw ModesEx(ModesEx::INVALID_ARG);
if (xmlIsBlankNode(cur))
continue;
- getDatafromNode(cur);
+ parseElement(cur);
iterateElement(cur->children);
}
}
-void ModeXMLParser::getDatafromNode(xmlNodePtr node)
+void ModeXMLParser::parseElement(xmlNodePtr node)
{
- if (MDS_EQUAL == xmlStrcmp(node->name, ModeTag::MODE)) {
+ if (MDS_EQUAL == xmlStrcmp(node->name, ModesXMLTag::MODE)) {
parseMode(node);
- } else if (MDS_EQUAL == xmlStrcmp(node->name, ModeTag::ACTION)) {
+ } else if (MDS_EQUAL == xmlStrcmp(node->name, ModesXMLTag::ACTION)) {
parseAction(node);
- } else if (MDS_EQUAL == xmlStrcmp(node->name, ModeTag::UNDO)) {
+ } else if (MDS_EQUAL == xmlStrcmp(node->name, ModesXMLTag::UNDO)) {
parseUndo(node);
} else {
DBG("Unhandled node : %s", node->name);
void ModeXMLParser::parseMode(xmlNodePtr node)
{
- mode.setName(getModeName(node));
- mode.setModeType(getModeType(node));
- mode.setCustomized(getModeCustom(node));
+ mode.setName(extractModeName(node));
+ mode.setModeType(extractModeType(node));
+ mode.setCustomized(extractModeCustom(node));
}
-std::string ModeXMLParser::getModeName(xmlNodePtr node)
+std::string ModeXMLParser::extractModeName(xmlNodePtr node)
{
- return getXmlTagStringValue(node, ModeTag::NAME);
+ return extractValueOfTag(node, ModesXMLTag::NAME);
}
-std::string ModeXMLParser::getModeType(xmlNodePtr node)
+std::string ModeXMLParser::extractModeType(xmlNodePtr node)
{
- return getXmlTagStringValue(node, ModeTag::TYPE);
+ return extractValueOfTag(node, ModesXMLTag::TYPE);
}
-bool ModeXMLParser::getModeCustom(xmlNodePtr node)
+bool ModeXMLParser::extractModeCustom(xmlNodePtr node)
{
- std::string data = getXmlTagStringValue(node, ModeTag::CUSTOM);
+ std::string data = extractValueOfTag(node, ModesXMLTag::CUSTOM);
return ("yes" == data);
}
-std::string ModeXMLParser::getXmlTagStringValue(xmlNodePtr node, const xmlChar* tag)
-{
- char *xmlTagValue;
- std::string xmlTagString;
-
- xmlTagValue = (char*)xmlGetProp(node, tag);
- if (xmlTagValue == NULL) {
- ERR("attribute(%s) is NULL. ", tag);
- xmlTagString = "";
- return xmlTagString;
- }
-
- xmlTagString = xmlTagValue;
- xmlFree(xmlTagValue);
- return xmlTagString;
-}
-
void ModeXMLParser::parseUndo(xmlNodePtr node)
{
Action *action = parseActionInfo(node);
void ModeXMLParser::parseActionAttr(xmlNodePtr node, Action *action)
{
- char *restictProp = (char*)xmlGetProp(node, ModeTag::RESTICT);
- if (restictProp && MDS_EQUAL == strcmp(restictProp, ModeTag::RESTICT_LOCK))
+ char *restictProp = (char*)xmlGetProp(node, ModesXMLTag::RESTICT);
+ if (restictProp && MDS_EQUAL == strcmp(restictProp, ModesXMLTag::RESTICT_LOCK))
action->setRestrict(Action::REQ_LOCK);
else
action->setRestrict(Action::REQ_NONE);
xmlFree(restictProp);
- char *stopOnErrProp = (char*)xmlGetProp(node, ModeTag::STOP_ON_ERR);
+ char *stopOnErrProp = (char*)xmlGetProp(node, ModesXMLTag::STOP_ON_ERR);
if (stopOnErrProp && MDS_EQUAL == strcmp(stopOnErrProp, "true"))
action->setStopOnErr(true);
else
Action* ModeXMLParser::parseActionInfo(xmlNodePtr node)
{
- char *ruleProp = (char*)xmlGetProp(node, ModeTag::RULE);
+ char *ruleProp = (char*)xmlGetProp(node, ModesXMLTag::RULE);
if (ruleProp == NULL) {
- ERR("rule attribute is null! [%s]", ModeTag::RULE);
+ ERR("rule attribute is null! [%s]", ModesXMLTag::RULE);
throw ModesEx(ModesEx::PARSER_ERROR, "rule attribute is null!");
}
#include <libxml/tree.h>
#include "mdss.h"
#include "ModeParser.h"
+#include "XMLParser.h"
#include "PluginManager.h"
MODES_NAMESPACE_BEGIN
-class ModeXMLParser : public ModeParser {
+class ModeXMLParser : public ModeParser, public XMLParser {
public:
ModeXMLParser(const std::string &modeFile, RuleManager &mgr, PluginManager &pluginMgr);
~ModeXMLParser() = default;
private:
void iterateElement(xmlNodePtr node);
- void getDatafromNode(xmlNodePtr node);
+ void parseElement(xmlNodePtr node);
void parseMode(xmlNodePtr node);
- std::string getModeName(xmlNodePtr node);
- std::string getModeType(xmlNodePtr node);
- bool getModeCustom(xmlNodePtr node);
- std::string getXmlTagStringValue(xmlNodePtr node, const xmlChar *tag);
+ std::string extractModeName(xmlNodePtr node);
+ std::string extractModeType(xmlNodePtr node);
+ bool extractModeCustom(xmlNodePtr node);
void parseActionAttr(xmlNodePtr node, Action *action);
void parseAction(xmlNodePtr node);
void parseUndo(xmlNodePtr node);
PluginManager &pluginManager;
Mode mode;
- std::string modeFile;
+ std::string filePath;
};
MODES_NAMESPACE_END
std::string modeXsdFile;
std::string actionRuleXsdFile;
std::string actionRuleDir;
+ std::string undoInfoDir;
};
MODES_NAMESPACE_END
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ModesXMLTag.h"
+
+MODES_NAMESPACE_USE;
+
+//common
+const xmlChar* const ModesXMLTag::XML_VERSION = (xmlChar*)"1.0";
+const xmlChar* const ModesXMLTag::XML_ENCODING = (xmlChar*)"utf-8";
+const xmlChar* const ModesXMLTag::TIZENMODES = (xmlChar*)"tizenModes";
+const xmlChar* const ModesXMLTag::XMLNS = (xmlChar*)"xmlns";
+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";
+//Mode
+const xmlChar* const ModesXMLTag::MODE = (xmlChar*)"mode";
+const xmlChar* const ModesXMLTag::NAME = (xmlChar*)"name";
+const xmlChar* const ModesXMLTag::TYPE = (xmlChar*)"type";
+const xmlChar* const ModesXMLTag::CUSTOM = (xmlChar*)"custom";
+//Action
+const xmlChar* const ModesXMLTag::ACTION = (xmlChar*)"action";
+const xmlChar* const ModesXMLTag::UNDO = (xmlChar*)"undo";
+const xmlChar* const ModesXMLTag::RULE = (xmlChar*)"rule";
+const xmlChar* const ModesXMLTag::STOP_ON_ERR = (xmlChar*)"stopOnErr";
+const xmlChar* const ModesXMLTag::RESTICT = (xmlChar*)"restrict";
+const char* const ModesXMLTag::RESTICT_LOCK = "lock";
+const xmlChar* const ModesXMLTag::ID = (xmlChar*)"ID";
+//UndoInfo
+const xmlChar* const ModesXMLTag::UNDO_INFO = (xmlChar*)"UndoInfo";
+const xmlChar* const ModesXMLTag::INFO = (xmlChar*)"info";
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <libxml/tree.h>
+#include "mdss.h"
+
+MODES_NAMESPACE_BEGIN
+
+struct ModesXMLTag {
+//common
+ static const xmlChar* const XML_VERSION;
+ static const xmlChar* const XML_ENCODING;
+ static const xmlChar* const TIZENMODES;
+ static const xmlChar* const XMLNS;
+ static const xmlChar* const XMLNS_STR;
+ static const xmlChar* const VERSION;
+ static const xmlChar* const CUR_VERSION;
+//Mode
+ static const xmlChar* const MODE;
+ static const xmlChar* const NAME;
+ static const xmlChar* const TYPE;
+ static const xmlChar* const CUSTOM;
+//Action
+ 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;
+ static const char* const RESTICT_LOCK;
+ static const xmlChar* const ID;
+//UndoInfo
+ static const xmlChar* const UNDO_INFO;
+ static const xmlChar* const INFO;
+};
+
+MODES_NAMESPACE_END
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
string file(entry->d_name);
- size_t pos = file.find_last_of("_");
- if (string::npos == pos
- || file.compare(pos, sizeof(MODES_ACTIONRULE_FILE_SUFFIX) - 1, MODES_ACTIONRULE_FILE_SUFFIX)) {
+ const size_t suffixLen = sizeof(MODES_ACTIONRULE_FILE_SUFFIX) - 1;
+ if (file.length() < suffixLen
+ || file.compare(file.length() - suffixLen, suffixLen, MODES_ACTIONRULE_FILE_SUFFIX)) {
continue;
}
void Supervisor::setOptions(const ModesConfig &config)
{
- modeMgr.setOptions(config.modeXMLDirs, config.modeXsdFile);
+ modeMgr.setOptions(config.modeXMLDirs, config.modeXsdFile, config.undoInfoDir);
pluginMgr.setPluginDir(config.pluginDir);
ruleMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile);
}
return MODES_ERROR_NONE;
}
+ int restoreUndoInfo(const std::string &info) override
+ {
+ RETVM_IF(NULL == plugin, MODES_ERROR_NO_DATA, "Action(%s) : No plugin", ruleName.c_str());
+
+ int pos = ruleName.find_first_of(".");
+ PluginAction *tmpAction = plugin->getUndoAction(ruleName.substr(pos + 1), info);
+ if (nullptr == tmpAction) {
+ ERR("plugin(%s) getUndoAction() Fail", plugin->getName().c_str());
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ plugin->setChangedCallback(valueChangedCallback, ruleName.substr(pos + 1), this);
+
+ piAction = tmpAction;
+ return MODES_ERROR_NONE;
+ }
+
+ std::string backupUndoInfo() override
+ {
+ RETVM_IF(NULL == plugin, std::string(), "Action(%s) : No plugin", ruleName.c_str());
+
+ std::string backup;
+ int ret = plugin->serializeAction(piAction, &backup);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("plugin(%s) serializeAction() Fail(%d)", plugin->getName().c_str(), ret);
+ return std::string();
+ }
+ return backup;
+ }
+
int apply() override
{
RETVM_IF(NULL == plugin, MODES_ERROR_NO_DATA, "Action(%s) : No plugin", ruleName.c_str());
PluginAction *tmpAction = nullptr;
int ret = plugin->set(ruleName.substr(pos + 1), value, &tmpAction);
if (MODES_ERROR_NONE != ret) {
- ERR("plugin(%s) set Fail(%d)", plugin->getName().c_str(), ret);
+ ERR("plugin(%s) set() Fail(%d)", plugin->getName().c_str(), ret);
return ret;
}
plugin->setChangedCallback(valueChangedCallback, ruleName.substr(pos + 1), this);
PluginAction *tmpAction = nullptr;
int ret = plugin->set(ruleName.substr(pos + 1), value, &tmpAction);
if (MODES_ERROR_NONE != ret) {
- ERR("plugin(%s) set Fail(%d)", plugin->getName().c_str(), ret);
+ ERR("plugin(%s) set() Fail(%d)", plugin->getName().c_str(), ret);
return ret;
}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "UndoInfoParser.h"
+#include <cstring>
+#include <string>
+#include <algorithm>
+#include <libxml/tree.h>
+#include <libxml/xmlschemas.h>
+#include "mdss.h"
+#include "ModesEx.h"
+#include "XMLParser.h"
+#include "ModesXMLTag.h"
+
+MODES_NAMESPACE_USE;
+
+UndoInfoParser::UndoInfoParser(const std::string &file)
+ : XMLParser(file)
+{
+}
+
+std::string UndoInfoParser::getModeName()
+{
+ XMLParser parser(filePath);
+ xmlNodePtr root = parser.getRoot();
+ for (xmlNodePtr cur = root->children; cur; cur = cur->next) {
+ if (xmlIsBlankNode(cur))
+ continue;
+
+ if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::UNDO_INFO))
+ return extractValueOfTag(cur, ModesXMLTag::NAME);
+ }
+
+ return std::string();
+}
+
+void UndoInfoParser::putUndoInfo(Mode &mode)
+{
+ std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+
+ iterateElement(getRoot(), actionList);
+}
+
+void UndoInfoParser::iterateElement(xmlNodePtr node, const std::list<std::shared_ptr<Action>> &actionList)
+{
+ xmlNode *cur = NULL;
+ for (cur = node; cur; cur = cur->next) {
+ if (xmlIsBlankNode(cur))
+ continue;
+ else if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::INFO))
+ parseInfo(cur, actionList);
+ else
+ DBG("Unhandled node : %s", node->name);
+
+ iterateElement(cur->children, actionList);
+ }
+}
+
+void UndoInfoParser::parseInfo(xmlNodePtr node, const std::list<std::shared_ptr<Action>> &actionList)
+{
+ char *ruleName = (char*)xmlGetProp(node, ModesXMLTag::RULE);
+ if (ruleName == NULL) {
+ ERR("rule attribute is null! [%s]", ModesXMLTag::RULE);
+ throw ModesEx(ModesEx::PARSER_ERROR, "rule attribute is null!");
+ }
+
+ auto it = std::find_if_not(actionList.begin(), actionList.end(), [ruleName](std::shared_ptr<Action> a)->bool {return a->getRuleName().compare(ruleName);});
+ std::shared_ptr<Action> action = *it;
+ if (action == nullptr) {
+ ERR("Find Action(%s) Fail", ruleName);
+ xmlFree(ruleName);
+ throw ModesEx(ModesEx::PARSER_ERROR, "Action is null!");
+ }
+ xmlFree(ruleName);
+
+ char *nodeContent = (char*)xmlNodeGetContent(node);
+ if (nodeContent == NULL)
+ ERR("Node Content is null!");
+
+ int ret = action->restoreUndoInfo(nodeContent ? nodeContent : "");
+ xmlFree(nodeContent);
+
+ if (MODES_ERROR_NONE != ret) {
+ ERR("Action(%s) setValue() Fail(%d)", action->getRuleName().c_str(), ret);
+ throw ModesEx(ModesEx::PARSER_ERROR, "Invalid Action Value");
+ }
+
+ action->printInfo();
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <libxml/tree.h>
+#include "mdss.h"
+#include "Mode.h"
+#include "XMLParser.h"
+
+MODES_NAMESPACE_BEGIN
+
+class UndoInfoParser : public XMLParser {
+public:
+ UndoInfoParser(const std::string &file);
+ ~UndoInfoParser() = default;
+
+ std::string getModeName();
+ void putUndoInfo(Mode &mode);
+private:
+ void iterateElement(xmlNodePtr node, const std::list<std::shared_ptr<Action>>& actionList);
+ void parseInfo(xmlNodePtr node, const std::list<std::shared_ptr<Action>> &actionList);
+
+ std::string filePath;
+};
+
+MODES_NAMESPACE_END
#include <libxml/tree.h>
#include <libxml/xmlschemas.h>
#include "Action.h"
-#include "ModeTag.h"
+#include "ModesXMLTag.h"
#include "ModesEx.h"
#include "XMLGenerator.h"
MODES_NAMESPACE_USE;
XMLGenerator::XMLGenerator()
- : doc(NULL), rootNode(NULL), modeNode(NULL)
+ : doc(NULL), rootNode(NULL)
{
}
void XMLGenerator::createRootNode()
{
- doc = xmlNewDoc(ModeTag::XML_VERSION);
- doc->encoding = ModeTag::XML_ENCODING;
+ doc = xmlNewDoc(ModesXMLTag::XML_VERSION);
+ doc->encoding = ModesXMLTag::XML_ENCODING;
doc->charset = 1;
- rootNode = xmlNewNode(NULL, ModeTag::TIZENMODES);
- xmlSetProp(rootNode, ModeTag::XMLNS, ModeTag::XMLNS_STR);
- xmlSetProp(rootNode, ModeTag::VERSION, ModeTag::CUR_VERSION);
+ rootNode = xmlNewNode(NULL, ModesXMLTag::TIZENMODES);
+ xmlSetProp(rootNode, ModesXMLTag::XMLNS, ModesXMLTag::XMLNS_STR);
+ xmlSetProp(rootNode, ModesXMLTag::VERSION, ModesXMLTag::CUR_VERSION);
xmlDocSetRootElement(doc, rootNode);
return;
}
const std::string modeType = getModeTypeStr(mode.getModeType());
std::string modeName = mode.getName();
- modeNode = xmlNewNode(NULL, ModeTag::MODE);
+ xmlNodePtr modeNode = xmlNewNode(NULL, ModesXMLTag::MODE);
- xmlSetProp(modeNode, ModeTag::NAME, (xmlChar*)modeName.c_str());
- xmlSetProp(modeNode, ModeTag::TYPE, (xmlChar*)modeType.c_str());
- xmlSetProp(modeNode, ModeTag::CUSTOM, (xmlChar*)((mode.getCustomized())? "yes": "no"));
+ xmlSetProp(modeNode, ModesXMLTag::NAME, (xmlChar*)modeName.c_str());
+ xmlSetProp(modeNode, ModesXMLTag::TYPE, (xmlChar*)modeType.c_str());
+ xmlSetProp(modeNode, ModesXMLTag::CUSTOM, (xmlChar*)((mode.getCustomized())? "yes": "no"));
xmlAddChild(rootNode, modeNode);
std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
- std::list<std::shared_ptr<Action>>::iterator it;
- for (it = actionList.begin(); it != actionList.end(); it++) {
- xmlNodePtr reqNode;
+ for (auto it = actionList.begin(); it != actionList.end(); it++) {
+ xmlNodePtr actionNode;
Action::ActionRestrict restriction = (*it)->getRestrict();
- reqNode = xmlNewNode(NULL, ModeTag::ACTION);
+ actionNode = xmlNewNode(NULL, ModesXMLTag::ACTION);
if (!(*it)->getID().empty())
- xmlSetProp(reqNode, ModeTag::ID, (xmlChar*)(*it)->getID().c_str());
+ xmlSetProp(actionNode, ModesXMLTag::ID, (xmlChar*)(*it)->getID().c_str());
- xmlSetProp(reqNode, ModeTag::RULE, (xmlChar*)(*it)->getRuleName().c_str());
+ xmlSetProp(actionNode, ModesXMLTag::RULE, (xmlChar*)(*it)->getRuleName().c_str());
if (restriction == Action::ActionRestrict::REQ_LOCK)
- xmlSetProp(reqNode, ModeTag::RESTICT, (xmlChar*)ModeTag::RESTICT_LOCK);
+ xmlSetProp(actionNode, ModesXMLTag::RESTICT, (xmlChar*)ModesXMLTag::RESTICT_LOCK);
- xmlNodeSetContent(reqNode, (xmlChar*)(*it)->getStringOfValue().c_str());
+ xmlNodeSetContent(actionNode, (xmlChar*)(*it)->getStringOfValue().c_str());
- xmlAddChild(modeNode, reqNode);
+ xmlAddChild(modeNode, actionNode);
+ }
+
+ write(filename);
+
+ doc->encoding = NULL;
+ xmlFreeDoc(doc);
+ return;
+}
+
+void XMLGenerator::makeUndoInfoXML(const std::string &filename, const Mode &mode)
+{
+ if (filename.empty()) {
+ ERR("filename empty!!");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
+
+ createRootNode();
+
+ xmlNodePtr undoInfoNode = xmlNewNode(NULL, ModesXMLTag::UNDO_INFO);
+ xmlSetProp(undoInfoNode, ModesXMLTag::NAME, (xmlChar*)mode.getName().c_str());
+ xmlAddChild(rootNode, undoInfoNode);
+
+ std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+ for (auto it = actionList.begin(); it != actionList.end(); it++) {
+ if ((*it)->backupUndoInfo().empty())
+ continue;
+
+ xmlNodePtr infoNode = xmlNewNode(NULL, ModesXMLTag::INFO);
+ xmlSetProp(infoNode, ModesXMLTag::RULE, (xmlChar*)(*it)->getRuleName().c_str());
+ xmlNodeSetContent(infoNode, (xmlChar*)(*it)->backupUndoInfo().c_str());
+ xmlAddChild(undoInfoNode, infoNode);
}
write(filename);
~XMLGenerator();
void makeModeXML(const std::string &filename, const Mode &mode);
+ void makeUndoInfoXML(const std::string &filename, const Mode &mode);
private:
void createRootNode();
xmlDocPtr doc;
xmlNodePtr rootNode;
- xmlNodePtr modeNode;
};
MODES_NAMESPACE_END
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#include "ModesEx.h"
#include "XMLParser.h"
+
#include <libxml/tree.h>
#include <libxml/xmlschemas.h>
+#include "mdss.h"
+#include "ModesEx.h"
MODES_NAMESPACE_USE;
return;
}
+
+std::string XMLParser::extractValueOfTag(xmlNodePtr node, const xmlChar *tag)
+{
+ char *value;
+
+ value = (char*)xmlGetProp(node, tag);
+ if (value == NULL) {
+ ERR("attribute(%s) is NULL. ", tag);
+ return std::string();
+ }
+
+ std::string valueStr = value;
+ xmlFree(value);
+ return valueStr;
+}
#pragma once
#include <libxml/tree.h>
+#include <string>
#include "mdss.h"
MODES_NAMESPACE_BEGIN
~XMLParser();
void validate(const std::string &xsd);
+ std::string extractValueOfTag(xmlNodePtr node, const xmlChar * tag);
xmlNodePtr getRoot();
private:
#=======================================================================================#
SET(GTEST_MODEMGR "modes-gtest-modemgr")
FILE(GLOB GTEST_MODEMGR_SRCS
- ${SUPERVISOR_DIR}/ModeTag.cpp
+ ${SUPERVISOR_DIR}/ModesXMLTag.cpp
${SUPERVISOR_DIR}/XMLParser.cpp
${SUPERVISOR_DIR}/XMLGenerator.cpp
${SUPERVISOR_DIR}/ModeManager.cpp
${SUPERVISOR_DIR}/ConflictManager.cpp
${SUPERVISOR_DIR}/ModeCareTaker.cpp
${SUPERVISOR_DIR}/ModeXMLParser.cpp
+ ${SUPERVISOR_DIR}/UndoInfoParser.cpp
${SUPERVISOR_DIR}/Action.cpp
${SUPERVISOR_DIR}/ActionRule.cpp
${SUPERVISOR_DIR}/RuleManager.cpp
${SUPERVISOR_DIR}/ModeXMLParser.cpp
${SUPERVISOR_DIR}/ModesEx.cpp
${SUPERVISOR_DIR}/Mode.cpp
- ${SUPERVISOR_DIR}/ModeTag.cpp
+ ${SUPERVISOR_DIR}/ModesXMLTag.cpp
${SUPERVISOR_DIR}/ValueChecker.cpp
modes_test_parser.cpp
)
SET(GTEST_GENERATOR "modes-gtest-generator")
FILE(GLOB GTEST_GENERATOR_SRCS
${SUPERVISOR_DIR}/XMLGenerator.cpp
- ${SUPERVISOR_DIR}/ModeTag.cpp
+ ${SUPERVISOR_DIR}/ModesXMLTag.cpp
${SUPERVISOR_DIR}/ModeXMLParser.cpp
${SUPERVISOR_DIR}/XMLParser.cpp
${SUPERVISOR_DIR}/Mode.cpp
${SUPERVISOR_DIR}/ConflictManager.cpp
${SUPERVISOR_DIR}/Mode.cpp
${SUPERVISOR_DIR}/ModeCareTaker.cpp
+ ${SUPERVISOR_DIR}/XMLGenerator.cpp
${SUPERVISOR_DIR}/Action.cpp
${SUPERVISOR_DIR}/ModeXMLParser.cpp
${SUPERVISOR_DIR}/XMLParser.cpp
${SUPERVISOR_DIR}/ModesEx.cpp
- ${SUPERVISOR_DIR}/ModeTag.cpp
+ ${SUPERVISOR_DIR}/ModesXMLTag.cpp
${SUPERVISOR_DIR}/PluginManager.cpp
${SUPERVISOR_DIR}/RuleManager.cpp
${SUPERVISOR_DIR}/ActionRule.cpp
void SetUp() override
{
ModeXMLParser modeparser("tizen_conflict1_mode.xml", ruleMgr, piMgr);
- careTaker.saveMode(modeparser.getMode());
+ careTaker.pushMode(modeparser.getMode());
}
void TearDown() override
{
- careTaker.undoMode("conflict1");
+ Mode mode;
+ careTaker.popMode("conflict1", mode);
}
PluginManager piMgr;
ModesConfig config;
config.actionRuleDir = ".";
config.actionRuleXsdFile = "./" MODES_ACTIONRULE_DEFAULT_XSD_FILE;
+ config.undoInfoDir = ".";
ruleMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile);
ruleMgr.makeRuleMap();
+ careTaker.setOptions(config.undoInfoDir);
}
TEST_F(ConflictTest, isSavedMode)
{
- ModeXMLParser modeparser("tizen_conflict2_mode.xml", ruleMgr, piMgr);
+ ModeXMLParser modeparser("tizen_conflict1_mode.xml", ruleMgr, piMgr);
EXPECT_TRUE(careTaker.isSavedMode(modeparser.getModeName()));
}
{
ModeXMLParser modeparser("tizen_conflict3_mode.xml", ruleMgr, piMgr);
- careTaker.saveMode(modeparser.getMode());
+ careTaker.pushMode(modeparser.getMode());
EXPECT_TRUE(careTaker.isExclusive());
- careTaker.undoMode(modeparser.getModeName());
+ Mode mode;
+ careTaker.popMode(modeparser.getModeName(), mode);
EXPECT_FALSE(careTaker.isExclusive());
}
ModesConfig config;
config.modeXMLDirs.insert(".");
config.modeXsdFile = "./" MODES_MODE_DEFAULT_XSD_FILE;
+ config.undoInfoDir = "./";
- mdMgr.setOptions(config.modeXMLDirs, config.modeXsdFile);
+ mdMgr.setOptions(config.modeXMLDirs, config.modeXsdFile, config.undoInfoDir);
mdMgr.init();
}