aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuta Doi <yuta-d@witz-inc.co.jp>2018-06-18 18:54:57 +0900
committerYuta Doi <yuta-d@witz-inc.co.jp>2018-06-18 18:54:57 +0900
commit76a933a557531b92d2802c4fbae8205bb8d68faf (patch)
tree0432bc327fbdb96400db57be90abe37071c3b6d7 /src
parent36098a64cf5bcac3d721f126e3d809674badc110 (diff)
Modify API of PolicyManager
Change-Id: Iae45cc7c34560396490722b2cc4570a04d806ae7 Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
Diffstat (limited to 'src')
-rw-r--r--src/app.cpp6
-rw-r--r--src/policy_manager/policy_manager.cpp80
-rw-r--r--src/policy_manager/policy_manager.hpp4
-rw-r--r--src/policy_manager/zipc/dummy_stm.c4
-rw-r--r--src/policy_manager/zipc/dummy_stm.h1
5 files changed, 74 insertions, 21 deletions
diff --git a/src/app.cpp b/src/app.cpp
index 712ec3b..d5fa3b4 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -582,7 +582,11 @@ void App::allocateWindowResource(char const *event, char const *drawing_name,
json_object_object_add(json_in, "area", json_object_new_string(new_area));
}
- this->pm_.inputEvent(json_in);
+ // Set input event data
+ this->pm_.setInputEventData(json_in);
+
+ // Execute state transition
+ this->pm_.executeStateTransition();
// Release json_object
json_object_put(json_in);
diff --git a/src/policy_manager/policy_manager.cpp b/src/policy_manager/policy_manager.cpp
index 23d1e29..bc3fd8d 100644
--- a/src/policy_manager/policy_manager.cpp
+++ b/src/policy_manager/policy_manager.cpp
@@ -20,6 +20,7 @@
#include <istream>
#include <thread>
#include <map>
+#include <queue>
#include <systemd/sd-event.h>
#include <json-c/json.h>
#include "policy_manager.hpp"
@@ -43,7 +44,6 @@ typedef std::vector<AreaState> AreaList;
typedef struct LayoutState {
std::string name;
std::map<std::string, int> category_num;
-// int category_num[stm::gStmCategoryNoNum];
AreaList area_list;
std::map<std::string, std::vector<std::string>> role_history;
} LayoutState;
@@ -53,10 +53,17 @@ typedef struct LayerState {
LayoutState layout_state;
} LayerState;
+typedef struct EventInfo {
+ int event;
+ std::string role;
+ uint64_t delay;
+} EventInfo;
+
struct sd_event* event_loop;
std::map<int, struct sd_event_source*> event_source_list;
-std::map<int, std::string> g_event_info_list;
+std::map<int, std::string> g_req_role_list;
PolicyManager::CallbackTable callback;
+std::queue<EventInfo> g_event_info_queue;
std::unordered_map<std::string, LayerState> g_prv_layers;
std::unordered_map<std::string, LayerState> g_crr_layers;
@@ -197,7 +204,7 @@ static void addStateToJson(const char* layer_name, unsigned int changed,
}
-static int checkPolicyEntry(int event, uint64_t delay_ms, const char* role);
+static int checkPolicyEntry(int event, uint64_t delay_ms, std::string role);
static int checkPolicy(sd_event_source *source, void *data) {
HMI_DEBUG("wm:pm", "Call");
HMI_DEBUG("wm:pm", ">>>>>>>>>> START CHECK POLICY");
@@ -265,7 +272,7 @@ static int checkPolicy(sd_event_source *source, void *data) {
// Store previous layers
pm::g_prv_layers = pm::g_crr_layers;
- std::string req_role = pm::g_event_info_list[event_data];
+ std::string req_role = pm::g_req_role_list[event_data];
std::string req_evt = std::string(stm::gStmEventName[event_no]);
std::string req_ctg = std::string(stm::gStmCategoryName[category_no]);
std::string req_area = std::string(stm::gStmAreaName[area_no]);
@@ -611,29 +618,26 @@ static int checkPolicy(sd_event_source *source, void *data) {
}
static int timerEvent(sd_event_source *source, uint64_t usec, void *data) {
+ HMI_DEBUG("wm:pm", "Call");
+
int ret = checkPolicy(source, data);
return ret;
-};
+}
-static int checkPolicyEntry(int event, uint64_t delay_ms, const char* role)
+static int checkPolicyEntry(int event, uint64_t delay_ms, std::string role)
{
HMI_DEBUG("wm:pm", "Call");
- HMI_DEBUG("wm:pm", "event:0x%x", event);
+ HMI_DEBUG("wm:pm", "event:0x%x delay:%d role:%s", event, delay_ms, role.c_str());
- // Store event info
- if (nullptr == role) {
- pm::g_event_info_list[event] = std::string("");
- }
- else {
- pm::g_event_info_list[event] = std::string(role);
- }
+ // Store requested role
+ pm::g_req_role_list[event] = role;
if (0 == delay_ms) {
int ret = sd_event_add_defer(pm::event_loop, NULL,
&checkPolicy, new int(event));
if (0 > ret) {
HMI_ERROR("wm:pm", "Faild to sd_event_add_defer: errno:%d", ret);
- pm::g_event_info_list.erase(event);
+ pm::g_req_role_list.erase(event);
return -1;
}
}
@@ -653,7 +657,7 @@ static int checkPolicyEntry(int event, uint64_t delay_ms, const char* role)
&timerEvent, new int(event));
if (0 > ret) {
HMI_ERROR("wm:pm", "Faild to sd_event_add_time: errno:%d", ret);
- pm::g_event_info_list.erase(event);
+ pm::g_req_role_list.erase(event);
return -1;
}
@@ -665,11 +669,13 @@ static int checkPolicyEntry(int event, uint64_t delay_ms, const char* role)
}
void PolicyManager::registerCallback(CallbackTable callback) {
+ HMI_DEBUG("wm:pm", "Call");
+
pm::callback.onStateTransitioned = callback.onStateTransitioned;
pm::callback.onError = callback.onError;
}
-int PolicyManager::inputEvent(json_object* json_in) {
+int PolicyManager::setInputEventData(json_object* json_in) {
HMI_DEBUG("wm:pm", "Call");
// Check arguments
@@ -715,12 +721,48 @@ int PolicyManager::inputEvent(json_object* json_in) {
HMI_DEBUG("wm:pm", "area(%s:%d)", area, area_no);
}
- // Check policy
- checkPolicyEntry((event_no | category_no | area_no), 0, role);
+ // Set event info to the queue
+ pm::EventInfo event_info;
+ event_info.event = (event_no | category_no | area_no);
+ if (nullptr == role) {
+ event_info.role = std::string("");
+ }
+ else {
+ event_info.role = std::string(role);
+ }
+ event_info.role = std::string(role);
+ event_info.delay = 0;
+ pm::g_event_info_queue.push(event_info);
return 0;
}
+int PolicyManager::executeStateTransition() {
+ HMI_DEBUG("wm:pm", "Call");
+
+ int ret;
+ pm::EventInfo event_info;
+
+ while (!pm::g_event_info_queue.empty()) {
+ // Get event info from queue and delete
+ event_info = pm::g_event_info_queue.front();
+ pm::g_event_info_queue.pop();
+
+ // Set event info for checking policy
+ ret = checkPolicyEntry(event_info.event, event_info.delay, event_info.role);
+ }
+ return ret;
+}
+
+void PolicyManager::undoState() {
+ HMI_DEBUG("wm:pm", "Call");
+
+ // Undo state of STM
+ stm::stmUndoState();
+
+ pm::g_crr_layers = pm::g_prv_layers;
+}
+
extern const char* kDefaultRoleDb;
int PolicyManager::loadRoleDb() {
HMI_DEBUG("wm:pm", "Call");
diff --git a/src/policy_manager/policy_manager.hpp b/src/policy_manager/policy_manager.hpp
index 0e05cc0..79792ee 100644
--- a/src/policy_manager/policy_manager.hpp
+++ b/src/policy_manager/policy_manager.hpp
@@ -41,7 +41,9 @@ public:
int initialize();
void registerCallback(CallbackTable callback_table);
- int inputEvent(json_object* json_in);
+ int setInputEventData(json_object* json_in);
+ int executeStateTransition();
+ void undoState();
private:
// Disable copy and move
diff --git a/src/policy_manager/zipc/dummy_stm.c b/src/policy_manager/zipc/dummy_stm.c
index 643e11e..3376987 100644
--- a/src/policy_manager/zipc/dummy_stm.c
+++ b/src/policy_manager/zipc/dummy_stm.c
@@ -600,3 +600,7 @@ int stmTransitionState(int event, stm_state_t* state) {
return 0;
}
+
+void stmUndoState() {
+ g_crr_state = g_prv_state;
+}
diff --git a/src/policy_manager/zipc/dummy_stm.h b/src/policy_manager/zipc/dummy_stm.h
index c94e8e0..495f8cf 100644
--- a/src/policy_manager/zipc/dummy_stm.h
+++ b/src/policy_manager/zipc/dummy_stm.h
@@ -196,6 +196,7 @@ typedef struct {
void stmInitialize();
int stmTransitionState(int event_no, stm_state_t* state);
+void stmUndoState();
#endif // TMCAGLWM_DUMMY_STM_HPP