careTaker.pushMode(mode);
}
} catch (ModesEx &e) {
- //Ususally, it is reached by Invalid Mode File
ERR("apply Fail(%s)", e.what());
- return MODES_ERROR_NO_DATA;
+
+ switch (e.getErrCode()) {
+ case ModesEx::INVALID_ARG:
+ //Ususally, it is reached by Invalid Mode File
+ return MODES_ERROR_NO_DATA;
+ case ModesEx::SYSTEM_ERROR:
+ default:
+ return MODES_ERROR_SYSTEM;
+ }
}
notifyObservers(modeName, ModeObserver::ON);
return MODES_ERROR_NONE;
} catch (ModesEx &e) {
ERR("XML generator Fail(%s)", e.what());
modeMap.erase(result.first);
- return MODES_ERROR_INVALID_PARAMETER;
+
+ switch (e.getErrCode()) {
+ case ModesEx::INVALID_ARG:
+ return MODES_ERROR_INVALID_PARAMETER;
+ case ModesEx::SYSTEM_ERROR:
+ default:
+ return MODES_ERROR_SYSTEM;
+ }
}
DBG("[%zu]addMode : Name(%s), Path(%s), Type(%d)", modeMap.size(), mode.getName().c_str(),
{
}
+ModesEx::ErrCode ModesEx::getErrCode()
+{
+ return err;
+}
+
std::string ModesEx::getExtraMsg()
{
return extraMsg;
ModesEx(ErrCode code);
ModesEx(ErrCode code, const std::string &msg);
+ ErrCode getErrCode();
std::string getExtraMsg();
virtual const char* what() const throw() override;
private:
}
}
-void XMLGenerator::makeModeXML(const std::string &filename, const Mode &mode)
+void XMLGenerator::makeModeXML(const std::string &path, const Mode &mode)
{
- if (filename.empty()) {
- ERR("filename empty!!");
+ if (path.empty()) {
+ ERR("NULL path");
throw ModesEx(ModesEx::INVALID_ARG);
}
+ if (0 != remove(path.c_str()) && ENOENT != errno) {
+ ERR("remove(%s) Fail(%d)", path.c_str(), errno);
+ throw ModesEx(ModesEx::SYSTEM_ERROR);
+ }
+
createRootNode();
const std::string modeType = getModeTypeStr(mode.getModeType());
xmlAddChild(modeNode, actionNode);
}
- saveToFile(filename);
+ saveToFile(path);
doc->encoding = NULL;
xmlFreeDoc(doc);
return;
}
-void XMLGenerator::makeUndoInfoXML(const std::string &filename, const Mode &mode)
+void XMLGenerator::makeUndoInfoXML(const std::string &path, const Mode &mode)
{
- if (filename.empty()) {
- ERR("filename empty!!");
+ if (path.empty()) {
+ ERR("NULL path");
throw ModesEx(ModesEx::INVALID_ARG);
}
+ if (0 != remove(path.c_str()) && ENOENT != errno) {
+ ERR("remove(%s) Fail(%d)", path.c_str(), errno);
+ throw ModesEx(ModesEx::SYSTEM_ERROR);
+ }
+
createRootNode();
xmlNodePtr undoInfoNode = xmlNewNode(NULL, ModesXMLTag::UNDO_INFO);
xmlAddChild(undoInfoNode, infoNode);
}
- saveToFile(filename);
+ saveToFile(path);
doc->encoding = NULL;
xmlFreeDoc(doc);