diff options
author | Yuta Doi <yuta-d@witz-inc.co.jp> | 2018-05-31 15:34:38 +0900 |
---|---|---|
committer | Yuta Doi <yuta-d@witz-inc.co.jp> | 2018-05-31 15:34:38 +0900 |
commit | 281b5c41bd8a7bade279c6626049af30f5ddcd00 (patch) | |
tree | 5f127b08908a6e7af5e170b3c695a36fc9e1492d /src | |
parent | 681bb3f7b1618a083ac07878d9513e56e9279967 (diff) |
Use sd_event_add_defer() for dispatching checkPolicy
and modify the format of the logs
Change-Id: Ic6e4a74c03e9fc74277ce4da0d3fd726c81a4a95
Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
Diffstat (limited to 'src')
-rw-r--r-- | src/policy_manager/policy_manager.cpp | 77 |
1 files changed, 45 insertions, 32 deletions
diff --git a/src/policy_manager/policy_manager.cpp b/src/policy_manager/policy_manager.cpp index 55d79d9..0cafdea 100644 --- a/src/policy_manager/policy_manager.cpp +++ b/src/policy_manager/policy_manager.cpp @@ -134,10 +134,11 @@ static void addStateToJson( json_object_object_add(*json_out, key, json_obj); } -static int checkPolicyEntry(PolicyManager* ctx, int event, int delay_ms, +static int checkPolicyEntry(PolicyManager* ctx, int event, uint64_t delay_ms, PolicyManager::Handler handler); -static int checkPolicy(sd_event_source *source, uint64_t usec, void *data) { +static int checkPolicy(sd_event_source *source, void *data) { HMI_DEBUG("wm:pm", "Call"); + HMI_DEBUG("wm:pm", ">>>>>>>>>> START CHECK POLICY"); int event = *((int*)data); @@ -149,7 +150,6 @@ static int checkPolicy(sd_event_source *source, uint64_t usec, void *data) { event_no = event & STM_MSK_EVT_NO; category_no = event & STM_MSK_CTG_NO; area_no = event & STM_MSK_ARA_NO; - HMI_DEBUG("wm:pm", ">>>>>>>>>> START CHECK POLICY"); HMI_DEBUG("wm:pm", ">>>>>>>>>> event:%s category:%s area:%s", stm::gStmEventName[event_no - 1], stm::gStmCategoryName[(category_no >> 8) - 1], @@ -163,43 +163,43 @@ static int checkPolicy(sd_event_source *source, uint64_t usec, void *data) { return -1; } - HMI_DEBUG("wm", "parking brake state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "parking brake state (is_changed:%d state:%d:%s)", crr_state.parking_brake.is_changed, crr_state.parking_brake.state, stm::gStmParkingBrakeStateNo2Name[crr_state.parking_brake.state]); - HMI_DEBUG("wm", "accelerator pedal state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "accelerator pedal state (is_changed:%d state:%d:%s)", crr_state.accel_pedal.is_changed, crr_state.accel_pedal.state, stm::gStmAccelPedalStateNo2Name[crr_state.accel_pedal.state]); - HMI_DEBUG("wm", "lightstatus brake state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "lightstatus brake state (is_changed:%d state:%d:%s)", crr_state.lightstatus_brake.is_changed, crr_state.lightstatus_brake.state, stm::gStmLightstatusBrakeStateNo2Name[crr_state.lightstatus_brake.state]); - HMI_DEBUG("wm", "car state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "car state (is_changed:%d state:%d:%s)", crr_state.car.is_changed, crr_state.car.state, stm::gStmCarStateNo2Name[crr_state.car.state]); - HMI_DEBUG("wm", "lamp state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "lamp state (is_changed:%d state:%d:%s)", crr_state.lamp.is_changed, crr_state.lamp.state, stm::gStmLampStateNo2Name[crr_state.lamp.state]); - HMI_DEBUG("wm", "restriction mode state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "restriction mode state (is_changed:%d state:%d:%s)", crr_state.restriction_mode.is_changed, crr_state.restriction_mode.state, stm::gStmRestrictionModeStateNo2Name[crr_state.restriction_mode.state]); - HMI_DEBUG("wm", "homescreen state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "homescreen state (is_changed:%d state:%d:%s)", crr_state.layer.homescreen.is_changed, crr_state.layer.homescreen.state, stm::gStmLayoutNo2Name[crr_state.layer.homescreen.state]); - HMI_DEBUG("wm", "apps state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "apps state (is_changed:%d state:%d:%s)", crr_state.layer.apps.is_changed, crr_state.layer.apps.state, stm::gStmLayoutNo2Name[crr_state.layer.apps.state]); - HMI_DEBUG("wm", "restriction state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "restriction state (is_changed:%d state:%d:%s)", crr_state.layer.restriction.is_changed, crr_state.layer.restriction.state, stm::gStmLayoutNo2Name[crr_state.layer.restriction.state]); - HMI_DEBUG("wm", "on_screen state (is_changed:%d state:%d:%s)", + HMI_DEBUG("wm:pm", "on_screen state (is_changed:%d state:%d:%s)", crr_state.layer.on_screen.is_changed, crr_state.layer.on_screen.state, stm::gStmLayoutNo2Name[crr_state.layer.on_screen.state]); @@ -341,10 +341,9 @@ static int checkPolicy(sd_event_source *source, uint64_t usec, void *data) { // Release json_object json_object_put(json_out); - HMI_DEBUG("wm:pm", ">>>>>>>>>> FINISH CHECK POLICY"); } else { - HMI_DEBUG("wm", "Request for event:%d is removed", event); + HMI_DEBUG("wm:pm", "Request for event:%d is removed", event); } // Release data @@ -353,10 +352,15 @@ static int checkPolicy(sd_event_source *source, uint64_t usec, void *data) { // Destroy sd_event_soutce object sd_event_source_unref(source); + HMI_DEBUG("wm:pm", ">>>>>>>>>> FINISH CHECK POLICY"); return 0; } -static int checkPolicyEntry(PolicyManager* ctx, int event, int delay_ms, +static int timerEvent(sd_event_source *source, uint64_t usec, void *data) { + checkPolicy(source, data); +}; + +static int checkPolicyEntry(PolicyManager* ctx, int event, uint64_t delay_ms, PolicyManager::Handler handler) { HMI_DEBUG("wm:pm", "Call"); @@ -377,22 +381,31 @@ static int checkPolicyEntry(PolicyManager* ctx, int event, int delay_ms, event_data.handler = handler; pm::event_data_list[event] = event_data; - // Get current time - struct timespec time_spec; - clock_gettime(CLOCK_MONOTONIC, &time_spec); - - // Calculate timer fired time - uint64_t usec = (time_spec.tv_sec * 1000000) - + (time_spec.tv_nsec / 1000) - + (delay_ms * 1000); - - // Set timer - struct sd_event_source *source; - int ret = sd_event_add_time(pm::event_loop, &source, CLOCK_MONOTONIC, usec, 1, - &checkPolicy, new int(event)); - if (0 > ret) { - HMI_ERROR("wm:pm", "Faild to sd_event_add_time: errno:%d", ret); - return -1; + 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); + return -1; + } + } + else { + // Get current time + struct timespec time_spec; + clock_gettime(CLOCK_MONOTONIC, &time_spec); + + // Calculate timer fired time + uint64_t usec = (time_spec.tv_sec * 1000000) + + (time_spec.tv_nsec / 1000) + + (delay_ms * 1000); + + // Set timer + int ret = sd_event_add_time(pm::event_loop, NULL, CLOCK_MONOTONIC, usec, 1, + &timerEvent, new int(event)); + if (0 > ret) { + HMI_ERROR("wm:pm", "Faild to sd_event_add_time: errno:%d", ret); + return -1; + } } return 0; |