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);
163 result<int> WindowManager::api_request_surface(char const *appid, char const *drawing_name)
165 // TODO: application requests by old role,
166 // so convert role old to new
167 const char *role = this->convertRoleOldToNew(drawing_name);
168 string str_id = appid;
169 string str_role = role;
172 if(!g_app_list.contains(str_id))
174 lid = this->lc->getNewLayerID(str_role);
177 // register drawing_name as fallback and make it displayed.
178 lid = this->lc->getNewLayerID(string("fallback"));
179 HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role);
182 return Err<int>("Designated role does not match any role, fallback is disabled");
185 this->lc->createNewLayer(lid);
186 // add client into the db
187 g_app_list.addClient(str_id, lid, str_role);
190 // generate surface ID for ivi-shell application
191 auto rname = this->id_alloc.lookup(str_role);
194 // name does not exist yet, allocate surface id...
195 auto id = int(this->id_alloc.generate_id(str_role));
196 this->tmp_surface2app[id] = {str_id, lid};
198 // Set role map of (new, old)
199 this->rolenew2old[role] = string(drawing_name);
204 // Check currently registered drawing names if it is already there.
205 return Err<int>("Surface already present");
208 char const *WindowManager::api_request_surface(char const *appid, char const *drawing_name,
211 // TODO: application requests by old role,
212 // so convert role old to new
213 const char *role = this->convertRoleOldToNew(drawing_name);
214 string str_id = appid;
215 string str_role = role;
217 unsigned sid = std::stol(ivi_id);
218 HMI_DEBUG("This API(requestSurfaceXDG) is for XDG Application using runXDG");
220 * IVI-shell doesn't send surface_size event via ivi-wm protocol
221 * if the application is using XDG surface.
222 * So WM has to set surface size with original size here
224 WMError ret = this->lc->setXDGSurfaceOriginSize(sid);
227 HMI_ERROR("%s", errorDescription(ret));
228 HMI_WARNING("The main user of this API is runXDG");
232 if(!g_app_list.contains(str_id))
234 unsigned l_id = this->lc->getNewLayerID(str_role);
237 // register drawing_name as fallback and make it displayed.
238 l_id = this->lc->getNewLayerID("fallback");
239 HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role);
242 return "Designated role does not match any role, fallback is disabled";
245 this->lc->createNewLayer(l_id);
246 // add client into the db
247 g_app_list.addClient(str_id, l_id, str_role);
250 auto rname = this->id_alloc.lookup(str_role);
254 return "Surface already present";
257 // register pair drawing_name and ivi_id
258 this->id_alloc.register_name_id(str_role, sid);
260 auto client = g_app_list.lookUpClient(str_id);
261 client->addSurface(sid);
263 // Set role map of (new, old)
264 this->rolenew2old[role] = string(drawing_name);
269 void WindowManager::api_activate_window(char const *appid, char const *drawing_name,
270 char const *drawing_area, const reply_func &reply)
272 // TODO: application requests by old role,
273 // so convert role old to new
274 const char *c_role = this->convertRoleOldToNew(drawing_name);
277 string role = c_role;
278 string area = drawing_area;
280 if(!g_app_list.contains(id))
282 reply("app doesn't request 'requestSurface' or 'setRole' yet");
285 auto client = g_app_list.lookUpClient(id);
287 Task task = Task::TASK_ALLOCATE;
288 unsigned req_num = 0;
289 WMError ret = WMError::UNKNOWN;
291 ret = this->setRequest(id, role, area, task, &req_num);
293 if(ret != WMError::SUCCESS)
295 HMI_ERROR(errorDescription(ret));
296 reply("Failed to set request");
301 if (req_num != g_app_list.currentRequestNumber())
303 // Add request, then invoked after the previous task is finished
304 HMI_SEQ_DEBUG(req_num, "request is accepted");
311 ret = this->checkPolicy(req_num);
313 if (ret != WMError::SUCCESS)
316 HMI_SEQ_ERROR(req_num, errorDescription(ret));
317 g_app_list.removeRequest(req_num);
318 this->processNextRequest();
322 void WindowManager::api_deactivate_window(char const *appid, char const *drawing_name,
323 const reply_func &reply)
325 // TODO: application requests by old role,
326 // so convert role old to new
327 const char *c_role = this->convertRoleOldToNew(drawing_name);
333 string role = c_role;
334 string area = ""; //drawing_area;
335 Task task = Task::TASK_RELEASE;
336 unsigned req_num = 0;
337 WMError ret = WMError::UNKNOWN;
339 ret = this->setRequest(id, role, area, task, &req_num);
341 if (ret != WMError::SUCCESS)
343 HMI_ERROR(errorDescription(ret));
344 reply("Failed to set request");
349 if (req_num != g_app_list.currentRequestNumber())
351 // Add request, then invoked after the previous task is finished
352 HMI_SEQ_DEBUG(req_num, "request is accepted");
359 ret = this->checkPolicy(req_num);
361 if (ret != WMError::SUCCESS)
364 HMI_SEQ_ERROR(req_num, errorDescription(ret));
365 g_app_list.removeRequest(req_num);
366 this->processNextRequest();
370 void WindowManager::api_enddraw(char const *appid, char const *drawing_name)
372 // TODO: application requests by old role,
373 // so convert role old to new
374 const char *c_role = this->convertRoleOldToNew(drawing_name);
377 string role = c_role;
378 unsigned current_req = g_app_list.currentRequestNumber();
379 bool result = g_app_list.setEndDrawFinished(current_req, id, role);
383 HMI_ERROR("%s is not in transition state", id.c_str());
387 if (g_app_list.endDrawFullfilled(current_req))
389 // do task for endDraw
391 WMError ret = this->doEndDraw(current_req);
393 if(ret != WMError::SUCCESS)
395 //this->emit_error();
397 // Undo state of PolicyManager
398 this->pmw.undoState();
399 this->lc->undoUpdate();
401 this->emitScreenUpdated(current_req);
402 HMI_SEQ_INFO(current_req, "Finish request status: %s", errorDescription(ret));
404 g_app_list.removeRequest(current_req);
406 this->processNextRequest();
410 HMI_SEQ_INFO(current_req, "Wait other App call endDraw");
415 int WindowManager::api_subscribe(afb_req req, int event_id)
417 struct afb_event event = this->map_afb_event[kListEventName[event_id]];
418 return afb_req_subscribe(req, event);
421 result<json_object *> WindowManager::api_get_display_info()
423 Screen screen = this->lc->getScreenInfo();
425 json_object *object = json_object_new_object();
426 json_object_object_add(object, kKeyWidthPixel, json_object_new_int(screen.width()));
427 json_object_object_add(object, kKeyHeightPixel, json_object_new_int(screen.height()));
429 json_object_object_add(object, kKeyWidthMm, json_object_new_int(0));
430 json_object_object_add(object, kKeyHeightMm, json_object_new_int(0));
431 json_object_object_add(object, kKeyScale, json_object_new_double(this->lc->scale()));
433 return Ok<json_object *>(object);
436 result<json_object *> WindowManager::api_get_area_info(char const *drawing_name)
440 // TODO: application requests by old role,
441 // so convert role old to new
442 const char *role = this->convertRoleOldToNew(drawing_name);
444 // Check drawing name, surface/layer id
445 auto const &surface_id = this->id_alloc.lookup(role);
448 return Err<json_object *>("Surface does not exist");
451 // Set area rectangle
452 struct rect area_info = this->area_info[*surface_id];
453 json_object *object = json_object_new_object();
454 json_object_object_add(object, kKeyX, json_object_new_int(area_info.x));
455 json_object_object_add(object, kKeyY, json_object_new_int(area_info.y));
456 json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w));
457 json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h));
459 return Ok<json_object *>(object);
462 void WindowManager::send_event(const string& evname, const string& role)
464 json_object *j = json_object_new_object();
465 json_object_object_add(j, kKeyDrawingName, json_object_new_string(role.c_str()));
467 int ret = afb_event_push(this->map_afb_event[evname], j);
470 HMI_DEBUG("afb_event_push failed: %m");
474 void WindowManager::send_event(const string& evname, const string& role, const string& area,
475 int x, int y, int w, int h)
477 json_object *j_rect = json_object_new_object();
478 json_object_object_add(j_rect, kKeyX, json_object_new_int(x));
479 json_object_object_add(j_rect, kKeyY, json_object_new_int(y));
480 json_object_object_add(j_rect, kKeyWidth, json_object_new_int(w));
481 json_object_object_add(j_rect, kKeyHeight, json_object_new_int(h));
483 json_object *j = json_object_new_object();
484 json_object_object_add(j, kKeyDrawingName, json_object_new_string(role.c_str()));
485 json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area.c_str()));
486 json_object_object_add(j, kKeyDrawingRect, j_rect);
488 int ret = afb_event_push(this->map_afb_event[evname], j);
491 HMI_DEBUG("afb_event_push failed: %m");
498 void WindowManager::surface_created(unsigned surface_id)
501 if(this->tmp_surface2app.count(surface_id) != 0)
503 string appid = this->tmp_surface2app[surface_id].appid;
504 auto client = g_app_list.lookUpClient(appid);
505 if(client != nullptr)
507 WMError ret = client->addSurface(surface_id);
508 HMI_INFO("Add surface %d to \"%s\"", surface_id, appid.c_str());
509 if(ret != WMError::SUCCESS)
511 HMI_ERROR("Failed to add surface to client %s", client->appID().c_str());
514 this->tmp_surface2app.erase(surface_id);
518 void WindowManager::surface_removed(unsigned surface_id)
520 HMI_DEBUG("Delete surface_id %u", surface_id);
521 this->id_alloc.remove_id(surface_id);
522 g_app_list.removeSurface(surface_id);
525 void WindowManager::removeClient(const string &appid)
527 HMI_DEBUG("Remove clinet %s from list", appid.c_str());
528 auto client = g_app_list.lookUpClient(appid);
529 this->lc->appTerminated(client);
530 g_app_list.removeClient(appid);
533 void WindowManager::exceptionProcessForTransition()
535 unsigned req_num = g_app_list.currentRequestNumber();
536 HMI_SEQ_NOTICE(req_num, "Process exception handling for request. Remove current request %d", req_num);
537 g_app_list.removeRequest(req_num);
538 HMI_SEQ_NOTICE(g_app_list.currentRequestNumber(), "Process next request if exists");
539 this->processNextRequest();
542 void WindowManager::timerHandler()
544 unsigned req_num = g_app_list.currentRequestNumber();
545 HMI_SEQ_DEBUG(req_num, "Timer expired remove Request");
546 g_app_list.reqDump();
547 g_app_list.removeRequest(req_num);
548 this->processNextRequest();
551 void WindowManager::startTransitionWrapper(vector<WMAction> &actions)
554 unsigned req_num = g_app_list.currentRequestNumber();
558 if (g_app_list.haveRequest())
560 HMI_SEQ_DEBUG(req_num, "There is no WMAction for this request");
561 goto proc_remove_request;
565 HMI_SEQ_DEBUG(req_num, "There is no request");
570 for (auto &act : actions)
575 auto const &surface_id = this->id_alloc.lookup(act.role.c_str());
576 if(surface_id == nullopt)
578 goto proc_remove_request;
580 string appid = g_app_list.getAppID(*surface_id, &found);
583 if (TaskVisible::INVISIBLE == act.visible)
585 // App is killed, so do not set this action
590 HMI_SEQ_ERROR(req_num, "appid which is visible is not found");
595 auto client = g_app_list.lookUpClient(appid);
596 act.req_num = req_num;
600 ret = g_app_list.setAction(req_num, act);
601 if (ret != WMError::SUCCESS)
603 HMI_SEQ_ERROR(req_num, "Setting action is failed");
608 HMI_SEQ_DEBUG(req_num, "Start transition.");
609 ret = this->startTransition(req_num);
610 if (ret != WMError::SUCCESS)
612 if (ret == WMError::NO_LAYOUT_CHANGE)
614 goto proc_remove_request;
618 HMI_SEQ_ERROR(req_num, "Transition state is failed");
627 HMI_SEQ_ERROR(req_num, errorDescription(ret));
628 this->pmw.undoState();
631 g_app_list.removeRequest(req_num);
632 this->processNextRequest();
635 void WindowManager::processError(WMError error)
637 unsigned req_num = g_app_list.currentRequestNumber();
640 HMI_SEQ_ERROR(req_num, errorDescription(error));
641 g_app_list.removeRequest(req_num);
642 this->processNextRequest();
646 ******* Private Functions *******
649 void WindowManager::emit_activated(const string& role)
651 this->send_event(kListEventName[Event_Active], role);
654 void WindowManager::emit_deactivated(const string& role)
656 this->send_event(kListEventName[Event_Inactive], role);
659 void WindowManager::emit_syncdraw(const string& role, char const *area, int x, int y, int w, int h)
661 this->send_event(kListEventName[Event_SyncDraw], role, area, x, y, w, h);
664 void WindowManager::emit_syncdraw(const string &role, const string &area)
666 struct rect rect = this->lc->getAreaSize(area);
667 this->send_event(kListEventName[Event_SyncDraw],
668 role.c_str(), area.c_str(), rect.x, rect.y, rect.w, rect.h);
671 void WindowManager::emit_flushdraw(const string& role)
673 this->send_event(kListEventName[Event_FlushDraw], role);
676 void WindowManager::emit_visible(const string& role, bool is_visible)
678 this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], role);
681 void WindowManager::emit_invisible(const string& role)
683 return emit_visible(role, false);
686 void WindowManager::emit_visible(const string& role) { return emit_visible(role, true); }
688 WMError WindowManager::setRequest(const string& appid, const string &role, const string &area,
689 Task task, unsigned* req_num)
691 if (!g_app_list.contains(appid))
693 return WMError::NOT_REGISTERED;
696 auto client = g_app_list.lookUpClient(appid);
701 unsigned current = g_app_list.currentRequestNumber();
702 unsigned requested_num = g_app_list.getRequestNumber(appid);
703 if (requested_num != 0)
705 HMI_SEQ_INFO(requested_num,
706 "%s %s %s request is already queued", appid.c_str(), role.c_str(), area.c_str());
710 WMRequest req = WMRequest(appid, role, area, task);
711 unsigned new_req = g_app_list.addRequest(req);
713 g_app_list.reqDump();
715 HMI_SEQ_DEBUG(current, "%s start sequence with %s, %s", appid.c_str(), role.c_str(), area.c_str());
717 return WMError::SUCCESS;
720 WMError WindowManager::checkPolicy(unsigned req_num)
725 // get current trigger
727 WMError ret = WMError::LAYOUT_CHANGE_FAIL;
728 auto trigger = g_app_list.getRequest(req_num, &found);
731 ret = WMError::NO_ENTRY;
734 string req_area = trigger.area;
736 // Input event data to PolicyManager
737 if (0 > this->pmw.setInputEventData(trigger.task, trigger.role, trigger.area))
739 HMI_SEQ_ERROR(req_num, "Failed to set input event data to PolicyManager");
743 // Execute state transition of PolicyManager
744 if (0 > this->pmw.executeStateTransition())
746 HMI_SEQ_ERROR(req_num, "Failed to execute state transition of PolicyManager");
750 ret = WMError::SUCCESS;
752 g_app_list.reqDump();
757 WMError WindowManager::startTransition(unsigned req_num)
759 bool sync_draw_happen = false;
761 WMError ret = WMError::SUCCESS;
762 auto actions = g_app_list.getActions(req_num, &found);
765 ret = WMError::NO_ENTRY;
766 HMI_SEQ_ERROR(req_num,
767 "Window Manager bug :%s : Action is not set", errorDescription(ret));
771 g_app_list.reqDump();
772 for (const auto &action : actions)
774 if (action.visible == TaskVisible::VISIBLE)
776 sync_draw_happen = true;
778 // TODO: application requests by old role,
779 // so convert role new to old for emitting event
780 string old_role = this->rolenew2old[action.role];
782 this->emit_syncdraw(old_role, action.area);
783 /* TODO: emit event for app not subscriber
784 if(g_app_list.contains(y.appid))
785 g_app_list.lookUpClient(y.appid)->emit_syncdraw(y.role, y.area); */
789 if (sync_draw_happen)
795 // deactivate only, no syncDraw
796 // Make it deactivate here
797 for (const auto &x : actions)
799 this->lc->visibilityChange(x);
800 string old_role = this->rolenew2old[x.role];
801 emit_deactivated(old_role.c_str());
802 /* if (g_app_list.contains(x.client->appID()))
804 auto client = g_app_list.lookUpClient(x.client->appID());
805 this->deactivate(client->surfaceID(x.role));
808 this->lc->renderLayers();
809 ret = WMError::NO_LAYOUT_CHANGE;
814 WMError WindowManager::doEndDraw(unsigned req_num)
818 auto actions = g_app_list.getActions(req_num, &found);
819 WMError ret = WMError::SUCCESS;
822 ret = WMError::NO_ENTRY;
826 HMI_SEQ_INFO(req_num, "do endDraw");
828 // layout change and make it visible
829 for (const auto &act : actions)
831 if(act.visible != TaskVisible::NO_CHANGE)
834 ret = this->lc->layoutChange(act);
835 if(ret != WMError::SUCCESS)
837 HMI_SEQ_WARNING(req_num,
838 "Failed to manipulate surfaces while state change : %s", errorDescription(ret));
841 ret = this->lc->visibilityChange(act);
843 // Emit active/deactive event
844 string old_role = this->rolenew2old[act.role];
845 if(act.visible == VISIBLE)
847 emit_visible(old_role.c_str());
848 emit_activated(old_role.c_str());
852 emit_invisible(old_role.c_str());
853 emit_deactivated(old_role.c_str());
856 if (ret != WMError::SUCCESS)
858 HMI_SEQ_WARNING(req_num,
859 "Failed to manipulate surfaces while state change : %s", errorDescription(ret));
862 HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str());
865 this->lc->renderLayers();
867 HMI_SEQ_INFO(req_num, "emit flushDraw");
869 for(const auto &act_flush : actions)
871 if(act_flush.visible == TaskVisible::VISIBLE)
873 // TODO: application requests by old role,
874 // so convert role new to old for emitting event
875 string old_role = this->rolenew2old[act_flush.role];
877 this->emit_flushdraw(old_role.c_str());
884 void WindowManager::emitScreenUpdated(unsigned req_num)
887 HMI_SEQ_DEBUG(req_num, "emit screen updated");
889 auto actions = g_app_list.getActions(req_num, &found);
891 // create json object
892 json_object *j = json_object_new_object();
893 json_object *jarray = json_object_new_array();
895 for(const auto& action: actions)
897 if(action.visible != TaskVisible::INVISIBLE)
899 json_object_array_add(jarray, json_object_new_string(action.client->appID().c_str()));
902 json_object_object_add(j, kKeyIds, jarray);
903 HMI_SEQ_INFO(req_num, "Visible app: %s", json_object_get_string(j));
905 int ret = afb_event_push(
906 this->map_afb_event[kListEventName[Event_ScreenUpdated]], j);
909 HMI_DEBUG("afb_event_push failed: %m");
913 void WindowManager::setTimer()
916 if (clock_gettime(CLOCK_BOOTTIME, &ts) != 0) {
917 HMI_ERROR("Could't set time (clock_gettime() returns with error");
921 HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "Timer set activate");
922 if (g_timer_ev_src == nullptr)
924 // firsttime set into sd_event
925 int ret = sd_event_add_time(afb_daemon_get_event_loop(), &g_timer_ev_src,
926 CLOCK_BOOTTIME, (uint64_t)(ts.tv_sec + kTimeOut) * 1000000ULL, 1, processTimerHandler, this);
929 HMI_ERROR("Could't set timer");
934 // update timer limitation after second time
935 sd_event_source_set_time(g_timer_ev_src, (uint64_t)(ts.tv_sec + kTimeOut) * 1000000ULL);
936 sd_event_source_set_enabled(g_timer_ev_src, SD_EVENT_ONESHOT);
940 void WindowManager::stopTimer()
942 unsigned req_num = g_app_list.currentRequestNumber();
943 HMI_SEQ_DEBUG(req_num, "Timer stop");
944 int rc = sd_event_source_set_enabled(g_timer_ev_src, SD_EVENT_OFF);
947 HMI_SEQ_ERROR(req_num, "Timer stop failed");
951 void WindowManager::processNextRequest()
954 g_app_list.reqDump();
955 unsigned req_num = g_app_list.currentRequestNumber();
956 if (g_app_list.haveRequest())
958 HMI_SEQ_DEBUG(req_num, "Process next request");
959 WMError rc = checkPolicy(req_num);
960 if (rc != WMError::SUCCESS)
962 HMI_SEQ_ERROR(req_num, errorDescription(rc));
967 HMI_SEQ_DEBUG(req_num, "Nothing Request. Waiting Request");
971 const char* WindowManager::convertRoleOldToNew(char const *old_role)
973 const char *new_role = nullptr;
975 for (auto const &on : this->roleold2new)
977 std::regex regex = std::regex(on.first);
978 if (std::regex_match(old_role, regex))
980 // role is old. So convert to new.
981 new_role = on.second.c_str();
986 if (nullptr == new_role)
988 // role is new or fallback.
992 HMI_DEBUG("old:%s -> new:%s", old_role, new_role);
997 int WindowManager::loadOldRoleDb()
999 // Get afm application installed dir
1000 char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR");
1001 HMI_DEBUG("afm_app_install_dir:%s", afm_app_install_dir);
1004 if (!afm_app_install_dir)
1006 HMI_ERROR("AFM_APP_INSTALL_DIR is not defined");
1010 file_name = string(afm_app_install_dir) + string("/etc/old_roles.json");
1014 json_object* json_obj;
1015 int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj);
1018 HMI_ERROR("Could not open old_role.db, so use default old_role information");
1019 json_obj = json_tokener_parse(kDefaultOldRoleDb);
1021 HMI_DEBUG("json_obj dump:%s", json_object_get_string(json_obj));
1024 json_object* json_cfg;
1025 if (!json_object_object_get_ex(json_obj, "old_roles", &json_cfg))
1027 HMI_ERROR("Parse Error!!");
1031 int len = json_object_array_length(json_cfg);
1032 HMI_DEBUG("json_cfg len:%d", len);
1033 HMI_DEBUG("json_cfg dump:%s", json_object_get_string(json_cfg));
1035 for (int i=0; i<len; i++)
1037 json_object* json_tmp = json_object_array_get_idx(json_cfg, i);
1039 const char* old_role = jh::getStringFromJson(json_tmp, "name");
1040 if (nullptr == old_role)
1042 HMI_ERROR("Parse Error!!");
1046 const char* new_role = jh::getStringFromJson(json_tmp, "new");
1047 if (nullptr == new_role)
1049 HMI_ERROR("Parse Error!!");
1053 this->roleold2new[old_role] = string(new_role);
1057 for(auto itr = this->roleold2new.begin();
1058 itr != this->roleold2new.end(); ++itr)
1060 HMI_DEBUG(">>> role old:%s new:%s",
1061 itr->first.c_str(), itr->second.c_str());
1064 // Release json_object
1065 json_object_put(json_obj);
1070 const char* WindowManager::kDefaultOldRoleDb = "{ \
1073 \"name\": \"HomeScreen\", \
1074 \"new\": \"homescreen\" \
1077 \"name\": \"Music\", \
1078 \"new\": \"music\" \
1081 \"name\": \"MediaPlayer\", \
1082 \"new\": \"music\" \
1085 \"name\": \"Video\", \
1086 \"new\": \"video\" \
1089 \"name\": \"VideoPlayer\", \
1090 \"new\": \"video\" \
1093 \"name\": \"WebBrowser\", \
1094 \"new\": \"browser\" \
1097 \"name\": \"Radio\", \
1098 \"new\": \"radio\" \
1101 \"name\": \"Phone\", \
1102 \"new\": \"phone\" \
1105 \"name\": \"Navigation\", \
1109 \"name\": \"HVAC\", \
1113 \"name\": \"Settings\", \
1114 \"new\": \"settings\" \
1117 \"name\": \"Dashboard\", \
1118 \"new\": \"dashboard\" \
1121 \"name\": \"POI\", \
1125 \"name\": \"Mixer\", \
1126 \"new\": \"mixer\" \
1129 \"name\": \"Restriction\", \
1130 \"new\": \"restriction\" \
1133 \"name\": \"^OnScreen.*\", \
1134 \"new\": \"on_screen\" \