+ this->crr_car_elements[car_ele_name].state = car_state;
+ this->crr_car_elements[car_ele_name].changed = changed;
+
+ HMI_DEBUG("wm:pm", ">>> >>> NAME: %s", car_ele_name);
+ HMI_DEBUG("wm:pm", ">>> >>> >>> STATE:%s", car_state.c_str());
+ HMI_DEBUG("wm:pm", ">>> >>> >>> CHANGED:%s", (changed) ? "true" : "false");
+ }
+}
+
+void PolicyManager::updateLayerState(int event_data, stm::StmState crr_state) {
+ int event_no, category_no, area_no;
+
+ event_no = STM_GET_EVENT_FROM_ID(event_data);
+ category_no = STM_GET_CATEGORY_FROM_ID(event_data);
+ area_no = STM_GET_AREA_FROM_ID(event_data);
+
+ std::string req_evt = stm::kStmEventName[event_no];
+ std::string req_ctg = stm::kStmCategoryName[category_no];
+ std::string req_area = stm::kStmAreaName[area_no];
+ std::string req_role = this->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
+ this->prv_layers = this->crr_layers;
+
+ // Update layers
+ for (int layer_no = stm::StmLayerNoMin;
+ layer_no <= stm::StmLayerNoMax; layer_no++) {
+ const char* layer_name = stm::kStmLayerName[layer_no];
+ HMI_DEBUG("wm:pm", "LAYER:%s", layer_name);
+
+#if 1
+ // If restriction mode is changed off -> on,
+ // store current state for state of restriction mode off
+ if ((crr_state.car_element[stm::StmCarElementNoRestrictionMode].changed)
+ && (stm::StmRestrictionModeSttNoOn == crr_state.car_element[stm::StmCarElementNoRestrictionMode].state)) {
+ HMI_DEBUG("wm:pm", "Store current state for state of restriction mode off");
+ this->prv_layers_car_stop[layer_name] = this->crr_layers[layer_name];
+ }
+#else
+ // If car state is changed car_stop -> car_run,
+ // store current state for state of car stop
+ if ((crr_state.car.changed)
+ && (stm::StmRunningNoRun == crr_state.car.state)) {
+ HMI_DEBUG("wm:pm", "Store current state for state of car stop");
+ this->prv_layers_car_stop[layer_name] = this->crr_layers[layer_name];
+ }
+#endif
+
+ // This layer is changed?
+ int changed = crr_state.layer[layer_no].changed;
+ if (changed) {
+ HMI_DEBUG("wm:pm", "This layer is changed");
+
+ // Get previous layout name of this layer
+ LayoutState prv_layout_state = this->prv_layers[layer_name].layout_state;
+ std::string prv_layout_name = prv_layout_state.name;
+
+ // Get current layout name of this layer
+ int crr_layout_state_no = crr_state.layer[layer_no].state;
+ std::string crr_layout_name = std::string(stm::kStmLayoutName[crr_layout_state_no]);
+
+ LayoutState crr_layout_state;
+#if 1
+ if ((crr_state.car_element[stm::StmCarElementNoRestrictionMode].changed)
+ && (stm::StmRestrictionModeSttNoOff == crr_state.car_element[stm::StmCarElementNoRestrictionMode].state)) {
+ // If restriction mode is changed on -> off,
+ // restore state of restriction mode off
+ HMI_DEBUG("wm:pm", "Restriction mode is changed on -> off, so restore state of restriction mode off");
+#else
+ if ((crr_state.car_element[stm::StmCarElementNoRunning].changed)
+ && (stm::StmCarElementNoStop == crr_state.car_element[stm::StmCarElementNoRunning].state)) {
+ // If car state is changed car_run -> car_stop,
+ // restore state of car stop
+ HMI_DEBUG("wm:pm", "Car state is changed car_run -> car_stop, so restore state of car stop");
+#endif
+ crr_layout_state = this->prv_layers_car_stop[layer_name].layout_state;
+ crr_layout_name = crr_layout_state.name;
+ if ((prv_layout_name == crr_layout_name)
+ && (stm::kStmAreaName[stm::StmAreaNoNone] == crr_layout_name)) {
+ changed = 0;
+ }
+ }
+ else if ((prv_layout_name == crr_layout_name)
+ && (stm::kStmAreaName[stm::StmAreaNoNone] == crr_layout_name)) {
+ // Copy previous layout state for current
+ crr_layout_state = prv_layout_state;
+ changed = 0;
+ }
+ else {
+ // Copy previous layout state for current
+ crr_layout_state = prv_layout_state;
+
+ HMI_DEBUG("wm:pm", "layout name previous:%s current:%s",
+ prv_layout_name.c_str(), crr_layout_name.c_str());
+ if (prv_layout_name == crr_layout_name) {
+ HMI_DEBUG("wm:pm", "Previous layout is same with current");
+ }
+ else {
+ // If previous layout is NOT same with current,
+ // current areas is set with default value
+ HMI_DEBUG("wm:pm", "Previous layout is NOT same with current");
+ crr_layout_state.name = this->default_layouts[crr_layout_name].name;
+ crr_layout_state.category_num = this->default_layouts[crr_layout_name].category_num;
+ crr_layout_state.area_list = this->default_layouts[crr_layout_name].area_list;
+ }
+
+ // Create candidate list
+ std::map<std::string, AreaList> cand_list;
+ for (int ctg_no=stm::StmCtgNoMin;
+ ctg_no<=stm::StmCtgNoMax; ctg_no++) {
+ const char* ctg = stm::kStmCategoryName[ctg_no];
+ HMI_DEBUG("wm:pm", "ctg:%s", ctg);
+
+ // Create candidate list for category from the previous displayed categories
+ AreaList tmp_cand_list;
+ for (AreaState area_state : prv_layout_state.area_list) {
+ if (std::string(ctg) == area_state.category) {
+ // If there is the category which is same with new category in previous layout,
+ // push it to list
+ HMI_DEBUG("wm:pm", "Push to candidate list category:%s role:%s",
+ area_state.category.c_str(), area_state.role.c_str());
+ tmp_cand_list.push_back(area_state);
+ }
+ }
+
+ int candidate_num = prv_layout_state.category_num[ctg];
+ int blank_num = crr_layout_state.category_num[ctg];
+ HMI_DEBUG("wm:pm", "blank_num:%d candidate_num:%d", blank_num, candidate_num);
+
+ // If requested event is "activate"
+ // and there are requested category and area,
+ // update area with requested role in current layout.
+ bool request_for_this_layer = false;
+ bool updated = false;
+ if ((ctg == req_ctg) && ("activate" == req_evt) ) {
+ HMI_DEBUG("wm:pm", "requested event is activate");
+ for (AreaState &as : crr_layout_state.area_list) {
+ if (as.category == req_ctg) {
+ request_for_this_layer = true;
+
+ if (as.name == req_area) {
+ HMI_DEBUG("wm:pm", "Update current layout: area:%s category:%s role:%s",
+ as.name.c_str(), as.category.c_str(), as.role.c_str());
+ as.role = req_role;
+ blank_num--;
+ updated = true;
+ break;
+ }
+ }
+ }
+
+ // If NOT updated: there is not requested area in new layout,
+ // so push requested role to candidate list
+ if (request_for_this_layer && (!updated)) {
+ HMI_DEBUG("wm:pm", "Push request to candidate list");
+ AreaState area_state;
+ area_state.name = req_area;
+ area_state.category = req_ctg;
+ area_state.role = req_role;
+ tmp_cand_list.push_back(area_state);
+ }
+ }
+
+ // Compare number of candidate/blank,
+ // And remove role in order of the oldest as necessary
+ if (candidate_num < blank_num) {
+ // Refer history stack
+ // and add to the top of tmp_cand_list in order to the newest
+ while (candidate_num != blank_num) {
+ AreaState area_state;
+ area_state.name = "";
+ area_state.category = ctg;
+ if (0 != crr_layout_state.role_history[ctg].size()) {
+ HMI_DEBUG("wm:pm", "Use role in history stack:%s",
+ crr_layout_state.role_history[ctg].back().c_str());
+ area_state.role = crr_layout_state.role_history[ctg].back();
+ crr_layout_state.role_history[ctg].pop_back();
+ }
+ else {
+ HMI_ERROR("wm:pm", "There is no role in history stack!!");
+ area_state.role = "";
+ }
+ tmp_cand_list.push_back(area_state);
+ candidate_num++;
+ }
+ }
+ else if (candidate_num > blank_num) {
+ HMI_DEBUG("wm:pm", "candidate_num > blank_num");
+
+ // Remove the oldest role from candidate list
+ while (candidate_num != blank_num) {
+ std::string removed_role = tmp_cand_list.begin()->role;
+ HMI_DEBUG("wm:pm", "Remove the oldest data(role:%s) from tmp_cand_list",
+ removed_role.c_str());
+ tmp_cand_list.erase(tmp_cand_list.begin());
+ candidate_num--;
+
+ // Push removed data to history stack
+ crr_layout_state.role_history[ctg].push_back(removed_role);
+ }
+ }
+ else { // (candidate_num == blank_num)
+ // nop
+ }
+
+ cand_list[ctg] = tmp_cand_list;
+ }
+
+ // Update areas
+ for (AreaState &as : crr_layout_state.area_list) {
+ HMI_DEBUG("wm:pm", "Current area info area:%s category:%s",
+ as.name.c_str(), as.category.c_str());
+ if ("" == as.role) {
+ HMI_DEBUG("wm:pm", "Update this area with role:%s",
+ cand_list[as.category].begin()->role.c_str());
+ as.role = cand_list[as.category].begin()->role;
+ cand_list[as.category].erase(cand_list[as.category].begin());
+ }
+ }
+ }
+ // Update current layout of this layer
+ this->crr_layers[layer_name].layout_state = crr_layout_state;