diff options
Diffstat (limited to 'src/policy_manager/policy_manager.cpp')
-rw-r--r-- | src/policy_manager/policy_manager.cpp | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/src/policy_manager/policy_manager.cpp b/src/policy_manager/policy_manager.cpp index 89a939c..1c2acb4 100644 --- a/src/policy_manager/policy_manager.cpp +++ b/src/policy_manager/policy_manager.cpp @@ -92,19 +92,19 @@ int PolicyManager::initialize() { int ret = 0; // Create convert map - for (int i = stm::gStmEventNoMin; i <= stm::gStmEventNoMax; i++) { - HMI_DEBUG("wm:pm", "event name:%s no:%d", stm::gStmEventName[i], stm::gStmEventNo[i]); - this->eventname2no[stm::gStmEventName[i]] = stm::gStmEventNo[i]; + for (int i = stm::STM_EVT_NO_MIN; i <= stm::STM_EVT_NO_MAX; i++) { + HMI_DEBUG("wm:pm", "event name:%s no:%d", stm::gStmEventName[i], i); + this->eventname2no[stm::gStmEventName[i]] = i; } - for (int i = stm::gStmCategoryNoMin; i <= stm::gStmCategoryNoMax; i++) { - HMI_DEBUG("wm:pm", "category name:%s no:%d", stm::gStmCategoryName[i], stm::gStmCategoryNo[i]); - this->categoryname2no[stm::gStmCategoryName[i]] = stm::gStmCategoryNo[i]; + for (int i = stm::STM_CTG_NO_MIN; i <= stm::STM_CTG_NO_MAX; i++) { + HMI_DEBUG("wm:pm", "category name:%s no:%d", stm::gStmCategoryName[i], i); + this->categoryname2no[stm::gStmCategoryName[i]] = i; } - for (int i = stm::gStmAreaNoMin; i <= stm::gStmAreaNoMax; i++) { - HMI_DEBUG("wm:pm", "area name:%s no:%d", stm::gStmAreaName[i], stm::gStmAreaNo[i]); - this->areaname2no[stm::gStmAreaName[i]] = stm::gStmAreaNo[i]; + for (int i = stm::STM_AREA_NO_MIN; i <= stm::STM_AREA_NO_MAX; i++) { + HMI_DEBUG("wm:pm", "area name:%s no:%d", stm::gStmAreaName[i], i); + this->areaname2no[stm::gStmAreaName[i]] = i; } // Load role.db @@ -153,7 +153,7 @@ static void initializeLocalCarElementState() { static void initializeLocalLayerState() { pm::AreaState init_area; pm::LayoutState init_layout; - init_area.name = stm::gStmAreaName[stm::gStmAreaNoNone]; + init_area.name = stm::gStmAreaName[stm::STM_AREA_NO_NONE]; init_area.category = ""; init_area.role = ""; init_layout.name = stm::gStmLayoutName[stm::gStmLayoutNoNone]; @@ -256,13 +256,13 @@ static void updateLocalCarElementState(stm::stm_state_t crr_state) { static void updateLocalLayerState(int event_data, stm::stm_state_t crr_state) { int event_no, category_no, area_no; - event_no = (event_data & STM_MSK_EVT_NO) - 1; - category_no = ((event_data & STM_MSK_CTG_NO) >> 8) - 1; - area_no = ((event_data & STM_MSK_ARA_NO) >> 16) - 1; + event_no = GET_EVENT_FROM_ID(event_data); + category_no = GET_CATEGORY_FROM_ID(event_data); + area_no = GET_AREA_FROM_ID(event_data); - std::string req_evt = std::string((event_no < 0) ? "-" : stm::gStmEventName[event_no]); - std::string req_ctg = std::string((category_no < 0) ? "-" : stm::gStmCategoryName[category_no]); - std::string req_area = std::string((area_no < 0) ? "-" : stm::gStmAreaName[area_no]); + std::string req_evt = stm::gStmEventName[event_no]; + std::string req_ctg = stm::gStmCategoryName[category_no]; + std::string req_area = stm::gStmAreaName[area_no]; 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()); @@ -324,12 +324,12 @@ static void updateLocalLayerState(int event_data, stm::stm_state_t crr_state) { crr_layout_state = pm::g_prv_layers_car_stop[layer_name].layout_state; crr_layout_name = crr_layout_state.name; if ((prv_layout_name == crr_layout_name) - && (stm::gStmAreaName[stm::gStmAreaNoNone] == crr_layout_name)) { + && (stm::gStmAreaName[stm::STM_AREA_NO_NONE] == crr_layout_name)) { changed = 0; } } else if ((prv_layout_name == crr_layout_name) - && (stm::gStmAreaName[stm::gStmAreaNoNone] == crr_layout_name)) { + && (stm::gStmAreaName[stm::STM_AREA_NO_NONE] == crr_layout_name)) { // Copy previous layout state for current crr_layout_state = prv_layout_state; changed = 0; @@ -354,8 +354,8 @@ static void updateLocalLayerState(int event_data, stm::stm_state_t crr_state) { // Create candidate list std::map<std::string, pm::AreaList> cand_list; - for (int ctg_no=stm::gStmCategoryNoMin; - ctg_no<=stm::gStmCategoryNoMax; ctg_no++) { + for (int ctg_no=stm::STM_CTG_NO_MIN; + ctg_no<=stm::STM_CTG_NO_MAX; ctg_no++) { const char* ctg = stm::gStmCategoryName[ctg_no]; HMI_DEBUG("wm:pm", "ctg:%s", ctg); @@ -559,15 +559,15 @@ static void controlTimerEvent(stm::stm_state_t crr_state) { if (crr_state.car_element[stm::gStmCarElementNoRunning].changed) { if (stm::gStmRunningNoRun == crr_state.car_element[stm::gStmCarElementNoRunning].state) { // Set delay event(restriction mode on) - checkPolicyEntry(STM_EVT_NO_RESTRICTION_MODE_ON, 3000, ""); + checkPolicyEntry(stm::STM_EVT_NO_RESTRICTION_MODE_ON, 3000, ""); } else if (stm::gStmRunningNoStop == crr_state.car_element[stm::gStmCarElementNoRunning].state) { // Stop timer for restriction on event - if (pm::event_source_list.find(STM_EVT_NO_RESTRICTION_MODE_ON) + if (pm::event_source_list.find(stm::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]; + = pm::event_source_list[stm::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"); @@ -575,7 +575,7 @@ static void controlTimerEvent(stm::stm_state_t crr_state) { } // Set event(restriction mode off) - checkPolicyEntry(STM_EVT_NO_RESTRICTION_MODE_OFF, 0, ""); + checkPolicyEntry(stm::STM_EVT_NO_RESTRICTION_MODE_OFF, 0, ""); } } } @@ -587,13 +587,13 @@ static int checkPolicy(sd_event_source *source, void *data) { int event_data = *((int*)data); int event_no, category_no, area_no; - event_no = (event_data & STM_MSK_EVT_NO) - 1; - category_no = ((event_data & STM_MSK_CTG_NO) >> 8) - 1; - area_no = ((event_data & STM_MSK_ARA_NO) >> 16) - 1; + event_no = GET_EVENT_FROM_ID(event_data); + category_no = GET_CATEGORY_FROM_ID(event_data); + area_no = GET_AREA_FROM_ID(event_data); HMI_DEBUG("wm:pm", ">>>>>>>>>> event:%s category:%s area:%s", - (event_no < 0) ? "-" : stm::gStmEventName[event_no], - (category_no < 0) ? "-" : stm::gStmCategoryName[category_no], - (area_no < 0) ? "-" : stm::gStmAreaName[area_no]); + stm::gStmEventName[event_no], + stm::gStmCategoryName[category_no], + stm::gStmAreaName[area_no]); // Transition state stm::stm_state_t crr_state; @@ -718,7 +718,7 @@ int PolicyManager::setInputEventData(json_object* json_in) { // Get event from json_object const char* event = this->getStringFromJson(json_in, "event"); - int event_no = stm::gStmEventNoNone; + int event_no = stm::STM_EVT_NO_NONE; if (nullptr != event) { // Convert name to number auto itr = this->eventname2no.find(event); @@ -738,7 +738,7 @@ int PolicyManager::setInputEventData(json_object* json_in) { // Get role from json_object const char* role = this->getStringFromJson(json_in, "role"); - int category_no = stm::gStmCategoryNoNone; + int category_no = stm::STM_CTG_NO_NONE; if (nullptr != role) { HMI_DEBUG("wm:pm", "role(%s)", role); @@ -754,13 +754,13 @@ int PolicyManager::setInputEventData(json_object* json_in) { } } - if (stm::gStmCategoryNoNone == category_no) { + if (stm::STM_CTG_NO_NONE == category_no) { role = ""; } // Get areat from json_object const char* area = this->getStringFromJson(json_in, "area"); - int area_no = stm::gStmAreaNoNone; + int area_no = stm::STM_AREA_NO_NONE; if (nullptr != area) { auto itr = this->areaname2no.find(area); if (this->areaname2no.end() != itr) { @@ -770,8 +770,8 @@ int PolicyManager::setInputEventData(json_object* json_in) { } // If role is set and area is not set, use default area - if ((stm::gStmAreaNoNone == area_no) - && (stm::gStmCategoryNoNone != category_no)) { + if ((stm::STM_AREA_NO_NONE == area_no) + && (stm::STM_CTG_NO_NONE != category_no)) { std::string def_area = this->role2defaultarea[role]; area_no = this->areaname2no[def_area]; HMI_DEBUG("wm:pm", "area(%s:%d)", def_area.c_str(), area_no); @@ -779,7 +779,8 @@ int PolicyManager::setInputEventData(json_object* json_in) { // Set event info to the queue EventInfo event_info; - event_info.event = (event_no | category_no | area_no); + int event_id = CREATE_EVENT_ID(event_no, category_no, area_no); + event_info.event = event_id; event_info.role = std::string(role); event_info.delay = 0; this->event_info_queue.push(event_info); @@ -968,8 +969,8 @@ int PolicyManager::loadLayoutDb() { pm::LayoutState layout_state; pm::AreaState area_state; std::map<std::string, int> category_num; - for (int ctg_no = stm::gStmCategoryNoMin; - ctg_no <= stm::gStmCategoryNoMax; ctg_no++) { + for (int ctg_no = stm::STM_CTG_NO_MIN; + ctg_no <= stm::STM_CTG_NO_MAX; ctg_no++) { const char* ctg_name = stm::gStmCategoryName[ctg_no]; category_num[ctg_name] = 0; } |