<?xml version="1.0" encoding="utf-8"?>
<tizenModes xmlns="http://www.tizen.org" version="5.5">
<mode name="ex1" type="normal">
- <action ID="wifiOn" rule="wifi.power" type="sync" priority="-100">on</action>
+ <action ID="wifiOn" rule="wifi.power" priority="-100">on</action>
<action rule="notification.donotdisturb">on</action>
<action rule="application.launch" before="GoPbsKids">com.vpn.usa123</action>
<action ID="GoPbsKids" rule="browser.url" after="wifiOn">https://pbskids.org/</action>
- <action ID="BMJ" rule="bluetooth.connet" type="sync">Modes-JBL</action>
- <action rule="media.music.player" type="async" after="BMJ">beatles-yesterday.mp3</action>
- <action ID="1" rule="vconf.db.setting.psmode" type="async" priority="-100"
+ <action ID="BMJ" rule="bluetooth.connet">Modes-JBL</action>
+ <action rule="media.music.player" after="BMJ">beatles-yesterday.mp3</action>
+ <action ID="1" rule="vconf.db.setting.psmode" priority="-100"
>SETTING_PSMODE_NORMAL</action>
</mode>
</tizenModes>
<?xml version="1.0" encoding="utf-8"?>
<tizenModes xmlns="http://www.tizen.org" version="5.5">
<mode name="ex2" type="exclusive">
- <action ID="1" rule="vconf.db.setting.psmode" type="async" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE</action>
- <action ID="wifiOff" rule="wifi.power" restrict="lock" type="sync" priority="-100">off</action>
+ <action ID="1" rule="vconf.db.setting.psmode" stopOnErr="true" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE</action>
+ <action ID="wifiOff" rule="wifi.power" restrict="lock" priority="-100">off</action>
</mode>
</tizenModes>
<xs:extension base="o:valueT">
<xs:attribute name="ID" type="xs:string" use="optional" />
<xs:attribute name="rule" type="xs:string" use="required" />
- <xs:attribute name="type" use="optional">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="sync"/>
- <xs:enumeration value="async"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
+ <xs:attribute name="stopOnErr" type="xs:boolean" use="optional" />
<xs:attribute name="restrict" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
DBG("Action(%s) Changed", key.c_str());
}
}
+
Action::Action()
- :plugin(nullptr), piAction(nullptr), isChanged(false), restriction(REQ_NONE)
+ :plugin(nullptr), piAction(nullptr), stopOnErr(false), isChanged(false), restriction(REQ_NONE)
{
}
Action::Action(const std::string &name)
- :ruleName(name), plugin(nullptr), piAction(nullptr), isChanged(false), restriction(REQ_NONE)
+ :ruleName(name), plugin(nullptr), piAction(nullptr), stopOnErr(false), isChanged(false), restriction(REQ_NONE)
{
}
+Action::~Action()
+{
+ if (plugin)
+ plugin->freeAction(piAction);
+}
+
void Action::printInfo()
{
DBG("Action(%s):ID(%s), Restrict(%d)", getRuleName().c_str(), getID().c_str(), getRestrict());
restriction = data;
}
+void Action::setStopOnErr(bool val)
+{
+ stopOnErr = val;
+}
+
+bool Action::getStopOnErr()
+{
+ return stopOnErr;
+}
+
Action::ActionRestrict Action::getRestrict()
{
return restriction;
REQ_LOCK
}ActionRestrict;
- virtual ~Action() = default;
Action();
Action(const std::string &ruleName);
+ virtual ~Action();
void printInfo();
void setRuleName(const std::string &data);
std::string getID();
void setRestrict(const ActionRestrict &data);
ActionRestrict getRestrict();
- void setPlugin(Plugin *pi);
+ void setStopOnErr(bool val);
+ bool getStopOnErr();
void setIsChanged();
bool getIsChanged();
+ void setPlugin(Plugin *pi);
virtual void setValue(const std::string &val) = 0;
virtual std::string getStringOfValue() = 0;
- virtual void apply() = 0;
- virtual void applyOneShot() = 0;
+ virtual int apply() = 0;
+ virtual int applyOneShot() = 0;
virtual void undo() = 0;
protected:
static void valueChangedCallback(const std::string &key, void *userData);
private:
- bool isChanged;
std::string id;
+ bool stopOnErr;
+ bool isChanged;
ActionRestrict restriction;
};
return customized;
}
-void Mode::apply()
+int Mode::apply()
{
std::list<std::shared_ptr<Action>>::iterator it;
- for (it = actionList.begin(); it != actionList.end(); it++)
- (*it)->apply();
+ for (it = actionList.begin(); it != actionList.end(); it++) {
+ int ret = (*it)->apply();
+ if (MODES_ERROR_NONE != ret && (*it)->getStopOnErr()) {
+ ERR("Action(%s) apply Fail(%d)", (*it)->getRuleName().c_str(), ret);
+ return ret;
+ }
+ }
+ return MODES_ERROR_NONE;
}
-void Mode::applyOneShot()
+int Mode::applyOneShot()
{
std::list<std::shared_ptr<Action>>::iterator it;
- for (it = actionList.begin(); it != actionList.end(); it++)
- (*it)->applyOneShot();
+ for (it = actionList.begin(); it != actionList.end(); it++) {
+ int ret = (*it)->applyOneShot();
+ if (MODES_ERROR_NONE != ret && (*it)->getStopOnErr()) {
+ ERR("Action(%s) applyOneShot Fail(%d)", (*it)->getRuleName().c_str(), ret);
+ return ret;
+ }
+ }
+ return MODES_ERROR_NONE;
}
void Mode::undo()
void addAction(Action *action);
std::list<std::shared_ptr<Action>> getActionList() const;
- void apply();
- void applyOneShot();
+ int apply();
+ int applyOneShot();
void undo();
private:
bool customized;
DBG("applyMode(%s)", path.c_str());
try {
- ModeParser *parser = getModeParser(path);
+ std::unique_ptr<ModeParser> parser(getModeParser(path));
Mode mode = parser->getMode();
DBG("applyMode(%s) Run", mode.getName().c_str());
return MODES_ERROR_CONFLICT;
}
- if (Mode::MODE_ONESHOT != mode.getModeType()) {
- mode.apply();
- careTaker.saveMode(mode);
+ if (Mode::MODE_ONESHOT == mode.getModeType()) {
+ int ret = mode.applyOneShot();
+ if (MODES_ERROR_NONE != ret) {
+ mode.undo();
+ return ret;
+ }
} else {
- mode.applyOneShot();
+ int ret = mode.apply();
+ if (MODES_ERROR_NONE != ret) {
+ mode.undo();
+ return ret;
+ }
+ careTaker.saveMode(mode);
}
-
- delete parser;
} catch (ModesEx &e) {
- ERR("parser Fail(%s)", e.what());
+ ERR("apply Fail(%s)", e.what());
}
return MODES_ERROR_NONE;
}
const xmlChar* const ModeTag::CUSTOM = (xmlChar*)"custom";
const xmlChar* const ModeTag::ACTION = (xmlChar*)"action";
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";
static const xmlChar* const CUSTOM;
static const xmlChar* const ACTION;
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;
return xmlTagString;
}
+void ModeXMLParser::parseActionAttr(xmlNodePtr node, Action *action)
+{
+ char *restictProp = (char*)xmlGetProp(node, ModeTag::RESTICT);
+ if (restictProp && MDS_EQUAL == strcmp(restictProp, ModeTag::RESTICT_LOCK))
+ action->setRestrict(Action::REQ_LOCK);
+ else
+ action->setRestrict(Action::REQ_NONE);
+ xmlFree(restictProp);
+
+ char *stopOnErrProp = (char*)xmlGetProp(node, ModeTag::STOP_ON_ERR);
+ if (stopOnErrProp && MDS_EQUAL == strcmp(stopOnErrProp, "true"))
+ action->setStopOnErr(true);
+ else
+ action->setStopOnErr(false);
+ xmlFree(stopOnErrProp);
+}
+
void ModeXMLParser::parseAction(xmlNodePtr node)
{
char *ruleProp = (char*)xmlGetProp(node, ModeTag::RULE);
bindPlugin(ruleProp, action);
xmlFree(ruleProp);
- char *restictProp = (char*)xmlGetProp(node, ModeTag::RESTICT);
- if (restictProp && MDS_EQUAL == strcmp(restictProp, ModeTag::RESTICT_LOCK)) {
- action->setRestrict(Action::REQ_LOCK);
- } else {
- action->setRestrict(Action::REQ_NONE);
- }
- xmlFree(restictProp);
+ parseActionAttr(node, action);
char *nodeContent = (char*)xmlNodeGetContent(node);
if (nodeContent == NULL) {
std::string getModeType(xmlNodePtr node);
bool getModeCustom(xmlNodePtr node);
std::string getXmlTagStringValue(xmlNodePtr node, const xmlChar *tag);
+ void parseActionAttr(xmlNodePtr node, Action *action);
void parseAction(xmlNodePtr node);
void bindPlugin(const std::string &name, Action *action);
}
}
- void apply() override
+ int apply() override
{
- RETM_IF(NULL == plugin, "Action(%s) : No plugin", ruleName.c_str());
+ RETVM_IF(NULL == plugin, MODES_ERROR_NO_DATA, "Action(%s) : No plugin", ruleName.c_str());
int pos = ruleName.find_first_of(".");
- plugin->set(ruleName.substr(pos + 1), value, &piAction);
+ 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);
+ return ret;
+ }
plugin->setChangedCallback(valueChangedCallback, ruleName.substr(pos + 1), this);
+
+ piAction = tmpAction;
+ return MODES_ERROR_NONE;
}
- void applyOneShot() override
+ int applyOneShot() override
{
- RETM_IF(NULL == plugin, "Action(%s) : No plugin", ruleName.c_str());
+ RETVM_IF(NULL == plugin, MODES_ERROR_NO_DATA, "Action(%s) : No plugin", ruleName.c_str());
int pos = ruleName.find_first_of(".");
- plugin->set(ruleName.substr(pos + 1), value, nullptr);
+ 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);
+ return ret;
+ }
+
+ piAction = tmpAction;
+ return MODES_ERROR_NONE;
}
void undo() override
EXPECT_EQ("ex1", modeparser.getModeName());
}
-TEST(XMLParser, getMode)
-{
- PluginManager pluginManager;
- RuleManager ruleMgr;
- ModeXMLParser modeparser("tizen_ex2_mode.xml", ruleMgr, pluginManager);
- Mode mode = modeparser.getMode();
-
- //EXPECT_TRUE(mode.empty());
-}
-
-TEST(Mode, getModeName)
+TEST(Mode, modeGetName)
{
PluginManager pluginManager;
RuleManager ruleMgr;