#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...)
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<ActionObserver*> observers;
};
--- /dev/null
+/*
+ * 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 <glib.h>
+#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;
+}
--- /dev/null
+/*
+ * 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 <string>
+#include <glib.h>
+#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
#include "mdss.h"
#include "XMLGenerator.h"
+#include "EssentialHandler.h"
MODES_NAMESPACE_USE;
savedModes.insert(std::pair<std::string, Mode>(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);
}
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;
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;
}
}
}
return stopOnErr;
}
+
+void ModeCareTaker::handleEssentialAction(const Mode &mode)
+{
+ DBG("Mode has Essential Action(%s)", mode.getName().c_str());
+
+ std::list<std::shared_ptr<Action>> 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);
+}
#include <string>
#include "mdss.h"
#include "Mode.h"
+#include "ActionObserver.h"
MODES_NAMESPACE_BEGIN
-class ModeCareTaker {
+class ModeCareTaker : public ActionObserver {
public:
ModeCareTaker();
~ModeCareTaker() = default;
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<std::string, Mode> savedModes;
+ std::multimap<std::string, std::string> essentialMap;
std::string undoDir;
bool exclusive;
};
void ModeManager::init()
{
modeMap.clear();
- essentialMap.clear();
for (auto it = modeDirList.begin(); it != modeDirList.end(); ++it) {
makeModeMap(*it);
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<std::shared_ptr<Action>> 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);
return ret;
}
careTaker.pushMode(mode);
- if (mode.hasEssential())
- handleEssentialAction(mode);
}
} catch (ModesEx &e) {
//Ususally, it is reached by Invalid Mode File
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;
(*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());
#include "RuleManager.h"
#include "ModeCareTaker.h"
#include "ModeObserver.h"
-#include "ActionObserver.h"
#include "ClientPrivilege.h"
MODES_NAMESPACE_BEGIN
-class ModeManager : public ActionObserver {
+class ModeManager {
public:
ModeManager(RuleManager &rMgr);
std::list<std::tuple<std::string, int>> 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);
ModeParser* getModeParser(const std::string &path);
std::map<std::string, std::pair<std::string, bool>> modeMap;
- std::map<std::string, std::string> essentialMap;
std::set<std::string> modeDirList;
std::string undoDir;
std::string modeSyntaxFile;
#include "ModesEx.h"
#include "ModeManager.h"
#include "RequestHandler.h"
+#include "EssentialHandler.h"
#include "ArgumentParser.h"
MODES_NAMESPACE_USE;
{
RequestHandler::setModeManager(&modeMgr);
RequestHandler::setRuleManager(&ruleMgr);
+ EssentialHandler::setModeManager(&modeMgr);
try {
clientConn.startDbus();
${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
${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