-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("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("afm_app_install_dir:%s", afm_app_install_dir);
-
- string file_name;
- if (!afm_app_install_dir)
- {
- HMI_ERROR("AFM_APP_INSTALL_DIR is not defined");
- }
- else
- {
- file_name = string(afm_app_install_dir) + string("/etc/old_roles.json");
- }
-
- // Load old_role.db
- json_object* json_obj;
- int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj);
- if (0 > ret)
- {
- HMI_ERROR("Could not open old_role.db, so use default old_role information");
- json_obj = json_tokener_parse(kDefaultOldRoleDb);
- }
- HMI_DEBUG("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("Parse Error!!");
- return -1;
- }
-
- int len = json_object_array_length(json_cfg);
- HMI_DEBUG("json_cfg len:%d", len);
- HMI_DEBUG("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("Parse Error!!");
- return -1;
- }
-
- const char* new_role = jh::getStringFromJson(json_tmp, "new");
- if (nullptr == new_role)
- {
- HMI_ERROR("Parse Error!!");
- return -1;
- }
-
- this->roleold2new[old_role] = string(new_role);
- }
-
- // Check
- for(auto itr = this->roleold2new.begin();
- itr != this->roleold2new.end(); ++itr)
- {
- HMI_DEBUG(">>> 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::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\" \
- } \
- ] \
-}";
-