aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuta Doi <yuta-d@witz-inc.co.jp>2018-06-11 13:32:38 +0900
committerYuta Doi <yuta-d@witz-inc.co.jp>2018-06-11 13:32:38 +0900
commit7dd08d9c507f595d3b7a786c3375ad5c67235522 (patch)
treef0715ca416b54566eb44888d91bc5f3373d28424
parent87c8fa0f0c92b61825973f44ba19686564fdd0cd (diff)
Update managing layout information
Change-Id: I57d7281afc000f4c4c22b54bedd4e61bdd91872b Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
-rw-r--r--src/policy_manager/policy_manager.cpp80
1 files changed, 62 insertions, 18 deletions
diff --git a/src/policy_manager/policy_manager.cpp b/src/policy_manager/policy_manager.cpp
index 2429cf2..0af8398 100644
--- a/src/policy_manager/policy_manager.cpp
+++ b/src/policy_manager/policy_manager.cpp
@@ -44,6 +44,7 @@ typedef struct LayoutState {
std::map<std::string, int> category_num;
// int category_num[stm::gStmCategoryNoNum];
std::vector<AreaState> area_list;
+ std::map<std::string, std::string> last_invisibled_role;
} LayoutState;
typedef struct LayerState {
@@ -247,6 +248,7 @@ static int checkPolicy(sd_event_source *source, void *data) {
std::string category = std::string(stm::gStmCategoryName[category_no]);
std::string area = std::string(stm::gStmAreaName[area_no]);
+ // Update layers
for (int layer_no = stm::gStmLayerNoMin;
layer_no <= stm::gStmLayerNoMax; layer_no++) {
const char* layer_name = stm::gStmLayerName[layer_no];
@@ -298,6 +300,7 @@ static int checkPolicy(sd_event_source *source, void *data) {
crr_layout_state = pm::g_prv_layers_car_stop[layer_name].layout_state;
#endif
}
+#if 0
else if ("none" == crr_layout_name) {
// If current layout is "none",
// current areas is set with "none"
@@ -309,18 +312,21 @@ static int checkPolicy(sd_event_source *source, void *data) {
crr_layout_state.name = "none";
crr_layout_state.area_list.push_back(crr_area_state);
}
+#endif
else {
+ // Copy previous layout state for current
+ crr_layout_state = prv_layout_state;
+
if (prv_layout_name == crr_layout_name) {
- // If previous layout is same with current,
- // previous areas are copied to current
HMI_DEBUG("wm:lm", "Previous layout is same with current");
- crr_layout_state = prv_layout_state;
}
else {
// If previous layout is NOT same with current,
// current areas is set with default value
HMI_DEBUG("wm:lm", "Previous layout is NOT same with current");
- crr_layout_state = pm::g_default_layouts[crr_layout_name];
+ crr_layout_state.name = pm::g_default_layouts[crr_layout_name].name;
+ crr_layout_state.category_num = pm::g_default_layouts[crr_layout_name].category_num;
+ crr_layout_state.area_list = pm::g_default_layouts[crr_layout_name].area_list;
}
// Update role in new area
@@ -346,10 +352,12 @@ static int checkPolicy(sd_event_source *source, void *data) {
const char* ctg = stm::gStmCategoryName[ctg_no];
HMI_DEBUG("wm:pm", "ctg:%s", ctg);
- // Create area list of previous/current app
+ // Create area list of previous app
std::vector<pm::AreaState> area_list;
for (pm::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 area list
HMI_DEBUG("wm:pm", "push area_state to prv list");
area_list.push_back(area_state);
}
@@ -359,18 +367,30 @@ static int checkPolicy(sd_event_source *source, void *data) {
int crr_ctg_num = crr_layout_state.category_num[ctg];
HMI_DEBUG("wm:pm", "crr_ctg_num:%d prv_ctg_num:%d", crr_ctg_num, prv_ctg_num);
+ // Remove state of area which is used no longer from area list
if (crr_ctg_num < prv_ctg_num) {
HMI_DEBUG("wm:pm", "crr_ctg_num < prv_ctg_num");
if (0 == strcmp(ctg, category.c_str())) {
- HMI_DEBUG("wm:pm", "category of requested role is same");
for (auto i = area_list.begin(); i != area_list.end(); ++i) {
if ((role == i->role) && (area == i->name)) {
- HMI_DEBUG("wm:pm", "remove requested role data");
+ HMI_DEBUG("wm:pm", "store removed role:%s", i->role.c_str());
+ crr_layout_state.last_invisibled_role[category] = i->role;
+
+ HMI_DEBUG("wm:pm", "remove area state which have same role with requested role");
area_list.erase(i);
+
+ prv_ctg_num--;
+
+ if (crr_ctg_num == prv_ctg_num) {
+ break;
+ }
}
}
}
else {
+ HMI_DEBUG("wm:pm", "store removed role:%s", area_list.begin()->role.c_str());
+ crr_layout_state.last_invisibled_role[ctg] = area_list.begin()->role;
+
HMI_DEBUG("wm:pm", "remove the oldest area data");
area_list.erase(area_list.begin());
}
@@ -380,6 +400,9 @@ static int checkPolicy(sd_event_source *source, void *data) {
if (0 == strcmp(ctg, category.c_str())) {
HMI_DEBUG("wm:pm", "category of requested role is same");
if ((crr_ctg_num == prv_ctg_num) && (0 != prv_ctg_num)) {
+ HMI_DEBUG("wm:pm", "store removed role:%s", area_list.begin()->role.c_str());
+ crr_layout_state.last_invisibled_role[ctg] = area_list.begin()->role;
+
HMI_DEBUG("wm:pm", "remove the oldest area data for adding requested role");
area_list.erase(area_list.begin());
}
@@ -387,7 +410,7 @@ static int checkPolicy(sd_event_source *source, void *data) {
}
// Check
- for (pm::AreaState area_state : prv_layout_state.area_list) {
+ for (pm::AreaState area_state : area_list) {
HMI_DEBUG("wm:pm", "area_list name:%s category:%s role:%s",
area_state.name.c_str(),
area_state.category.c_str(),
@@ -398,19 +421,26 @@ static int checkPolicy(sd_event_source *source, void *data) {
}
if (event == "activate") {
+ HMI_DEBUG("wm:pm", "event is activate");
// First, update area for requested role
+ bool request_for_this_layer = false;
bool updated = false;
for (pm::AreaState &as : crr_layout_state.area_list) {
- if ((as.category == category) && (as.name == area)) {
- as.role = role;
- updated = true;
- break;
+ if (as.category == category) {
+ request_for_this_layer = true;
+ if (as.name == area) {
+ HMI_DEBUG("wm:pm", "update area for requested category:%s role:%s area:%s", category.c_str(), role.c_str(), area.c_str());
+ as.role = role;
+ updated = true;
+ break;
+ }
}
}
// If NOT updated: there is not requested area in new layout,
// requested role is used later.
- if (!updated) {
+ if (request_for_this_layer && (!updated)) {
+ HMI_DEBUG("wm:pm", "requested role is used later category:%s role:%s area:%s", category.c_str(), role.c_str(), area.c_str());
pm::AreaState area_state;
area_state.name = area;
area_state.category = category;
@@ -421,11 +451,19 @@ static int checkPolicy(sd_event_source *source, void *data) {
// Update areas
for (pm::AreaState &as : crr_layout_state.area_list) {
-
- // This conditional expression is useful in only activate
- if (as.role != role) {
- as.role = ctg_list[as.category].begin()->role;
- ctg_list[as.category].erase(ctg_list[as.category].begin());
+ if (as.role != role) { // This conditional expression is useful in only when requested activate event
+ HMI_DEBUG("wm:pm", "update areas for category:%s", as.category.c_str());
+ if (0 != ctg_list[as.category].size()) {
+ HMI_DEBUG("wm:pm", "update role to %s by using area list this category",
+ ctg_list[as.category].begin()->role);
+ as.role = ctg_list[as.category].begin()->role;
+ ctg_list[as.category].erase(ctg_list[as.category].begin());
+ }
+ else {
+ HMI_DEBUG("wm:pm", "there is no area list for this category, so update area by last invisibled role:", crr_layout_state.last_invisibled_role[as.category]);
+ as.role = crr_layout_state.last_invisibled_role[as.category];
+ crr_layout_state.last_invisibled_role.erase(as.category);
+ }
}
}
}
@@ -928,6 +966,12 @@ int PolicyManager::loadLayoutDb() {
pm::g_default_layouts[layout] = layout_state;
}
+ // initialize for none layout
+ pm::LayoutState none_layout_state;
+ memset(&none_layout_state, 0, sizeof(none_layout_state));
+ none_layout_state.name = "none";
+ pm::g_default_layouts["none"] = none_layout_state;
+
// Check
for(auto itr_layout = pm::g_default_layouts.begin();
itr_layout != pm::g_default_layouts.end(); ++itr_layout) {