Add calling callback for onError
authorYuta Doi <yuta-d@witz-inc.co.jp>
Wed, 20 Jun 2018 08:26:25 +0000 (17:26 +0900)
committerYuta Doi <yuta-d@witz-inc.co.jp>
Wed, 20 Jun 2018 08:26:25 +0000 (17:26 +0900)
Change-Id: I462759f3fe1f826bfd45e15c9b9416cf53486ed2
Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
src/app.cpp
src/policy_manager/policy_manager.cpp

index a30a963..05f8b64 100644 (file)
@@ -95,9 +95,14 @@ struct result<layer_map> load_layer_map(char const *filename) {
 
 namespace rm {
 App *context;
-static void eventHandler(json_object* json_out) {
+static void onStateTransitioned(json_object* json_out) {
     context->updateWindowResources(json_out);
 }
+
+static void onError(json_object* json_out) {
+    HMI_DEBUG("wm", "error message from PolicyManager:%s",
+              json_object_get_string(json_out));
+}
 }  // namespace rm
 
 
@@ -389,8 +394,8 @@ int App::init() {
 
    // Register callback to PolicyManager
    PolicyManager::CallbackTable callback;
-   callback.onStateTransitioned = rm::eventHandler;
-   callback.onError = nullptr;
+   callback.onStateTransitioned = rm::onStateTransitioned;
+   callback.onError = rm::onError;
    this->pm_.registerCallback(callback);
 
    // Initialize LayoutManager
index c15936d..bb5b14c 100644 (file)
@@ -210,11 +210,11 @@ static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
     category_no = ((event_data & STM_MSK_CTG_NO) >> 8) - 1;
     area_no     = ((event_data & STM_MSK_ARA_NO) >> 16) - 1;
 
-    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]);
-    HMI_DEBUG("wm:pm", "REQ: event:%s role%s category:%s area:%s",
+    std::string req_role = pm::g_req_role_list[event_data];
+    HMI_DEBUG("wm:pm", "REQ: event:%s role:%s category:%s area:%s",
         req_evt.c_str(), req_role.c_str(), req_ctg.c_str(), req_area.c_str());
 
     // Store previous layers
@@ -407,6 +407,9 @@ static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
         }
     }
 
+    // Erase role for the event_data from list
+    pm::g_req_role_list.erase(event_data);
+
     // Check
     for (auto itr : pm::g_crr_layers) {
         pm::LayerState ls = itr.second;
@@ -533,7 +536,20 @@ static int checkPolicy(sd_event_source *source, void *data) {
     stm::stm_state_t crr_state;
     int ret = stm::stmTransitionState(event_data, &crr_state);
     if (0 > ret) {
-        HMI_ERROR("wm:pm", "Error!!");
+        HMI_ERROR("wm:pm", "Failed transition state");
+        if (nullptr != pm::callback.onError) {
+            json_object* json_out = json_object_new_object();
+            json_object_object_add(json_out, "message",
+                                   json_object_new_string("Failed to transition state"));
+            json_object_object_add(json_out, "event",
+                                   json_object_new_string(stm::gStmEventName[event_no]));
+            json_object_object_add(json_out, "role",
+                                   json_object_new_string(pm::g_req_role_list[event_data].c_str()));
+            json_object_object_add(json_out, "area",
+                                   json_object_new_string(stm::gStmAreaName[area_no]));
+            pm::callback.onError(json_out);
+            json_object_put(json_out);
+        }
         return -1;
     }