2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "window_manager.hpp"
21 #include "json_helper.hpp"
22 #include "applist.hpp"
26 #include <systemd/sd-event.h>
35 static const uint64_t kTimeOut = 3ULL; /* 3s */
37 /* DrawingArea name used by "{layout}.{area}" */
38 const char kNameLayoutNormal[] = "normal";
39 const char kNameLayoutSplit[] = "split";
40 const char kNameAreaFull[] = "full";
41 const char kNameAreaMain[] = "main";
42 const char kNameAreaSub[] = "sub";
44 /* Key for json obejct */
45 const char kKeyDrawingName[] = "drawing_name";
46 const char kKeyDrawingArea[] = "drawing_area";
47 const char kKeyDrawingRect[] = "drawing_rect";
48 const char kKeyX[] = "x";
49 const char kKeyY[] = "y";
50 const char kKeyWidth[] = "width";
51 const char kKeyHeight[] = "height";
52 const char kKeyWidthPixel[] = "width_pixel";
53 const char kKeyHeightPixel[] = "height_pixel";
54 const char kKeyWidthMm[] = "width_mm";
55 const char kKeyHeightMm[] = "height_mm";
56 const char kKeyScale[] = "scale";
57 const char kKeyIds[] = "ids";
59 static const vector<string> kListEventName{
69 static sd_event_source *g_timer_ev_src = nullptr;
70 static AppList g_app_list;
71 static WindowManager *g_context;
76 static int processTimerHandler(sd_event_source *s, uint64_t usec, void *userdata)
78 HMI_NOTICE("Time out occurs because the client replys endDraw slow, so revert the request");
79 reinterpret_cast<wm::WindowManager *>(userdata)->timerHandler();
83 static void onStateTransitioned(vector<WMAction> actions)
85 g_context->startTransitionWrapper(actions);
90 g_context->processError(WMError::LAYOUT_CHANGE_FAIL);
97 WindowManager::WindowManager()
100 const char *path = getenv("AFM_APP_INSTALL_DIR");
103 HMI_ERROR("AFM_APP_INSTALL_DIR is not defined");
107 this->lc = std::make_shared<LayerControl>(root);
109 HMI_DEBUG("Layer Controller initialized");
112 int WindowManager::init()
114 LayerControlCallbacks lmcb;
115 lmcb.surfaceCreated = [&](unsigned pid, unsigned surface){
116 this->surface_created(surface);
118 lmcb.surfaceDestroyed = [&](unsigned surface){
119 this->surface_removed(surface);
122 if(this->lc->init(lmcb) != WMError::SUCCESS)
127 // TODO: application requests by old role,
128 // so create role map (old, new)
130 this->loadOldRoleDb();
132 // Store my context for calling callback from PolicyManager
135 // Initialize PMWrapper
136 this->pmw.initialize();
138 // Register callback to PolicyManager
139 this->pmw.registerCallback(onStateTransitioned, onError);
142 for (int i = Event_Val_Min; i <= Event_Val_Max; i++)
144 map_afb_event[kListEventName[i]] = afb_daemon_make_event(kListEventName[i].c_str());
147 const struct rect css_bg = this->lc->getAreaSize("fullscreen");
148 Screen screen = this->lc->getScreenInfo();
149 rectangle dp_bg(screen.width(), screen.height());
151 dp_bg.set_aspect(static_cast<double>(css_bg.w) / css_bg.h);
152 dp_bg.fit(screen.width(), screen.height());
153 dp_bg.center(screen.width(), screen.height());
154 HMI_DEBUG("SCALING: CSS BG(%dx%d) -> DDP %dx%d,(%dx%d)",
155 css_bg.w, css_bg.h, dp_bg.left(), dp_bg.top(), dp_bg.width(), dp_bg.height());
157 double scale = static_cast<double>(dp_bg.height()) / css_bg.h;
158 this->lc->setupArea(dp_bg, scale);
160 this->lc->createLayers();
165 result<int> WindowManager::api_request_surface(char const *appid, char const *drawing_name)
167 // TODO: application requests by old role,
168 // so convert role old to new
169 const char *role = this->convertRoleOldToNew(drawing_name);
171 // auto lid = this->layers.get_layer_id(string(role));
172 unsigned lid = this->lc->getLayerID(string(role));
176 * register drawing_name as fallback and make it displayed.
178 // lid = this->layers.get_layer_id(string("fallback"));
179 lid = this->lc->getLayerID(string("fallback"));
180 HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role);
183 return Err<int>("Drawing name does not match any role, fallback is disabled");
187 auto rname = this->id_alloc.lookup(role);
190 // name does not exist yet, allocate surface id...
191 auto id = int(this->id_alloc.generate_id(role));
192 // this->layers.add_surface(id, *lid);
193 this->tmp_surface2app[id] = {string(appid), lid};
195 // add client into the db
196 string appid_str(appid);
197 g_app_list.addClient(appid_str, lid, id, string(role));
199 // Set role map of (new, old)
200 this->rolenew2old[role] = string(drawing_name);
205 // Check currently registered drawing names if it is already there.
206 return Err<int>("Surface already present");
209 char const *WindowManager::api_request_surface(char const *appid, char const *drawing_name,
212 // TODO: application requests by old role,
213 // so convert role old to new
214 const char *role = this->convertRoleOldToNew(drawing_name);
216 unsigned sid = std::stol(ivi_id);
217 WMError ret = this->lc->setXDGSurfaceOriginSize(sid);
220 HMI_ERROR("%s", errorDescription(ret));
221 HMI_WARNING("The main user of this API is runXDG");
225 // auto lid = this->layers.get_layer_id(string(role));
226 auto lid = this->lc->getLayerID(string(role));
230 * register drawing_name as fallback and make it displayed.
232 lid = this->lc->getLayerID(string("fallback"));
233 HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role);
236 return "Drawing name does not match any role, fallback is disabled";
240 auto rname = this->id_alloc.lookup(role);
244 return "Surface already present";
247 // register pair drawing_name and ivi_id
248 this->id_alloc.register_name_id(role, sid);
249 this->lc->addSurface(sid, lid);
251 HMI_DEBUG("surface_id is %u, layer_id is %u", sid, lid);
253 // add client into the list
254 string appid_str(appid);
255 g_app_list.addClient(appid_str, lid, sid, string(role));
257 // Set role map of (new, old)
258 this->rolenew2old[role] = string(drawing_name);
263 void WindowManager::api_activate_window(char const *appid, char const *drawing_name,
264 char const *drawing_area, const reply_func &reply)
266 // TODO: application requests by old role,
267 // so convert role old to new
268 const char *c_role = this->convertRoleOldToNew(drawing_name);
271 string role = c_role;
272 string area = drawing_area;
274 if(!g_app_list.contains(id))
276 reply("app doesn't request 'requestSurface' or 'setRole' yet");
280 auto client = g_app_list.lookUpClient(id);
281 Task task = Task::TASK_ALLOCATE;
282 unsigned req_num = 0;
283 WMError ret = WMError::UNKNOWN;
285 ret = this->setRequest(id, role, area, task, &req_num);
287 if(ret != WMError::SUCCESS)
289 HMI_ERROR(errorDescription(ret));
290 reply("Failed to set request");
295 if (req_num != g_app_list.currentRequestNumber())
297 // Add request, then invoked after the previous task is finished
298 HMI_SEQ_DEBUG(req_num, "request is accepted");
305 ret = this->checkPolicy(req_num);
307 if (ret != WMError::SUCCESS)
310 HMI_SEQ_ERROR(req_num, errorDescription(ret));
311 g_app_list.removeRequest(req_num);
312 this->processNextRequest();
316 void WindowManager::api_deactivate_window(char const *appid, char const *drawing_name,
317 const reply_func &reply)
319 // TODO: application requests by old role,
320 // so convert role old to new
321 const char *c_role = this->convertRoleOldToNew(drawing_name);
327 string role = c_role;
328 string area = ""; //drawing_area;
329 Task task = Task::TASK_RELEASE;
330 unsigned req_num = 0;
331 WMError ret = WMError::UNKNOWN;
333 ret = this->setRequest(id, role, area, task, &req_num);
335 if (ret != WMError::SUCCESS)
337 HMI_ERROR(errorDescription(ret));
338 reply("Failed to set request");
343 if (req_num != g_app_list.currentRequestNumber())
345 // Add request, then invoked after the previous task is finished
346 HMI_SEQ_DEBUG(req_num, "request is accepted");
353 ret = this->checkPolicy(req_num);
355 if (ret != WMError::SUCCESS)
358 HMI_SEQ_ERROR(req_num, errorDescription(ret));
359 g_app_list.removeRequest(req_num);
360 this->processNextRequest();
364 void WindowManager::api_enddraw(char const *appid, char const *drawing_name)
366 // TODO: application requests by old role,
367 // so convert role old to new
368 const char *c_role = this->convertRoleOldToNew(drawing_name);
371 string role = c_role;
372 unsigned current_req = g_app_list.currentRequestNumber();
373 bool result = g_app_list.setEndDrawFinished(current_req, id, role);
377 HMI_ERROR("%s is not in transition state", id.c_str());
381 if (g_app_list.endDrawFullfilled(current_req))
383 // do task for endDraw
385 WMError ret = this->doEndDraw(current_req);
387 if(ret != WMError::SUCCESS)
389 //this->emit_error();
391 // Undo state of PolicyManager
392 this->pmw.undoState();
394 this->emitScreenUpdated(current_req);
395 HMI_SEQ_INFO(current_req, "Finish request status: %s", errorDescription(ret));
397 g_app_list.removeRequest(current_req);
399 this->processNextRequest();
403 HMI_SEQ_INFO(current_req, "Wait other App call endDraw");
408 int WindowManager::api_subscribe(afb_req req, int event_id)
410 struct afb_event event = this->map_afb_event[kListEventName[event_id]];
411 return afb_req_subscribe(req, event);
414 result<json_object *> WindowManager::api_get_display_info()
416 Screen screen = this->lc->getScreenInfo();
418 json_object *object = json_object_new_object();
419 json_object_object_add(object, kKeyWidthPixel, json_object_new_int(screen.width()));
420 json_object_object_add(object, kKeyHeightPixel, json_object_new_int(screen.height()));
422 json_object_object_add(object, kKeyWidthMm, json_object_new_int(0));
423 json_object_object_add(object, kKeyHeightMm, json_object_new_int(0));
424 json_object_object_add(object, kKeyScale, json_object_new_double(this->lc->scale()));
426 return Ok<json_object *>(object);
429 result<json_object *> WindowManager::api_get_area_info(char const *drawing_name)
433 // TODO: application requests by old role,
434 // so convert role old to new
435 const char *role = this->convertRoleOldToNew(drawing_name);
437 // Check drawing name, surface/layer id
438 auto const &surface_id = this->id_alloc.lookup(role);
441 return Err<json_object *>("Surface does not exist");
444 // Set area rectangle
445 struct rect area_info = this->area_info[*surface_id];
446 json_object *object = json_object_new_object();
447 json_object_object_add(object, kKeyX, json_object_new_int(area_info.x));
448 json_object_object_add(object, kKeyY, json_object_new_int(area_info.y));
449 json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w));
450 json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h));
452 return Ok<json_object *>(object);
455 void WindowManager::send_event(const string& evname, const string& role)
457 json_object *j = json_object_new_object();
458 json_object_object_add(j, kKeyDrawingName, json_object_new_string(role.c_str()));
460 int ret = afb_event_push(this->map_afb_event[evname], j);
463 HMI_DEBUG("afb_event_push failed: %m");
467 void WindowManager::send_event(const string& evname, const string& role, const string& area,
468 int x, int y, int w, int h)
470 json_object *j_rect = json_object_new_object();
471 json_object_object_add(j_rect, kKeyX, json_object_new_int(x));
472 json_object_object_add(j_rect, kKeyY, json_object_new_int(y));
473 json_object_object_add(j_rect, kKeyWidth, json_object_new_int(w));
474 json_object_object_add(j_rect, kKeyHeight, json_object_new_int(h));
476 json_object *j = json_object_new_object();
477 json_object_object_add(j, kKeyDrawingName, json_object_new_string(role.c_str()));
478 json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area.c_str()));
479 json_object_object_add(j, kKeyDrawingRect, j_rect);
481 int ret = afb_event_push(this->map_afb_event[evname], j);
484 HMI_DEBUG("afb_event_push failed: %m");
491 void WindowManager::surface_created(unsigned surface_id)
494 if(this->tmp_surface2app.count(surface_id) != 0)
496 unsigned layer_id = this->tmp_surface2app[surface_id].layer;
497 this->lc->addSurface(surface_id, layer_id);
498 this->tmp_surface2app.erase(surface_id);
499 HMI_DEBUG("surface_id is %u, layer_id is %u", surface_id, layer_id);
503 void WindowManager::surface_removed(unsigned surface_id)
505 HMI_DEBUG("Delete surface_id %u", surface_id);
506 this->id_alloc.remove_id(surface_id);
507 g_app_list.removeSurface(surface_id);
510 void WindowManager::removeClient(const string &appid)
512 HMI_DEBUG("Remove clinet %s from list", appid.c_str());
513 g_app_list.removeClient(appid);
516 void WindowManager::exceptionProcessForTransition()
518 unsigned req_num = g_app_list.currentRequestNumber();
519 HMI_SEQ_NOTICE(req_num, "Process exception handling for request. Remove current request %d", req_num);
520 g_app_list.removeRequest(req_num);
521 HMI_SEQ_NOTICE(g_app_list.currentRequestNumber(), "Process next request if exists");
522 this->processNextRequest();
525 void WindowManager::timerHandler()
527 unsigned req_num = g_app_list.currentRequestNumber();
528 HMI_SEQ_DEBUG(req_num, "Timer expired remove Request");
529 g_app_list.reqDump();
530 g_app_list.removeRequest(req_num);
531 this->processNextRequest();
534 void WindowManager::startTransitionWrapper(vector<WMAction> &actions)
537 unsigned req_num = g_app_list.currentRequestNumber();
541 if (g_app_list.haveRequest())
543 HMI_SEQ_DEBUG(req_num, "There is no WMAction for this request");
544 goto proc_remove_request;
548 HMI_SEQ_DEBUG(req_num, "There is no request");
553 for (auto &act : actions)
558 auto const &surface_id = this->id_alloc.lookup(act.role.c_str());
559 if(surface_id == nullopt)
561 goto proc_remove_request;
563 string appid = g_app_list.getAppID(*surface_id, act.role, &found);
566 if (TaskVisible::INVISIBLE == act.visible)
568 // App is killed, so do not set this action
573 HMI_SEQ_ERROR(req_num, "appid which is visible is not found");
578 auto client = g_app_list.lookUpClient(appid);
579 act.req_num = req_num;
583 ret = g_app_list.setAction(req_num, act);
584 if (ret != WMError::SUCCESS)
586 HMI_SEQ_ERROR(req_num, "Setting action is failed");
591 HMI_SEQ_DEBUG(req_num, "Start transition.");
592 ret = this->startTransition(req_num);
593 if (ret != WMError::SUCCESS)
595 if (ret == WMError::NO_LAYOUT_CHANGE)
597 goto proc_remove_request;
601 HMI_SEQ_ERROR(req_num, "Transition state is failed");
610 HMI_SEQ_ERROR(req_num, errorDescription(ret));
611 this->pmw.undoState();
614 g_app_list.removeRequest(req_num);
615 this->processNextRequest();
618 void WindowManager::processError(WMError error)
620 unsigned req_num = g_app_list.currentRequestNumber();
623 HMI_SEQ_ERROR(req_num, errorDescription(error));
624 g_app_list.removeRequest(req_num);
625 this->processNextRequest();
629 ******* Private Functions *******
632 void WindowManager::emit_activated(const string& role)
634 this->send_event(kListEventName[Event_Active], role);
637 void WindowManager::emit_deactivated(const string& role)
639 this->send_event(kListEventName[Event_Inactive], role);
642 void WindowManager::emit_syncdraw(const string& role, char const *area, int x, int y, int w, int h)
644 this->send_event(kListEventName[Event_SyncDraw], role, area, x, y, w, h);
647 void WindowManager::emit_syncdraw(const string &role, const string &area)
649 struct rect rect = this->lc->getAreaSize(area);
650 this->send_event(kListEventName[Event_SyncDraw],
651 role.c_str(), area.c_str(), rect.x, rect.y, rect.w, rect.h);
654 void WindowManager::emit_flushdraw(const string& role)
656 this->send_event(kListEventName[Event_FlushDraw], role);
659 void WindowManager::emit_visible(const string& role, bool is_visible)
661 this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], role);
664 void WindowManager::emit_invisible(const string& role)
666 return emit_visible(role, false);
669 void WindowManager::emit_visible(const string& role) { return emit_visible(role, true); }
671 WMError WindowManager::setRequest(const string& appid, const string &role, const string &area,
672 Task task, unsigned* req_num)
674 if (!g_app_list.contains(appid))
676 return WMError::NOT_REGISTERED;
679 auto client = g_app_list.lookUpClient(appid);
684 unsigned current = g_app_list.currentRequestNumber();
685 unsigned requested_num = g_app_list.getRequestNumber(appid);
686 if (requested_num != 0)
688 HMI_SEQ_INFO(requested_num,
689 "%s %s %s request is already queued", appid.c_str(), role.c_str(), area.c_str());
693 WMRequest req = WMRequest(appid, role, area, task);
694 unsigned new_req = g_app_list.addRequest(req);
696 g_app_list.reqDump();
698 HMI_SEQ_DEBUG(current, "%s start sequence with %s, %s", appid.c_str(), role.c_str(), area.c_str());
700 return WMError::SUCCESS;
703 WMError WindowManager::checkPolicy(unsigned req_num)
708 // get current trigger
710 WMError ret = WMError::LAYOUT_CHANGE_FAIL;
711 auto trigger = g_app_list.getRequest(req_num, &found);
714 ret = WMError::NO_ENTRY;
717 string req_area = trigger.area;
719 if (trigger.task == Task::TASK_ALLOCATE)
721 const char *msg = this->check_surface_exist(trigger.role.c_str());
725 HMI_SEQ_ERROR(req_num, msg);
730 // Input event data to PolicyManager
731 if (0 > this->pmw.setInputEventData(trigger.task, trigger.role, trigger.area))
733 HMI_SEQ_ERROR(req_num, "Failed to set input event data to PolicyManager");
737 // Execute state transition of PolicyManager
738 if (0 > this->pmw.executeStateTransition())
740 HMI_SEQ_ERROR(req_num, "Failed to execute state transition of PolicyManager");
744 ret = WMError::SUCCESS;
746 g_app_list.reqDump();
751 WMError WindowManager::startTransition(unsigned req_num)
753 bool sync_draw_happen = false;
755 WMError ret = WMError::SUCCESS;
756 auto actions = g_app_list.getActions(req_num, &found);
759 ret = WMError::NO_ENTRY;
760 HMI_SEQ_ERROR(req_num,
761 "Window Manager bug :%s : Action is not set", errorDescription(ret));
765 for (const auto &action : actions)
767 if (action.visible == TaskVisible::VISIBLE)
769 sync_draw_happen = true;
771 // TODO: application requests by old role,
772 // so convert role new to old for emitting event
773 string old_role = this->rolenew2old[action.role];
775 this->emit_syncdraw(old_role, action.area);
776 /* TODO: emit event for app not subscriber
777 if(g_app_list.contains(y.appid))
778 g_app_list.lookUpClient(y.appid)->emit_syncdraw(y.role, y.area); */
782 if (sync_draw_happen)
788 // deactivate only, no syncDraw
789 // Make it deactivate here
790 for (const auto &x : actions)
792 this->lc->visibilityChange(x);
793 string old_role = this->rolenew2old[x.role];
794 emit_deactivated(old_role.c_str());
795 /* if (g_app_list.contains(x.client->appID()))
797 auto client = g_app_list.lookUpClient(x.client->appID());
798 this->deactivate(client->surfaceID(x.role));
801 ret = WMError::NO_LAYOUT_CHANGE;
806 WMError WindowManager::doEndDraw(unsigned req_num)
810 auto actions = g_app_list.getActions(req_num, &found);
811 WMError ret = WMError::SUCCESS;
814 ret = WMError::NO_ENTRY;
818 HMI_SEQ_INFO(req_num, "do endDraw");
820 // layout change and make it visible
821 for (const auto &act : actions)
823 if(act.visible != TaskVisible::NO_CHANGE)
826 ret = this->lc->layoutChange(act);
827 if(ret != WMError::SUCCESS)
829 HMI_SEQ_WARNING(req_num,
830 "Failed to manipulate surfaces while state change : %s", errorDescription(ret));
833 ret = this->lc->visibilityChange(act);
835 // Emit active/deactive event
836 string old_role = this->rolenew2old[act.role];
837 if(act.visible == VISIBLE)
839 emit_activated(old_role.c_str());
843 emit_deactivated(old_role.c_str());
846 if (ret != WMError::SUCCESS)
848 HMI_SEQ_WARNING(req_num,
849 "Failed to manipulate surfaces while state change : %s", errorDescription(ret));
852 HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str());
856 HMI_SEQ_INFO(req_num, "emit flushDraw");
858 for(const auto &act_flush : actions)
860 if(act_flush.visible == TaskVisible::VISIBLE)
862 // TODO: application requests by old role,
863 // so convert role new to old for emitting event
864 string old_role = this->rolenew2old[act_flush.role];
866 this->emit_flushdraw(old_role.c_str());
873 void WindowManager::emitScreenUpdated(unsigned req_num)
876 HMI_SEQ_DEBUG(req_num, "emit screen updated");
878 auto actions = g_app_list.getActions(req_num, &found);
880 // create json object
881 json_object *j = json_object_new_object();
882 json_object *jarray = json_object_new_array();
884 for(const auto& action: actions)
886 if(action.visible != TaskVisible::INVISIBLE)
888 json_object_array_add(jarray, json_object_new_string(action.client->appID().c_str()));
891 json_object_object_add(j, kKeyIds, jarray);
892 HMI_SEQ_INFO(req_num, "Visible app: %s", json_object_get_string(j));
894 int ret = afb_event_push(
895 this->map_afb_event[kListEventName[Event_ScreenUpdated]], j);
898 HMI_DEBUG("afb_event_push failed: %m");
902 void WindowManager::setTimer()
905 if (clock_gettime(CLOCK_BOOTTIME, &ts) != 0) {
906 HMI_ERROR("Could't set time (clock_gettime() returns with error");
910 HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "Timer set activate");
911 if (g_timer_ev_src == nullptr)
913 // firsttime set into sd_event
914 int ret = sd_event_add_time(afb_daemon_get_event_loop(), &g_timer_ev_src,
915 CLOCK_BOOTTIME, (uint64_t)(ts.tv_sec + kTimeOut) * 1000000ULL, 1, processTimerHandler, this);
918 HMI_ERROR("Could't set timer");
923 // update timer limitation after second time
924 sd_event_source_set_time(g_timer_ev_src, (uint64_t)(ts.tv_sec + kTimeOut) * 1000000ULL);
925 sd_event_source_set_enabled(g_timer_ev_src, SD_EVENT_ONESHOT);
929 void WindowManager::stopTimer()
931 unsigned req_num = g_app_list.currentRequestNumber();
932 HMI_SEQ_DEBUG(req_num, "Timer stop");
933 int rc = sd_event_source_set_enabled(g_timer_ev_src, SD_EVENT_OFF);
936 HMI_SEQ_ERROR(req_num, "Timer stop failed");
940 void WindowManager::processNextRequest()
943 g_app_list.reqDump();
944 unsigned req_num = g_app_list.currentRequestNumber();
945 if (g_app_list.haveRequest())
947 HMI_SEQ_DEBUG(req_num, "Process next request");
948 WMError rc = checkPolicy(req_num);
949 if (rc != WMError::SUCCESS)
951 HMI_SEQ_ERROR(req_num, errorDescription(rc));
956 HMI_SEQ_DEBUG(req_num, "Nothing Request. Waiting Request");
960 const char* WindowManager::convertRoleOldToNew(char const *old_role)
962 const char *new_role = nullptr;
964 for (auto const &on : this->roleold2new)
966 std::regex regex = std::regex(on.first);
967 if (std::regex_match(old_role, regex))
969 // role is old. So convert to new.
970 new_role = on.second.c_str();
975 if (nullptr == new_role)
977 // role is new or fallback.
981 HMI_DEBUG("old:%s -> new:%s", old_role, new_role);
986 int WindowManager::loadOldRoleDb()
988 // Get afm application installed dir
989 char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR");
990 HMI_DEBUG("afm_app_install_dir:%s", afm_app_install_dir);
993 if (!afm_app_install_dir)
995 HMI_ERROR("AFM_APP_INSTALL_DIR is not defined");
999 file_name = string(afm_app_install_dir) + string("/etc/old_roles.db");
1003 json_object* json_obj;
1004 int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj);
1007 HMI_ERROR("Could not open old_role.db, so use default old_role information");
1008 json_obj = json_tokener_parse(kDefaultOldRoleDb);
1010 HMI_DEBUG("json_obj dump:%s", json_object_get_string(json_obj));
1013 json_object* json_cfg;
1014 if (!json_object_object_get_ex(json_obj, "old_roles", &json_cfg))
1016 HMI_ERROR("Parse Error!!");
1020 int len = json_object_array_length(json_cfg);
1021 HMI_DEBUG("json_cfg len:%d", len);
1022 HMI_DEBUG("json_cfg dump:%s", json_object_get_string(json_cfg));
1024 for (int i=0; i<len; i++)
1026 json_object* json_tmp = json_object_array_get_idx(json_cfg, i);
1028 const char* old_role = jh::getStringFromJson(json_tmp, "name");
1029 if (nullptr == old_role)
1031 HMI_ERROR("Parse Error!!");
1035 const char* new_role = jh::getStringFromJson(json_tmp, "new");
1036 if (nullptr == new_role)
1038 HMI_ERROR("Parse Error!!");
1042 this->roleold2new[old_role] = string(new_role);
1046 for(auto itr = this->roleold2new.begin();
1047 itr != this->roleold2new.end(); ++itr)
1049 HMI_DEBUG(">>> role old:%s new:%s",
1050 itr->first.c_str(), itr->second.c_str());
1053 // Release json_object
1054 json_object_put(json_obj);
1059 const char *WindowManager::check_surface_exist(const char *drawing_name)
1061 auto const &surface_id = this->id_alloc.lookup(drawing_name);
1064 return "Surface does not exist";
1069 const char* WindowManager::kDefaultOldRoleDb = "{ \
1072 \"name\": \"HomeScreen\", \
1073 \"new\": \"homescreen\" \
1076 \"name\": \"Music\", \
1077 \"new\": \"music\" \
1080 \"name\": \"MediaPlayer\", \
1081 \"new\": \"music\" \
1084 \"name\": \"Video\", \
1085 \"new\": \"video\" \
1088 \"name\": \"VideoPlayer\", \
1089 \"new\": \"video\" \
1092 \"name\": \"WebBrowser\", \
1093 \"new\": \"browser\" \
1096 \"name\": \"Radio\", \
1097 \"new\": \"radio\" \
1100 \"name\": \"Phone\", \
1101 \"new\": \"phone\" \
1104 \"name\": \"Navigation\", \
1108 \"name\": \"HVAC\", \
1112 \"name\": \"Settings\", \
1113 \"new\": \"settings\" \
1116 \"name\": \"Dashboard\", \
1117 \"new\": \"dashboard\" \
1120 \"name\": \"POI\", \
1124 \"name\": \"Mixer\", \
1125 \"new\": \"mixer\" \
1128 \"name\": \"Restriction\", \
1129 \"new\": \"restriction\" \
1132 \"name\": \"^OnScreen.*\", \
1133 \"new\": \"on_screen\" \