From: Youngjae Shin Date: Tue, 4 Feb 2020 05:02:46 +0000 (+0900) Subject: apply essential handler X-Git-Tag: submit/tizen/20200319.043412~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=beef946cd119ce14b928cdd26a95eed2e96a8e9a;p=platform%2Fcore%2Fsystem%2Fmodes.git apply essential handler --- diff --git a/common/log.h b/common/log.h index b563986..e6b1746 100644 --- a/common/log.h +++ b/common/log.h @@ -92,10 +92,6 @@ #define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg) #else /* MDS_DEBUGGING */ -#define API_CALL -#define API_END -#define FN_CALL -#define FN_END #define DBG(fmt, arg...) #define WARN(fmt, arg...) #define ERR(fmt, arg...) diff --git a/supervisor/Action.h b/supervisor/Action.h index e39bfe1..480d9b0 100644 --- a/supervisor/Action.h +++ b/supervisor/Action.h @@ -79,7 +79,7 @@ private: std::string privilege; bool stopOnErr; ActionRestrict restriction; - bool locked; + bool locked; //Another action(same rule) is restricted(LOCK), It is assigned by ConflictManager std::list observers; }; diff --git a/supervisor/EssentialHandler.cpp b/supervisor/EssentialHandler.cpp new file mode 100644 index 0000000..5170df5 --- /dev/null +++ b/supervisor/EssentialHandler.cpp @@ -0,0 +1,51 @@ +/* + * 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. + */ +#include "EssentialHandler.h" + +#include +#include "mdss.h" +#include "ModesEx.h" + +MODES_NAMESPACE_USE; + +ModeManager *EssentialHandler::modeMgr = nullptr; + +void EssentialHandler::setModeManager(ModeManager *mgr) +{ + modeMgr = mgr; +} + +void EssentialHandler::undoHandler(const std::string &modeName) +{ + DBG("undo idler(%s) is added", modeName.c_str()); + + g_idle_add(undoIdler, new std::string(modeName)); +} + +gboolean EssentialHandler::undoIdler(gpointer data) +{ + RETV_IF(NULL == data, G_SOURCE_REMOVE); + RETV_IF(nullptr == modeMgr, G_SOURCE_REMOVE); + + std::string &modeName = *(std::string*)data; + + int ret = modeMgr->undoMode(modeName); + if (MODES_ERROR_NONE != ret) + ERR("undoMode(%s) Fail(%d)", modeName.c_str(), ret); + + delete &modeName; + return G_SOURCE_REMOVE; +} diff --git a/supervisor/EssentialHandler.h b/supervisor/EssentialHandler.h new file mode 100644 index 0000000..ba4a57a --- /dev/null +++ b/supervisor/EssentialHandler.h @@ -0,0 +1,34 @@ +/* + * 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 +#include "mdss.h" +#include "ModeManager.h" + +MODES_NAMESPACE_BEGIN + +class EssentialHandler { +public: + static void setModeManager(ModeManager *mgr); + static void undoHandler(const std::string &modeName); +private: + static gboolean undoIdler(gpointer data); + static ModeManager *modeMgr; +}; + +MODES_NAMESPACE_END diff --git a/supervisor/ModeCareTaker.cpp b/supervisor/ModeCareTaker.cpp index 01ceee5..76c0675 100644 --- a/supervisor/ModeCareTaker.cpp +++ b/supervisor/ModeCareTaker.cpp @@ -17,6 +17,7 @@ #include "mdss.h" #include "XMLGenerator.h" +#include "EssentialHandler.h" MODES_NAMESPACE_USE; @@ -41,6 +42,9 @@ void ModeCareTaker::pushMode(const Mode &mode) savedModes.insert(std::pair(mode.getName(), mode)); exclusive = (Mode::MODE_EXCLUSIVE == mode.getModeType()); + if (mode.hasEssential()) + handleEssentialAction(mode); + XMLGenerator gen; gen.makeUndoInfoXML(undoDir + "/tizen_" + mode.getName() + MODES_UNDO_FILE_SUFFIX, mode); } @@ -57,6 +61,13 @@ int ModeCareTaker::popMode(const std::string &name, Mode &mode) if (0 != remove(filePath.c_str())) ERR("remove(%s) Fail(%s)", filePath.c_str(), strerror(errno)); + for (auto it = essentialMap.begin(); it != essentialMap.end(); ) { + if (it->second == name) + it = essentialMap.erase(it); + else + ++it; + } + mode = found->second; if (Mode::MODE_EXCLUSIVE == mode.getModeType()) exclusive = false; @@ -92,7 +103,7 @@ bool ModeCareTaker::findLockedAction(const std::string &ruleName) for (auto actionIt = actionList.begin(); actionIt != actionList.end(); actionIt++) if ((*actionIt)->getRuleName() == ruleName && (*actionIt)->getRestrict() == Action::LOCK) { - ERR("%s is restricted", ruleName.c_str()); + ERR("%s is Locked", ruleName.c_str()); return true; } } @@ -113,3 +124,28 @@ bool ModeCareTaker::checkConflictAction(const Mode &mode) } return stopOnErr; } + +void ModeCareTaker::handleEssentialAction(const Mode &mode) +{ + DBG("Mode has Essential Action(%s)", mode.getName().c_str()); + + std::list> actionList = mode.getActionList(); + for (auto it = actionList.begin(); it != actionList.end(); it++) { + if ((*it)->getRestrict() == Action::ESSENTIAL) { + DBG("Essential Action(%s)", (*it)->getRuleName().c_str()); + essentialMap.insert(std::make_pair((*it)->getRuleName(), mode.getName())); + (*it)->attachObserver(this); + } + } +} + +void ModeCareTaker::update(const std::string &rule) +{ + auto found = essentialMap.find(rule); + if (essentialMap.end() == found) { + ERR("No Mode related with essential rule(%s)", rule.c_str()); + return; + } + + EssentialHandler::undoHandler(found->second); +} diff --git a/supervisor/ModeCareTaker.h b/supervisor/ModeCareTaker.h index 1510152..c5ed7fe 100644 --- a/supervisor/ModeCareTaker.h +++ b/supervisor/ModeCareTaker.h @@ -19,10 +19,11 @@ #include #include "mdss.h" #include "Mode.h" +#include "ActionObserver.h" MODES_NAMESPACE_BEGIN -class ModeCareTaker { +class ModeCareTaker : public ActionObserver { public: ModeCareTaker(); ~ModeCareTaker() = default; @@ -34,10 +35,12 @@ public: bool isSavedMode(const std::string &name); bool isExclusive(); bool checkConflictAction(const Mode &mode); + void update(const std::string &rule); private: - void handleEssentialAction(); + void handleEssentialAction(const Mode &mode); bool findLockedAction(const std::string &ruleName); std::map savedModes; + std::multimap essentialMap; std::string undoDir; bool exclusive; }; diff --git a/supervisor/ModeManager.cpp b/supervisor/ModeManager.cpp index d2c185e..359fb74 100644 --- a/supervisor/ModeManager.cpp +++ b/supervisor/ModeManager.cpp @@ -49,7 +49,6 @@ void ModeManager::setOptions(const std::set &modeDirs, const string &xsd void ModeManager::init() { modeMap.clear(); - essentialMap.clear(); for (auto it = modeDirList.begin(); it != modeDirList.end(); ++it) { makeModeMap(*it); @@ -80,19 +79,6 @@ void ModeManager::addModeAttributes(ModeParser *parser, const string &path) DBG("[%d] modeName : %s, modePath : %s, hidden : %s", modeMap.size(), modeName.c_str(), path.c_str(), hidden? "true": "false"); } -bool ModeManager::handleEssentialAction(const Mode &mode) -{ - bool stopOnErr = false; - std::list> actionList = mode.getActionList(); - for (auto it = actionList.begin(); it != actionList.end(); it++) { - if ((*it)->getRestrict() == Action::ESSENTIAL) { - essentialMap.insert(std::make_pair(mode.getName(), (*it)->getRuleName())); - (*it)->attachObserver(this); - } - } - return stopOnErr; -} - int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool isTest) { auto found = modeMap.find(modeName); @@ -140,8 +126,6 @@ int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool i return ret; } careTaker.pushMode(mode); - if (mode.hasEssential()) - handleEssentialAction(mode); } } catch (ModesEx &e) { //Ususally, it is reached by Invalid Mode File @@ -180,12 +164,6 @@ int ModeManager::undoMode(const string &modeName) return ret; } mode.undo(); - for (auto it = essentialMap.begin(); it != essentialMap.end(); ) { - if (it->second == modeName) - it = essentialMap.erase(it); - else - ++it; - } notifyObservers(modeName, ModeObserver::OFF); return MODES_ERROR_NONE; @@ -222,17 +200,6 @@ void ModeManager::notifyObservers(const string &modeName, ModeObserver::ModeStat (*it)->update(modeName, state); } -void ModeManager::update(const std::string &rule) -{ - auto found = essentialMap.find(rule); - if (essentialMap.end() == found) { - ERR("No Mode related with essential rule(%s)", rule.c_str()); - throw ModesEx(ModesEx::NO_DATA); - } - - undoMode(found->second); -} - bool ModeManager::makeModeMap(const string &dirPath) { DBG("dirPath : [%s]", dirPath.c_str()); diff --git a/supervisor/ModeManager.h b/supervisor/ModeManager.h index 29971d7..82f4adb 100644 --- a/supervisor/ModeManager.h +++ b/supervisor/ModeManager.h @@ -23,7 +23,6 @@ #include "RuleManager.h" #include "ModeCareTaker.h" #include "ModeObserver.h" -#include "ActionObserver.h" #include "ClientPrivilege.h" @@ -34,7 +33,7 @@ MODES_NAMESPACE_BEGIN -class ModeManager : public ActionObserver { +class ModeManager { public: ModeManager(RuleManager &rMgr); @@ -47,7 +46,6 @@ public: std::list> getModes(); void attachObserver(ModeObserver *obs); void detachObserver(ModeObserver *obs); - void update(const std::string &rule); private: bool handleEssentialAction(const Mode &mode); void notifyObservers(const std::string &modeName, ModeObserver::ModeState state); @@ -57,7 +55,6 @@ private: ModeParser* getModeParser(const std::string &path); std::map> modeMap; - std::map essentialMap; std::set modeDirList; std::string undoDir; std::string modeSyntaxFile; diff --git a/supervisor/Supervisor.cpp b/supervisor/Supervisor.cpp index 90366e1..93add79 100644 --- a/supervisor/Supervisor.cpp +++ b/supervisor/Supervisor.cpp @@ -19,6 +19,7 @@ #include "ModesEx.h" #include "ModeManager.h" #include "RequestHandler.h" +#include "EssentialHandler.h" #include "ArgumentParser.h" MODES_NAMESPACE_USE; @@ -32,6 +33,7 @@ void Supervisor::init() { RequestHandler::setModeManager(&modeMgr); RequestHandler::setRuleManager(&ruleMgr); + EssentialHandler::setModeManager(&modeMgr); try { clientConn.startDbus(); diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 88d3d5b..335073b 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -44,6 +44,7 @@ FILE(GLOB GTEST_MODEMGR_SRCS ${SUPERVISOR_DIR}/ModeManager.cpp ${SUPERVISOR_DIR}/ConflictManager.cpp ${SUPERVISOR_DIR}/ModeCareTaker.cpp + ${SUPERVISOR_DIR}/EssentialHandler.cpp ${SUPERVISOR_DIR}/ModeXMLParser.cpp ${SUPERVISOR_DIR}/UndoInfoParser.cpp ${SUPERVISOR_DIR}/Action.cpp @@ -120,6 +121,9 @@ FILE(GLOB GTEST_CONFLICT_SRCS ${SUPERVISOR_DIR}/ConflictManager.cpp ${SUPERVISOR_DIR}/Mode.cpp ${SUPERVISOR_DIR}/ModeCareTaker.cpp + ${SUPERVISOR_DIR}/EssentialHandler.cpp + ${SUPERVISOR_DIR}/ModeManager.cpp + ${SUPERVISOR_DIR}/UndoInfoParser.cpp ${SUPERVISOR_DIR}/XMLGenerator.cpp ${SUPERVISOR_DIR}/Action.cpp ${SUPERVISOR_DIR}/ModeXMLParser.cpp