namespace pm {
+typedef std::unordered_map<std::string, std::string> AppAttribute;
+typedef std::unordered_map<std::string, AppAttribute> AreasState;
+typedef std::unordered_map<std::string, AreasState> LayoutState;
+typedef std::unordered_map<std::string, LayoutState> LayersState;
+
struct sd_event* event_loop;
std::map<int, struct sd_event_source*> event_source_list;
PolicyManager::CallbackTable callback;
+LayersState g_prv_layers;
+LayersState g_crr_layers;
} // namespace pm
return ret;
}
+ // Initialize current/previous state of layers
+ pm::AppAttribute init_app;
+ pm::AreasState init_area;
+ pm::LayoutState init_layout;
+ init_app["role"] = "none";
+ init_area["none"] = init_app;
+ init_layout["none"] = init_area;
+
+ pm::g_crr_layers["homescreen"] = init_layout;
+ pm::g_crr_layers["apps"] = init_layout;
+ pm::g_crr_layers["restriction"] = init_layout;
+ pm::g_crr_layers["on_screen"] = init_layout;
+ pm::g_prv_layers = pm::g_crr_layers;
+
// Initialize StateTransitioner
stm::stmInitialize();
crr_state.restriction_mode.state,
stm::gStmRestrictionModeStateNo2Name[crr_state.restriction_mode.state]);
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]);
+ crr_state.layer[stm::gStmLayerNoHomescreen].is_changed,
+ crr_state.layer[stm::gStmLayerNoHomescreen].state,
+ stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoHomescreen].state]);
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]);
+ crr_state.layer[stm::gStmLayerNoApps].is_changed,
+ crr_state.layer[stm::gStmLayerNoApps].state,
+ stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoApps].state]);
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]);
+ crr_state.layer[stm::gStmLayerNoRestriction].is_changed,
+ crr_state.layer[stm::gStmLayerNoRestriction].state,
+ stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoRestriction].state]);
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]);
+ crr_state.layer[stm::gStmLayerNoOnScreen].is_changed,
+ crr_state.layer[stm::gStmLayerNoOnScreen].state,
+ stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoOnScreen].state]);
+
+#if 0 // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+ // Store previous layers
+ pm::g_prv_layers = pm::g_crr_layers;
+
+ std::string layer_name = "homescreen";
+
+ // changed?
+ if (crr_state.layer[stm::gStmLayerNoHomescreen].is_changed) {
+ // Get previous layout name of this layer
+ pm::LayoutState prv_layout_state = pm::g_prv_layers[layer_name];
+ std::string prv_layout_name = prv_homescreen_layout_state.first();
+
+ // Get current layout name of this layer
+ std::string crr_layout_name = std::string(stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoHomescreen].state]);
+
+ // Compare layout name
+ pm::LayoutState crr_layout_state;
+ if ("none" == crr_layout_name) {
+ // If current layout is "none",
+ // current areas is set with "none"
+ HMI_DEBUG("wm:pm", "Current layout is \"none\"");
+ HMI_DEBUG("wm:lm", "Current layout is \"none\"");
+ pm::AppAttribute crr_app_attribute;
+ pm::AreasState crr_areas_state;
+ crr_app_attribute["role"] = "none";
+ crr_areas_state["none"] = "none";
+ crr_layout_state["none"] = crr_areas_state;
+ }
+ else {
+ if (prv_layout_name == crr_layout_name) {
+ // If previous layout is same with current,
+ // previous areas are copied to current
+ crr_layout_state[crr_layout_name] = pm::g_prv_layers[layer_name][crr_layout_name];
+ }
+ else {
+ // If previous layout is same with current,
+ // previous areas are copied to current
+ crr_layout_state[crr_layout_name] = this->default_layout_state[crr_layout_name];
+ }
+
+ // Update role in new area
+#if 1
+ if (crr_state.restriction_mode.is_changed) {
+ // Updating role is not necessary
+ // because new_role is not specified
+ // when restriction mode is changed
+ HMI_DEBUG("wm:lm", "Updating role is not necessary because new_role is not specified when restriction mode is changed");
+#else
+ if (crr_state.car.is_changed) {
+ // Updating role is not necessary
+ // because new_role is not specified
+ // when car state is changed
+ HMI_DEBUG("wm:lm", "Updating role is not necessary because new_role is not specified when car state is changed");
+#endif
+ }
+ else {
+ HMI_DEBUG("wm:lm", "Get new_area for new role");
+ // Get new_area for new role
+ std::string new_area = this->getAreaName(this->layout_define_[crr_layout_name],
+ new_role, category);
+
+ if ("none" == new_area) {
+ HMI_DEBUG("wm:lm", "It is not necessary to update role of areas in this layer, because new_role is not specified for this layer");
+ }
+ else {
+ // Is there new_area?
+ // if there is new_area, set new role there
+
+ // if NOT, find same category of new_role
+ // pop old role and shift area
+ // push new role and set area
+
+
+ // Update role in new area
+ // because new_role is specified for this layer
+ TypeRolCtg crr_role;
+ crr_role["role"] = std::string(new_role);
+ crr_layout[crr_layout_name][new_area] = crr_role;
+ }
+ }
+ }
+ }
+
+ // Update current layout of this layer
+ pm::g_crr_layers[layer_name] = crr_layout_state;
+
+ }
+#endif // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
json_object* json_out = json_object_new_object();
// }
json_tmp = json_object_new_object();
addStateToJson("homescreen",
- crr_state.layer.homescreen.is_changed,
- stm::gStmLayoutNo2Name[crr_state.layer.homescreen.state],
+ crr_state.layer[stm::gStmLayerNoHomescreen].is_changed,
+ stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoHomescreen].state],
&json_tmp);
json_object_array_add(json_layer, json_tmp);
// },
json_tmp = json_object_new_object();
addStateToJson("apps",
- crr_state.layer.apps.is_changed,
- stm::gStmLayoutNo2Name[crr_state.layer.apps.state],
+ crr_state.layer[stm::gStmLayerNoApps].is_changed,
+ stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoApps].state],
&json_tmp);
json_object_array_add(json_layer, json_tmp);
// },
json_tmp = json_object_new_object();
addStateToJson("restriction",
- crr_state.layer.restriction.is_changed,
- stm::gStmLayoutNo2Name[crr_state.layer.restriction.state],
+ crr_state.layer[stm::gStmLayerNoRestriction].is_changed,
+ stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoRestriction].state],
&json_tmp);
json_object_array_add(json_layer, json_tmp);
// },
json_tmp = json_object_new_object();
addStateToJson("on_screen",
- crr_state.layer.on_screen.is_changed,
- stm::gStmLayoutNo2Name[crr_state.layer.on_screen.state],
+ crr_state.layer[stm::gStmLayerNoOnScreen].is_changed,
+ stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoOnScreen].state],
&json_tmp);
json_object_array_add(json_layer, json_tmp);