-bool LayoutManager::updateLayout(json_object* obj,
- const char* new_role, const char* category) {
- HMI_DEBUG("wm:lm", "Call");
-
- bool ret = false;
-
- // Check car state change
- json_object* json_car;
- if (!json_object_object_get_ex(obj, "car", &json_car)) {
- HMI_ERROR("wm:lm", "Parse Error!!");
- return -1;
- }
-
- json_bool is_car_state_changed;
- std::string car_state = "";
- is_car_state_changed = jh::getBoolFromJson(json_car, "is_changed");
- if (is_car_state_changed) {
- // If car state is changed, get car state
- car_state = jh::getStringFromJson(json_car, "state");
- }
-
- // Update layout of all layers
- json_object* json_layers;
- if (!json_object_object_get_ex(obj, "layers", &json_layers)) {
- HMI_ERROR("wm:lm", "Parse Error!!");
- return -1;
- }
-
- int len = json_object_array_length(json_layers);
- HMI_DEBUG("wm:lm", "json_layers len:%d", len);
- HMI_DEBUG("wm:lm", "json_layers dump:%s", json_object_get_string(json_layers));
-
- for (int i=0; i<len; i++) {
- json_object* json_tmp = json_object_array_get_idx(json_layers, i);
-
- // Get layer name and json_object
- const char* layer;
- json_object* json_layer;
- json_object_object_foreach(json_tmp, key, val) {
- layer = key;
- json_layer = val;
- HMI_DEBUG("wm:lm", "Update %s layer state", layer);
- }
-
- // Store previous state
- this->prv_layers_[layer] = this->crr_layers_[layer];
- std::string prv_layout_name = this->prv_layers_[layer].begin()->first;
-
- // If car state is changed car_stop -> car_run,
- // store current state for state of car stop
- if ((is_car_state_changed) && ("car_run" == car_state)) {
- HMI_DEBUG("wm:lm", "Store current state for state of car stop");
- this->prv_layers_car_stop_[layer] = this->crr_layers_[layer];
- }
-
- json_object* json_is_changed;
- if (!json_object_object_get_ex(json_layer, "is_changed", &json_is_changed)) {
- HMI_ERROR("wm:lm", "Not found key \"is_changed\"");
- return false;
- }
-
- // If layer state is changed
- if (json_object_get_boolean(json_is_changed)) {
- // Set layout changed flag
- this->is_layout_changed_[layer] = true;
-
- json_object* json_state;
- if (!json_object_object_get_ex(json_layer, "state", &json_state)) {
- HMI_ERROR("wm:lm", "Not found key \"state\"");
- return false;
- }
-
- const char* crr_layout_name = json_object_get_string(json_state);
- HMI_DEBUG("wm:lm", "crr state: %s", crr_layout_name);
-
- TypeLayouts crr_layout;
- if ((is_car_state_changed) && ("car_stop" == car_state)) {
- // If car state is changed car_run -> car_stop,
- // restore state of car stop
- HMI_DEBUG("wm:lm", "Restore state of car stop");
- crr_layout = this->prv_layers_car_stop_[layer];
- }
- else if ("none" == std::string(crr_layout_name)) {
- // If current layout is "none",
- // current areas is set with "none"
- TypeAreas area;
- TypeRolCtg rol_ctg;
- rol_ctg["none"] = "none";
- area["none"] = rol_ctg;
- crr_layout["none"] = area;
- }
- else {
- if (std::string(crr_layout_name) == prv_layout_name) {
- // If previous layout is same with current,
- // previous areas are copied to current
- crr_layout[crr_layout_name] = this->prv_layers_[layer][crr_layout_name];
- }
- else {
- // If previous layout is NOT same with current,
- // current areas is set with default value
- crr_layout[crr_layout_name] = this->layout_define_[crr_layout_name];
- }
-
- if (is_car_state_changed) {
- // Updating role is not necessary
- // because new_role is not specified when car state is changed
- }
- else {
- // Get new_area for new role
- std::string new_area = this->getAreaName(this->layout_define_[crr_layout_name],
- new_role, category);
-
- // Update role in new area
- TypeRolCtg crr_role;
- crr_role["role"] = std::string(new_role);
- crr_layout[crr_layout_name][new_area] = crr_role;
- }
- }
-
- // Update layer state
- this->crr_layers_[layer] = crr_layout;
-
- // Check
- for (auto itr_layout = this->crr_layers_[layer].begin();
- itr_layout != this->crr_layers_[layer].end(); ++itr_layout) {
- for (auto itr_area = itr_layout->second.begin();
- itr_area != itr_layout->second.end(); ++itr_area) {
- for (auto itr_role = itr_area->second.begin();
- itr_role != itr_area->second.end(); ++itr_role) {
- HMI_DEBUG("wm:lm", "layout:%s, area:%s, rol_ctg:%s, name:%s",
- itr_layout->first.c_str(), itr_area->first.c_str(),
- itr_role->first.c_str(), itr_role->second.c_str());
- }
- }
- }
-
- ret = true;
- }
- else {
- // Clear layout changed flag
- this->is_layout_changed_[layer] = false;
- }
- }
- return ret;
-}
-
-// TODO: This API is for workaround, so this will be removed
-void LayoutManager::updateArea(const char* layer, const char* role, const char* area) {
- this->crr_layers_[layer].begin()->second[area]["role"] = std::string(role);
-}
-
-LayoutManager::TypeLayers LayoutManager::getCurrentLayers() {
- return this->crr_layers_;
-}
-
-LayoutManager::TypeLayers LayoutManager::getPreviousLayers() {
- return this->prv_layers_;
-}
-