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)
{
}
return ruleName;
}
+void Action::setIgnoreUndo(bool ignore)
+{
+ ignoreUndo = ignore;
+}
+
+bool Action::isIgnored()
+{
+ return ignoreUndo;
+}
+
void Action::setID(const std::string &actionId)
{
id = actionId;
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;
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);
}
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);
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;
#include "mdss.h"
#include "XMLGenerator.h"
+#include "UndoInfoParser.h"
#include "EssentialHandler.h"
MODES_NAMESPACE_USE;
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)
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;
}
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;
~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);
#include "ModeObserver.h"
#include "XMLGenerator.h"
#include "ModeXMLParser.h"
-#include "UndoInfoParser.h"
using std::string;
MODES_NAMESPACE_USE;
makeModeMap(*it);
DBG("Mode Directory(%s) added", it->c_str());
}
- restoreUndoInfo(careTaker.getUndoInfoDir());
}
// TODO: apply better polymorphism
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");
}
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);
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);
{
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");
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);
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";
//UndoInfo
const xmlChar* const ModesXMLTag::UNDO_INFO = (xmlChar*)"UndoInfo";
const xmlChar* const ModesXMLTag::INFO = (xmlChar*)"info";
+const xmlChar* const ModesXMLTag::IGNORE = (xmlChar*)"ignore";
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;
//UndoInfo
static const xmlChar* const UNDO_INFO;
static const xmlChar* const INFO;
+ static const xmlChar* const IGNORE;
};
MODES_NAMESPACE_END
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);
std::map<std::string, T, CaseIndependentLess> valueAliases;
std::mutex actionMutex;
- bool undoing;
T value{};
};
MODES_NAMESPACE_END
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);
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();
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);
}
bool isSubscribed(Action *action)
{
- return action->subscribed;
+ return !(action->isIgnored());
}
Plugin *plugin;