-const char* WindowManager::convertRoleOldToNew(char const *old_role)
-{
- const char *new_role = nullptr;
-
- for (auto const &on : this->roleold2new)
- {
- std::regex regex = std::regex(on.first);
- if (std::regex_match(old_role, regex))
- {
- // role is old. So convert to new.
- new_role = on.second.c_str();
- break;
- }
- }
-
- if (nullptr == new_role)
- {
- // role is new or fallback.
- new_role = old_role;
- }
-
- HMI_DEBUG("wm", "old:%s -> new:%s", old_role, new_role);
-
- return new_role;
-}
-
-int WindowManager::loadOldRoleDb()
-{
- // Get afm application installed dir
- char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR");
- HMI_DEBUG("wm", "afm_app_install_dir:%s", afm_app_install_dir);
-
- std::string file_name;
- if (!afm_app_install_dir)
- {
- HMI_ERROR("wm", "AFM_APP_INSTALL_DIR is not defined");
- }
- else
- {
- file_name = std::string(afm_app_install_dir) + std::string("/etc/old_roles.db");
- }
-
- // Load old_role.db
- json_object* json_obj;
- int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj);
- if (0 > ret)
- {
- HMI_ERROR("wm", "Could not open old_role.db, so use default old_role information");
- json_obj = json_tokener_parse(kDefaultOldRoleDb);
- }
- HMI_DEBUG("wm", "json_obj dump:%s", json_object_get_string(json_obj));
-
- // Perse apps
- json_object* json_cfg;
- if (!json_object_object_get_ex(json_obj, "old_roles", &json_cfg))
- {
- HMI_ERROR("wm", "Parse Error!!");
- return -1;
- }
-
- int len = json_object_array_length(json_cfg);
- HMI_DEBUG("wm", "json_cfg len:%d", len);
- HMI_DEBUG("wm", "json_cfg dump:%s", json_object_get_string(json_cfg));
-
- for (int i=0; i<len; i++)
- {
- json_object* json_tmp = json_object_array_get_idx(json_cfg, i);
-
- const char* old_role = jh::getStringFromJson(json_tmp, "name");
- if (nullptr == old_role)
- {
- HMI_ERROR("wm", "Parse Error!!");
- return -1;
- }
-
- const char* new_role = jh::getStringFromJson(json_tmp, "new");
- if (nullptr == new_role)
- {
- HMI_ERROR("wm", "Parse Error!!");
- return -1;
- }
-
- this->roleold2new[old_role] = std::string(new_role);
- }
-
- // Check
- for(auto itr = this->roleold2new.begin();
- itr != this->roleold2new.end(); ++itr)
- {
- HMI_DEBUG("wm", ">>> role old:%s new:%s",
- itr->first.c_str(), itr->second.c_str());
- }
-
- // Release json_object
- json_object_put(json_obj);
-
- return 0;
-}
-
-const char *WindowManager::check_surface_exist(const char *drawing_name)
-{
- auto const &surface_id = this->lookup_id(drawing_name);
- if (!surface_id)
- {
- return "Surface does not exist";
- }
-
- if (!this->controller->surface_exists(*surface_id))
- {
- return "Surface does not exist in controller!";
- }
-
- auto layer_id = this->layers.get_layer_id(*surface_id);
-
- if (!layer_id)
- {
- return "Surface is not on any layer!";
- }
-
- auto o_state = *this->layers.get_layout_state(*surface_id);
-
- if (o_state == nullptr)
- {
- return "Could not find layer for surface";
- }
-
- HMI_DEBUG("wm", "surface %d is detected", *surface_id);
- return nullptr;
-}
-
-bool WindowManager::can_split(struct LayoutState const &state, int new_id)
-{
- if (state.main != -1 && state.main != new_id)
- {
- auto new_id_layer = this->layers.get_layer_id(new_id).value();
- auto current_id_layer = this->layers.get_layer_id(state.main).value();
-
- // surfaces are on separate layers, don't bother.
- if (new_id_layer != current_id_layer)
- {
- return false;
- }
-
- std::string const &new_id_str = this->lookup_name(new_id).value();
- std::string const &cur_id_str = this->lookup_name(state.main).value();
-
- auto const &layer = this->layers.get_layer(new_id_layer);
-
- HMI_DEBUG("wm", "layer info name: %s", layer->name.c_str());
-
- if (layer->layouts.empty())
- {
- return false;
- }
-
- for (auto i = layer->layouts.cbegin(); i != layer->layouts.cend(); i++)
- {
- HMI_DEBUG("wm", "%d main_match '%s'", new_id_layer, i->main_match.c_str());
- auto rem = std::regex(i->main_match);
- if (std::regex_match(cur_id_str, rem))
- {
- // build the second one only if the first already matched
- HMI_DEBUG("wm", "%d sub_match '%s'", new_id_layer, i->sub_match.c_str());
- auto res = std::regex(i->sub_match);
- if (std::regex_match(new_id_str, res))
- {
- HMI_DEBUG("wm", "layout matched!");
- return true;
- }
- }
- }
- }
-
- return false;
-}
-
-const char* WindowManager::kDefaultOldRoleDb = "{ \
- \"old_roles\": [ \
- { \
- \"name\": \"HomeScreen\", \
- \"new\": \"homescreen\" \
- }, \
- { \
- \"name\": \"Music\", \
- \"new\": \"music\" \
- }, \
- { \
- \"name\": \"MediaPlayer\", \
- \"new\": \"music\" \
- }, \
- { \
- \"name\": \"Video\", \
- \"new\": \"video\" \
- }, \
- { \
- \"name\": \"VideoPlayer\", \
- \"new\": \"video\" \
- }, \
- { \
- \"name\": \"WebBrowser\", \
- \"new\": \"browser\" \
- }, \
- { \
- \"name\": \"Radio\", \
- \"new\": \"radio\" \
- }, \
- { \
- \"name\": \"Phone\", \
- \"new\": \"phone\" \
- }, \
- { \
- \"name\": \"Navigation\", \
- \"new\": \"map\" \
- }, \
- { \
- \"name\": \"HVAC\", \
- \"new\": \"hvac\" \
- }, \
- { \
- \"name\": \"Settings\", \
- \"new\": \"settings\" \
- }, \
- { \
- \"name\": \"Dashboard\", \
- \"new\": \"dashboard\" \
- }, \
- { \
- \"name\": \"POI\", \
- \"new\": \"poi\" \
- }, \
- { \
- \"name\": \"Mixer\", \
- \"new\": \"mixer\" \
- }, \
- { \
- \"name\": \"Restriction\", \
- \"new\": \"restriction\" \
- }, \
- { \
- \"name\": \"^OnScreen.*\", \
- \"new\": \"on_screen\" \
- } \
- ] \
-}";
-
-/**
- * controller_hooks
- */
-void controller_hooks::surface_created(uint32_t surface_id)
-{
- this->app->surface_created(surface_id);
-}
-
-void controller_hooks::surface_removed(uint32_t surface_id)
-{
- this->app->surface_removed(surface_id);
-}
-
-void controller_hooks::surface_visibility(uint32_t /*surface_id*/,
- uint32_t /*v*/) {}
-
-void controller_hooks::surface_destination_rectangle(uint32_t /*surface_id*/,
- uint32_t /*x*/,
- uint32_t /*y*/,
- uint32_t /*w*/,
- uint32_t /*h*/) {}
-