From: Youngjae Shin Date: Tue, 12 May 2020 06:35:59 +0000 (+0900) Subject: remove ModeParser X-Git-Tag: submit/tizen/20200513.090930~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b4be3b2f715659fea6cc55cde1a24012b1db981;p=platform%2Fcore%2Fsystem%2Fmodes.git remove ModeParser The ModeParser is not useful because the mode description is fixed on XML. --- diff --git a/supervisor/ModeManager.cpp b/supervisor/ModeManager.cpp index 48b91f1..3a1d6d6 100644 --- a/supervisor/ModeManager.cpp +++ b/supervisor/ModeManager.cpp @@ -46,28 +46,17 @@ void ModeManager::init() } } -// TODO: apply better polymorphism -ModeParser* ModeManager::getModeParser(const string &path) +void ModeManager::addModeAttributes(ModeXMLParser &parser, const string &path) { - const size_t suffixLen = sizeof("xml") - 1; - if (suffixLen < path.length() - || path.compare(path.length() - suffixLen, suffixLen, "xml")) { - return new ModeXMLParser(path, ruleMgr); - } else { - ERR("Wrong path(%s)", path.c_str()); - throw std::invalid_argument("Wrong path"); - } -} - -void ModeManager::addModeAttributes(ModeParser *parser, const string &path) -{ - Mode mode = parser->getMode(); - modeMap.insert(std::make_pair(mode.getName(), std::make_tuple(path, mode.getModeType(), mode.isHidden()))); + Mode mode = parser.getMode(); + auto infos = std::make_tuple(path, mode.getModeType(), mode.isHidden()); + modeMap.insert(std::make_pair(mode.getName(), infos)); if (careTaker.hasUndoInfo(mode.getName())) careTaker.restoreMode(mode); - DBG("[%zu] modeName : %s, modePath : %s, type : %d, hidden : %s", modeMap.size(), mode.getName().c_str(), path.c_str(), mode.getModeType(), mode.isHidden()? "true": "false"); + DBG("[%zu]Name(%s), Path(%s), Type(%d), hidden(%s)", modeMap.size(), mode.getName().c_str(), + path.c_str(), mode.getModeType(), mode.isHidden() ? "true": "false"); } int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool isTest) @@ -82,8 +71,8 @@ int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool i DBG("applyMode(%s)", path.c_str()); try { - std::unique_ptr parser(getModeParser(path)); - Mode mode = parser->getMode(); + ModeXMLParser parser(path, ruleMgr); + Mode mode = parser.getMode(); DBG("applyMode(%s) Run", mode.getName().c_str()); @@ -128,10 +117,10 @@ int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool i int ModeManager::addMode(const Mode &mode) { - string filename = MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" + mode.getName() + "_mode.xml"; + string path = MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" + mode.getName() + "_mode.xml"; XMLGenerator xmlWriter; - auto element = std::make_pair(mode.getName(), std::make_tuple(filename, mode.getModeType(), false)); + auto element = std::make_pair(mode.getName(), std::make_tuple(path, mode.getModeType(), false)); auto result = modeMap.insert(element); if (false == result.second) { ERR("Invalid mode(%s), already exists", mode.getName().c_str()); @@ -139,14 +128,15 @@ int ModeManager::addMode(const Mode &mode) } try { - xmlWriter.makeModeXML(filename, mode); + xmlWriter.makeModeXML(path, mode); } catch (ModesEx &e) { ERR("XML generator Fail(%s)", e.what()); modeMap.erase(result.first); return MODES_ERROR_INVALID_PARAMETER; } - DBG("[%zu] addMode modeName : %s, modePath : %s, type : %d, hidden : false", modeMap.size(), mode.getName().c_str(), filename.c_str(), mode.getModeType()); + DBG("[%zu]addMode : Name(%s), Path(%s), Type(%d)", modeMap.size(), mode.getName().c_str(), + path.c_str(), mode.getModeType()); return MODES_ERROR_NONE; } @@ -164,19 +154,18 @@ int ModeManager::removeMode(const string &modeName) return MODES_ERROR_INVALID_PARAMETER; } - string filename = std::get<0>(result->second); - if (string::npos == filename.find(MODES_CUSTOM_MODE_DEFAULT_DIR)) - { + string path = std::get<0>(result->second); + if (string::npos == path.find(MODES_CUSTOM_MODE_DEFAULT_DIR)) { ERR("Invalid mode(%s), custom mode only can be removed.", modeName.c_str()); return MODES_ERROR_INVALID_PARAMETER; } modeMap.erase(result); - if (0 != remove(filename.c_str())) - ERR("remove(%s) Fail(%d)", filename.c_str(), errno); + if (0 != remove(path.c_str())) + ERR("remove(%s) Fail(%d)", path.c_str(), errno); - DBG("[%zu] Remove modeName : %s, modePath : %s", modeMap.size(), modeName.c_str(), filename.c_str()); + DBG("[%zu]removeMode : Name(%s), Path(%s)", modeMap.size(), modeName.c_str(), path.c_str()); return MODES_ERROR_NONE; } @@ -270,10 +259,9 @@ bool ModeManager::makeModeMap(const string &dirPath) string fileFullPath = dirPath + "/" + string(entry->d_name); try { - ModeParser *modeParser = getModeParser(fileFullPath); - modeParser->validateMode(modeSyntaxFile); + ModeXMLParser modeParser(fileFullPath, ruleMgr); + modeParser.validateMode(modeSyntaxFile); addModeAttributes(modeParser, fileFullPath); - delete modeParser; } catch (ModesEx &e) { ERR("parser(%s) Fail(%s)", fileFullPath.c_str(), e.what()); } catch (std::invalid_argument &e) { diff --git a/supervisor/ModeManager.h b/supervisor/ModeManager.h index 7953d63..36f7a8f 100644 --- a/supervisor/ModeManager.h +++ b/supervisor/ModeManager.h @@ -19,10 +19,10 @@ #include #include #include "mdss.h" -#include "ModeParser.h" #include "RuleManager.h" -#include "ModeCareTaker.h" #include "ModeObserver.h" +#include "ModeCareTaker.h" +#include "ModeXMLParser.h" #include "ClientPrivilege.h" MODES_NAMESPACE_BEGIN @@ -44,8 +44,7 @@ public: private: void notifyObservers(const std::string &modeName, ModeObserver::ModeState state); bool makeModeMap(const std::string &dirPath); - void addModeAttributes(ModeParser *parser, const std::string &path); - ModeParser* getModeParser(const std::string &path); + void addModeAttributes(ModeXMLParser &parser, const std::string &path); std::map> modeMap; std::set modeDirList; diff --git a/supervisor/ModeParser.h b/supervisor/ModeParser.h deleted file mode 100644 index d32e19e..0000000 --- a/supervisor/ModeParser.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2019-2020 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 -#include "mdss.h" -#include "Mode.h" -#include "RuleManager.h" - -MODES_NAMESPACE_BEGIN - -class ModeParser { -public: - virtual ~ModeParser() = default; - - virtual Mode getMode() = 0; - virtual void validateMode(const std::string &syntaxFile) = 0; -protected: - ModeParser(RuleManager &rMgr) :ruleMgr(rMgr) - { - } - RuleManager &ruleMgr; -}; - -MODES_NAMESPACE_END diff --git a/supervisor/ModeXMLParser.cpp b/supervisor/ModeXMLParser.cpp index cdd8f12..ebe8a38 100644 --- a/supervisor/ModeXMLParser.cpp +++ b/supervisor/ModeXMLParser.cpp @@ -29,7 +29,7 @@ MODES_NAMESPACE_USE; ModeXMLParser::ModeXMLParser(const std::string &modeFile, RuleManager &rMgr) - : ModeParser(rMgr), XMLParser(modeFile), isParsedModeAttr(false) + : XMLParser(modeFile), ruleMgr(rMgr) { } diff --git a/supervisor/ModeXMLParser.h b/supervisor/ModeXMLParser.h index 1edb043..f7bbd5f 100644 --- a/supervisor/ModeXMLParser.h +++ b/supervisor/ModeXMLParser.h @@ -17,18 +17,19 @@ #include #include "mdss.h" -#include "ModeParser.h" +#include "Mode.h" #include "XMLParser.h" +#include "RuleManager.h" MODES_NAMESPACE_BEGIN -class ModeXMLParser : public ModeParser, public XMLParser { +class ModeXMLParser : public XMLParser { public: ModeXMLParser(const std::string &modeFile, RuleManager &mgr); ~ModeXMLParser() = default; - Mode getMode() override; - void validateMode(const std::string &xsd) override; + Mode getMode(); + void validateMode(const std::string &xsd); private: void parseModeAttr(xmlNodePtr node); @@ -39,12 +40,11 @@ private: void parseAction(xmlNodePtr node); void parseUndo(xmlNodePtr node); Action* parseActionInfo(xmlNodePtr node); - void parseModeAttrOnly(); void iterateElement(xmlNodePtr node); Mode mode; std::string filePath; - bool isParsedModeAttr; + RuleManager &ruleMgr; }; MODES_NAMESPACE_END