Segment process for control timer event
[apps/agl-service-windowmanager.git] / src / policy_manager / policy_manager.cpp
index bb5b14c..6ae80c6 100644 (file)
@@ -424,7 +424,7 @@ static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
     }
 }
 
-void createOutputInformation(stm::stm_state_t crr_state, json_object **json_out) {
+static void createOutputInformation(stm::stm_state_t crr_state, json_object **json_out) {
     // Create result
     // {
     //     "parking_brake": {
@@ -517,6 +517,31 @@ void createOutputInformation(stm::stm_state_t crr_state, json_object **json_out)
 }
 
 static int checkPolicyEntry(int event, uint64_t delay_ms, std::string role);
+static void controlTimerEvent(stm::stm_state_t crr_state) {
+    if (crr_state.car.is_changed) {
+        if (stm::gStmCarStateNoRun == crr_state.car.state) {
+            // Set delay event(restriction mode on)
+            checkPolicyEntry(STM_EVT_NO_RESTRICTION_MODE_ON, 3000, "");
+        }
+        else if (stm::gStmCarStateNoStop == crr_state.car.state) {
+            // Stop timer for restriction on event
+            if (pm::event_source_list.find(STM_EVT_NO_RESTRICTION_MODE_ON)
+              != pm::event_source_list.end()) {
+                HMI_DEBUG("wm:pm", "Stop timer for restriction on");
+                sd_event_source *event_source
+                    = pm::event_source_list[STM_EVT_NO_RESTRICTION_MODE_ON];
+                int ret = sd_event_source_set_enabled(event_source, SD_EVENT_OFF);
+                if (0 > ret) {
+                    HMI_ERROR("wm:pm", "Failed to stop timer");
+                }
+            }
+
+            // Set event(restriction mode off)
+            checkPolicyEntry(STM_EVT_NO_RESTRICTION_MODE_OFF, 0, "");
+        }
+    }
+}
+
 static int checkPolicy(sd_event_source *source, void *data) {
     HMI_DEBUG("wm:pm", "Call");
     HMI_DEBUG("wm:pm", ">>>>>>>>>> START CHECK POLICY");
@@ -601,34 +626,13 @@ static int checkPolicy(sd_event_source *source, void *data) {
     json_object* json_out = json_object_new_object();
     createOutputInformation(crr_state, &json_out);
 
-    // Notify state is changed
+    // Notify changed state
     if (nullptr != pm::callback.onStateTransitioned) {
         pm::callback.onStateTransitioned(json_out);
     }
 
-    // Start/Stop timer event
-    if (crr_state.car.is_changed) {
-        if (stm::gStmCarStateNoRun == crr_state.car.state) {
-            // Set delay event(restriction mode on)
-            checkPolicyEntry(STM_EVT_NO_RESTRICTION_MODE_ON, 3000, "");
-        }
-        else if (stm::gStmCarStateNoStop == crr_state.car.state) {
-            // Set event(restriction mode off)
-            checkPolicyEntry(STM_EVT_NO_RESTRICTION_MODE_OFF, 0, "");
-
-            // Stop timer for restriction on event
-            if (pm::event_source_list.find(STM_EVT_NO_RESTRICTION_MODE_ON)
-              != pm::event_source_list.end()) {
-                HMI_DEBUG("wm:pm", "Stop timer for restriction on");
-                sd_event_source *event_source
-                    = pm::event_source_list[STM_EVT_NO_RESTRICTION_MODE_ON];
-                int ret = sd_event_source_set_enabled(event_source, SD_EVENT_OFF);
-                if (0 > ret) {
-                    HMI_ERROR("wm:pm", "Failed to stop timer");
-                }
-            }
-        }
-    }
+    // Start/Stop timer events
+    controlTimerEvent(crr_state);
 
     // Release json_object
     json_object_put(json_out);