Merge "set_role_pid_ver"
[apps/agl-service-windowmanager.git] / src / window_manager.cpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <fstream>
18 #include <regex>
19
20 #include "window_manager.hpp"
21 #include "json_helper.hpp"
22 #include "wm_config.hpp"
23 #include "applist.hpp"
24
25 extern "C"
26 {
27 #include <systemd/sd-event.h>
28 }
29
30 namespace wm
31 {
32
33 static const unsigned kTimeOut = 3000000UL; /* 3s */
34
35 /* DrawingArea name used by "{layout}.{area}" */
36 const char kNameLayoutNormal[] = "normal";
37 const char kNameLayoutSplit[]  = "split";
38 const char kNameAreaFull[]     = "full";
39 const char kNameAreaMain[]     = "main";
40 const char kNameAreaSub[]      = "sub";
41
42 /* Key for json obejct */
43 const char kKeyDrawingName[] = "drawing_name";
44 const char kKeyDrawingArea[] = "drawing_area";
45 const char kKeyDrawingRect[] = "drawing_rect";
46 const char kKeyX[]           = "x";
47 const char kKeyY[]           = "y";
48 const char kKeyWidth[]       = "width";
49 const char kKeyHeight[]      = "height";
50 const char kKeyWidthPixel[]  = "width_pixel";
51 const char kKeyHeightPixel[] = "height_pixel";
52 const char kKeyWidthMm[]     = "width_mm";
53 const char kKeyHeightMm[]    = "height_mm";
54 const char kKeyIds[]         = "ids";
55
56 static sd_event_source *g_timer_ev_src = nullptr;
57 static AppList g_app_list;
58 static WindowManager *g_context;
59
60 namespace
61 {
62
63 using nlohmann::json;
64
65 result<json> file_to_json(char const *filename)
66 {
67     json j;
68     std::ifstream i(filename);
69     if (i.fail())
70     {
71         HMI_DEBUG("wm", "Could not open config file, so use default layer information");
72         j = default_layers_json;
73     }
74     else
75     {
76         i >> j;
77     }
78
79     return Ok(j);
80 }
81
82 struct result<layer_map> load_layer_map(char const *filename)
83 {
84     HMI_DEBUG("wm", "loading IDs from %s", filename);
85
86     auto j = file_to_json(filename);
87     if (j.is_err())
88     {
89         return Err<layer_map>(j.unwrap_err());
90     }
91     json jids = j.unwrap();
92
93     return to_layer_map(jids);
94 }
95
96 static int processTimerHandler(sd_event_source *s, uint64_t usec, void *userdata)
97 {
98     HMI_NOTICE("wm", "Time out occurs because the client replys endDraw slow, so revert the request");
99     reinterpret_cast<wm::WindowManager *>(userdata)->timerHandler();
100     return 0;
101 }
102
103 static void onStateTransitioned(std::vector<WMAction> actions)
104 {
105     g_context->startTransitionWrapper(actions);
106 }
107
108 static void onError()
109 {
110     g_context->processError(WMError::LAYOUT_CHANGE_FAIL);
111 }
112 } // namespace
113
114 /**
115  * WindowManager Impl
116  */
117 WindowManager::WindowManager(wl::display *d)
118     : chooks{this},
119       display{d},
120       controller{},
121       outputs(),
122       layers(),
123       id_alloc{},
124       pending_events(false)
125 {
126     char const *path_layers_json = getenv("AFM_APP_INSTALL_DIR");
127     std::string path;
128     if (!path_layers_json)
129     {
130         HMI_ERROR("wm", "AFM_APP_INSTALL_DIR is not defined");
131         path = std::string(path_layers_json);
132     }
133     else
134     {
135         path = std::string(path_layers_json) + std::string("/etc/layers.json");
136     }
137
138     try
139     {
140         {
141             auto l = load_layer_map(path.c_str());
142             if (l.is_ok())
143             {
144                 this->layers = l.unwrap();
145             }
146             else
147             {
148                 HMI_ERROR("wm", "%s", l.err().value());
149             }
150         }
151     }
152     catch (std::exception &e)
153     {
154         HMI_ERROR("wm", "Loading of configuration failed: %s", e.what());
155     }
156 }
157
158 int WindowManager::init()
159 {
160     int ret;
161     if (!this->display->ok())
162     {
163         return -1;
164     }
165
166     if (this->layers.mapping.empty())
167     {
168         HMI_ERROR("wm", "No surface -> layer mapping loaded");
169         return -1;
170     }
171
172     // TODO: application requests by old role,
173     //       so create role map (old, new)
174     // Load old_role.db
175     this->loadOldRoleDb();
176
177     // Store my context for calling callback from PolicyManager
178     g_context = this;
179
180     // Initialize PMWrapper
181     this->pmw.initialize();
182
183     // Register callback to PolicyManager
184     this->pmw.registerCallback(onStateTransitioned, onError);
185
186     // Make afb event
187     for (int i = Event_Val_Min; i <= Event_Val_Max; i++)
188     {
189         map_afb_event[kListEventName[i]] = afb_daemon_make_event(kListEventName[i]);
190     }
191
192     this->display->add_global_handler(
193         "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) {
194             this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
195         });
196
197     this->display->add_global_handler(
198         "ivi_wm", [this](wl_registry *r, uint32_t name, uint32_t v) {
199             this->controller =
200                 std::make_unique<struct compositor::controller>(r, name, v);
201
202             // Init controller hooks
203             this->controller->chooks = &this->chooks;
204
205             // This protocol needs the output, so lets just add our mapping here...
206             this->controller->add_proxy_to_id_mapping(
207                 this->outputs.back()->proxy.get(),
208                 wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
209                     this->outputs.back()->proxy.get())));
210
211             // Create screen
212             this->controller->create_screen(this->outputs.back()->proxy.get());
213
214             // Set display to controller
215             this->controller->display = this->display;
216         });
217
218     // First level objects
219     this->display->roundtrip();
220     // Second level objects
221     this->display->roundtrip();
222     // Third level objects
223     this->display->roundtrip();
224
225     ret = init_layers();
226     return ret;
227 }
228
229 int WindowManager::dispatch_pending_events()
230 {
231     if (this->pop_pending_events())
232     {
233         this->display->dispatch_pending();
234         return 0;
235     }
236     return -1;
237 }
238
239 void WindowManager::set_pending_events()
240 {
241     this->pending_events.store(true, std::memory_order_release);
242 }
243
244 result<int> WindowManager::api_request_surface(char const *appid, char const *drawing_name)
245 {
246     // TODO: application requests by old role,
247     //       so convert role old to new
248     const char *role = this->convertRoleOldToNew(drawing_name);
249
250     auto lid = this->layers.get_layer_id(std::string(role));
251     if (!lid)
252     {
253         /**
254        * register drawing_name as fallback and make it displayed.
255        */
256         lid = this->layers.get_layer_id(std::string("fallback"));
257         HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", role);
258         if (!lid)
259         {
260             return Err<int>("Drawing name does not match any role, Fallback is disabled");
261         }
262     }
263
264     auto rname = this->lookup_id(role);
265     if (!rname)
266     {
267         // name does not exist yet, allocate surface id...
268         auto id = int(this->id_alloc.generate_id(role));
269         this->layers.add_surface(id, *lid);
270
271         // set the main_surface[_name] here and now
272         if (!this->layers.main_surface_name.empty() &&
273             this->layers.main_surface_name == drawing_name)
274         {
275             this->layers.main_surface = id;
276             HMI_DEBUG("wm", "Set main_surface id to %u", id);
277         }
278
279         // add client into the db
280         std::string appid_str(appid);
281         g_app_list.addClient(appid_str, *lid, id, std::string(role));
282
283         // Set role map of (new, old)
284         this->rolenew2old[role] = std::string(drawing_name);
285
286         return Ok<int>(id);
287     }
288
289     // Check currently registered drawing names if it is already there.
290     return Err<int>("Surface already present");
291 }
292
293 char const *WindowManager::api_request_surface(char const *appid, char const *drawing_name,
294                                      char const *ivi_id)
295 {
296     ST();
297
298     // TODO: application requests by old role,
299     //       so convert role old to new
300     const char *role = this->convertRoleOldToNew(drawing_name);
301
302     auto lid = this->layers.get_layer_id(std::string(role));
303     unsigned sid = std::stol(ivi_id);
304
305     if (!lid)
306     {
307         /**
308        * register drawing_name as fallback and make it displayed.
309        */
310         lid = this->layers.get_layer_id(std::string("fallback"));
311         HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", role);
312         if (!lid)
313         {
314             return "Drawing name does not match any role, Fallback is disabled";
315         }
316     }
317
318     auto rname = this->lookup_id(role);
319
320     if (rname)
321     {
322         return "Surface already present";
323     }
324
325     // register pair drawing_name and ivi_id
326     this->id_alloc.register_name_id(role, sid);
327     this->layers.add_surface(sid, *lid);
328
329     // this surface is already created
330     HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", sid, *lid);
331
332     this->controller->layers[*lid]->add_surface(sid);
333     this->layout_commit();
334
335     // add client into the db
336     std::string appid_str(appid);
337     g_app_list.addClient(appid_str, *lid, sid, std::string(role));
338
339     // Set role map of (new, old)
340     this->rolenew2old[role] = std::string(drawing_name);
341
342     return nullptr;
343 }
344
345 /**
346  * This function is substitute of requestSurface
347  * If surface creation is faster than application request of this function,
348  * WM will bind surfaceID with application and role.
349  * If surface creation is slower than application request of thie function,
350  * WM will put Client into pending list.
351  *
352  * Note :
353  * Application can request with pid but this is temporary solution for now.
354  * This will be removed.
355  * */
356 bool WindowManager::api_set_role(char const *appid, char const *drawing_name, unsigned pid){
357     std::string id = appid;
358     std::string role = drawing_name;
359     unsigned surface = 0;
360     WMError wm_err = WMError::UNKNOWN;
361     bool ret = false;
362
363     // get layer ID which role should be in
364     auto lid = this->layers.get_layer_id(role);
365     if (!lid)
366     {
367         /**
368        * register drawing_name as fallback and make it displayed.
369        */
370         lid = this->layers.get_layer_id(std::string("fallback"));
371         HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", role.c_str());
372         if (!lid)
373         {
374             HMI_ERROR("wm", "Drawing name does not match any role, fallback is disabled");
375             return ret;
376         }
377     }
378
379     if(0 != pid){
380         // search floating surfaceID from pid if pid is designated.
381         // It is not good that application request with its pid
382         wm_err = g_app_list.popFloatingSurface(pid, &surface);
383     }
384     else{
385         // get floating surface with appid. If WM queries appid from pid,
386         // WM can bind surface and role with appid(not implemented yet)
387         //wm_err = g_app_list.popFloatingSurface(id);
388     }
389     if(wm_err != WMError::SUCCESS){
390         HMI_ERROR("wm", "No floating surface for app: %s", id.c_str());
391         g_app_list.addFloatingClient(id, *lid, role);
392         HMI_NOTICE("wm", "%s : Waiting for surface creation", id.c_str());
393         return ret;
394     }
395
396     ret = true;
397     if (g_app_list.contains(id))
398     {
399         HMI_INFO("wm", "Add role: %s with surface: %d. Client %s has multi surfaces.",
400                  role.c_str(), surface, id.c_str());
401         wm_err = g_app_list.appendRole(id, role, surface);
402         if(wm_err != WMError::SUCCESS){
403             HMI_INFO("wm", errorDescription(wm_err));
404         }
405     }
406     else{
407         HMI_INFO("wm", "Create new client: %s, surface: %d into layer: %d with role: %s",
408                  id.c_str(), surface, *lid, role.c_str());
409         g_app_list.addClient(id, *lid, surface, role);
410     }
411
412     // register pair drawing_name and ivi_id
413     this->id_alloc.register_name_id(role.c_str(), surface);
414     this->layers.add_surface(surface, *lid);
415
416     // this surface is already created
417     HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", surface, *lid);
418
419     const auto &o_layer = this->layers.get_layer(*lid);
420     auto rect = o_layer.value().rect;
421     if(rect.w < 0)
422     {
423         rect.w = this->controller->output_size.w + 1 + rect.w;
424     }
425     if(rect.h < 0)
426     {
427         rect.h = this->controller->output_size.h + 1 + rect.h;
428     }
429     this->controller->surfaces[surface]->set_source_rectangle(0, 0, rect.w, rect.h);
430
431     this->controller->layers[*lid]->add_surface(surface);
432     this->layout_commit();
433
434     return ret;
435 }
436
437 void WindowManager::api_activate_surface(char const *appid, char const *drawing_name,
438                                char const *drawing_area, const reply_func &reply)
439 {
440     ST();
441
442     // TODO: application requests by old role,
443     //       so convert role old to new
444     const char *c_role = this->convertRoleOldToNew(drawing_name);
445
446     std::string id = appid;
447     std::string role = c_role;
448     std::string area = drawing_area;
449     Task task = Task::TASK_ALLOCATE;
450     unsigned req_num = 0;
451     WMError ret = WMError::UNKNOWN;
452
453     ret = this->setRequest(id, role, area, task, &req_num);
454
455     if(ret != WMError::SUCCESS)
456     {
457         HMI_ERROR("wm", errorDescription(ret));
458         reply("Failed to set request");
459         return;
460     }
461
462     reply(nullptr);
463     if (req_num != g_app_list.currentRequestNumber())
464     {
465         // Add request, then invoked after the previous task is finished
466         HMI_SEQ_DEBUG(req_num, "request is accepted");
467         return;
468     }
469
470     /*
471      * Do allocate tasks
472      */
473     ret = this->doTransition(req_num);
474
475     if (ret != WMError::SUCCESS)
476     {
477         //this->emit_error()
478         HMI_SEQ_ERROR(req_num, errorDescription(ret));
479         g_app_list.removeRequest(req_num);
480         this->processNextRequest();
481     }
482 }
483
484 void WindowManager::api_deactivate_surface(char const *appid, char const *drawing_name,
485                                  const reply_func &reply)
486 {
487     ST();
488
489     // TODO: application requests by old role,
490     //       so convert role old to new
491     const char *c_role = this->convertRoleOldToNew(drawing_name);
492
493     /*
494     * Check Phase
495     */
496     std::string id = appid;
497     std::string role = c_role;
498     std::string area = ""; //drawing_area;
499     Task task = Task::TASK_RELEASE;
500     unsigned req_num = 0;
501     WMError ret = WMError::UNKNOWN;
502
503     ret = this->setRequest(id, role, area, task, &req_num);
504
505     if (ret != WMError::SUCCESS)
506     {
507         HMI_ERROR("wm", errorDescription(ret));
508         reply("Failed to set request");
509         return;
510     }
511
512     reply(nullptr);
513     if (req_num != g_app_list.currentRequestNumber())
514     {
515         // Add request, then invoked after the previous task is finished
516         HMI_SEQ_DEBUG(req_num, "request is accepted");
517         return;
518     }
519
520     /*
521     * Do allocate tasks
522     */
523     ret = this->doTransition(req_num);
524
525     if (ret != WMError::SUCCESS)
526     {
527         //this->emit_error()
528         HMI_SEQ_ERROR(req_num, errorDescription(ret));
529         g_app_list.removeRequest(req_num);
530         this->processNextRequest();
531     }
532 }
533
534 void WindowManager::api_enddraw(char const *appid, char const *drawing_name)
535 {
536     // TODO: application requests by old role,
537     //       so convert role old to new
538     const char *c_role = this->convertRoleOldToNew(drawing_name);
539
540     std::string id = appid;
541     std::string role = c_role;
542     unsigned current_req = g_app_list.currentRequestNumber();
543     bool result = g_app_list.setEndDrawFinished(current_req, id, role);
544
545     if (!result)
546     {
547         HMI_ERROR("wm", "%s is not in transition state", id.c_str());
548         return;
549     }
550
551     if (g_app_list.endDrawFullfilled(current_req))
552     {
553         // do task for endDraw
554         this->stopTimer();
555         WMError ret = this->doEndDraw(current_req);
556
557         if(ret != WMError::SUCCESS)
558         {
559             //this->emit_error();
560
561             // Undo state of PolicyManager
562             this->pmw.undoState();
563         }
564         this->emitScreenUpdated(current_req);
565         HMI_SEQ_INFO(current_req, "Finish request status: %s", errorDescription(ret));
566
567         g_app_list.removeRequest(current_req);
568
569         this->processNextRequest();
570     }
571     else
572     {
573         HMI_SEQ_INFO(current_req, "Wait other App call endDraw");
574         return;
575     }
576 }
577
578 result<json_object *> WindowManager::api_get_display_info()
579 {
580     // Check controller
581     if (!this->controller)
582     {
583         return Err<json_object *>("ivi_controller global not available");
584     }
585
586     // Set display info
587     compositor::size o_size = this->controller->output_size;
588     compositor::size p_size = this->controller->physical_size;
589
590     json_object *object = json_object_new_object();
591     json_object_object_add(object, kKeyWidthPixel, json_object_new_int(o_size.w));
592     json_object_object_add(object, kKeyHeightPixel, json_object_new_int(o_size.h));
593     json_object_object_add(object, kKeyWidthMm, json_object_new_int(p_size.w));
594     json_object_object_add(object, kKeyHeightMm, json_object_new_int(p_size.h));
595
596     return Ok<json_object *>(object);
597 }
598
599 result<json_object *> WindowManager::api_get_area_info(char const *drawing_name)
600 {
601     HMI_DEBUG("wm", "called");
602
603     // TODO: application requests by old role,
604     //       so convert role old to new
605     const char *role = this->convertRoleOldToNew(drawing_name);
606
607     // Check drawing name, surface/layer id
608     auto const &surface_id = this->lookup_id(role);
609     if (!surface_id)
610     {
611         return Err<json_object *>("Surface does not exist");
612     }
613
614     if (!this->controller->surface_exists(*surface_id))
615     {
616         return Err<json_object *>("Surface does not exist in controller!");
617     }
618
619     auto layer_id = this->layers.get_layer_id(*surface_id);
620     if (!layer_id)
621     {
622         return Err<json_object *>("Surface is not on any layer!");
623     }
624
625     // Set area rectangle
626     compositor::rect area_info = this->area_info[*surface_id];
627     json_object *object = json_object_new_object();
628     json_object_object_add(object, kKeyX, json_object_new_int(area_info.x));
629     json_object_object_add(object, kKeyY, json_object_new_int(area_info.y));
630     json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w));
631     json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h));
632
633     return Ok<json_object *>(object);
634 }
635
636 void WindowManager::api_ping() { this->dispatch_pending_events(); }
637
638 void WindowManager::send_event(char const *evname, char const *label)
639 {
640     HMI_DEBUG("wm", "%s: %s(%s)", __func__, evname, label);
641
642     json_object *j = json_object_new_object();
643     json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
644
645     int ret = afb_event_push(this->map_afb_event[evname], j);
646     if (ret != 0)
647     {
648         HMI_DEBUG("wm", "afb_event_push failed: %m");
649     }
650 }
651
652 void WindowManager::send_event(char const *evname, char const *label, char const *area,
653                      int x, int y, int w, int h)
654 {
655     HMI_DEBUG("wm", "%s: %s(%s, %s) x:%d y:%d w:%d h:%d",
656               __func__, evname, label, area, x, y, w, h);
657
658     json_object *j_rect = json_object_new_object();
659     json_object_object_add(j_rect, kKeyX, json_object_new_int(x));
660     json_object_object_add(j_rect, kKeyY, json_object_new_int(y));
661     json_object_object_add(j_rect, kKeyWidth, json_object_new_int(w));
662     json_object_object_add(j_rect, kKeyHeight, json_object_new_int(h));
663
664     json_object *j = json_object_new_object();
665     json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
666     json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area));
667     json_object_object_add(j, kKeyDrawingRect, j_rect);
668
669     int ret = afb_event_push(this->map_afb_event[evname], j);
670     if (ret != 0)
671     {
672         HMI_DEBUG("wm", "afb_event_push failed: %m");
673     }
674 }
675
676 /**
677  * proxied events
678  */
679 void WindowManager::surface_created(uint32_t surface_id)
680 {
681     auto layer_id = this->layers.get_layer_id(surface_id);
682     if (!layer_id)
683     {
684         HMI_DEBUG("wm", "Newly created surfce %d is not associated with any layer!",
685                   surface_id);
686         return;
687     }
688
689     HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", surface_id, *layer_id);
690
691     this->controller->layers[*layer_id]->add_surface(surface_id);
692     this->layout_commit();
693 }
694
695 void WindowManager::surface_removed(uint32_t surface_id)
696 {
697     HMI_DEBUG("wm", "surface_id is %u", surface_id);
698     g_app_list.removeSurface(surface_id);
699 }
700
701 void WindowManager::removeClient(const std::string &appid)
702 {
703     HMI_DEBUG("wm", "Remove clinet %s from list", appid.c_str());
704     g_app_list.removeClient(appid);
705 }
706
707 void WindowManager::exceptionProcessForTransition()
708 {
709     unsigned req_num = g_app_list.currentRequestNumber();
710     HMI_SEQ_NOTICE(req_num, "Process exception handling for request. Remove current request %d", req_num);
711     g_app_list.removeRequest(req_num);
712     HMI_SEQ_NOTICE(g_app_list.currentRequestNumber(), "Process next request if exists");
713     this->processNextRequest();
714 }
715
716 void WindowManager::timerHandler()
717 {
718     unsigned req_num = g_app_list.currentRequestNumber();
719     HMI_SEQ_DEBUG(req_num, "Timer expired remove Request");
720     g_app_list.reqDump();
721     g_app_list.removeRequest(req_num);
722     this->processNextRequest();
723 }
724
725 void WindowManager::startTransitionWrapper(std::vector<WMAction> &actions)
726 {
727     WMError ret;
728     unsigned req_num = g_app_list.currentRequestNumber();
729
730     if (actions.empty())
731     {
732         if (g_app_list.haveRequest())
733         {
734             HMI_SEQ_DEBUG(req_num, "There is no WMAction for this request");
735             goto proc_remove_request;
736         }
737         else
738         {
739             HMI_SEQ_DEBUG(req_num, "There is no request");
740             return;
741         }
742     }
743
744     for (auto &act : actions)
745     {
746         if ("" != act.role)
747         {
748             bool found;
749             auto const &surface_id = this->lookup_id(act.role.c_str());
750             std::string appid = g_app_list.getAppID(*surface_id, act.role, &found);
751             if (!found)
752             {
753                 goto error;
754             }
755             act.appid = appid;
756         }
757
758         ret = g_app_list.setAction(req_num, act);
759         if (ret != WMError::SUCCESS)
760         {
761             goto error;
762         }
763     }
764
765     HMI_SEQ_DEBUG(req_num, "Start transition.");
766     ret = this->startTransition(req_num);
767     if (ret != WMError::SUCCESS)
768     {
769         if (ret == WMError::NO_LAYOUT_CHANGE)
770         {
771             goto proc_remove_request;
772         }
773         else
774         {
775             goto error;
776         }
777     }
778
779     return;
780
781 error:
782     //this->emit_error()
783     HMI_SEQ_ERROR(req_num, errorDescription(ret));
784     this->pmw.undoState();
785
786 proc_remove_request:
787     g_app_list.removeRequest(req_num);
788     this->processNextRequest();
789 }
790
791 void WindowManager::processError(WMError error)
792 {
793     unsigned req_num = g_app_list.currentRequestNumber();
794
795     //this->emit_error()
796     HMI_SEQ_ERROR(req_num, errorDescription(error));
797     g_app_list.removeRequest(req_num);
798     this->processNextRequest();
799 }
800
801 /*
802  ******* Private Functions *******
803  */
804
805 bool WindowManager::pop_pending_events()
806 {
807     bool x{true};
808     return this->pending_events.compare_exchange_strong(
809         x, false, std::memory_order_consume);
810 }
811
812 optional<int> WindowManager::lookup_id(char const *name)
813 {
814     return this->id_alloc.lookup(std::string(name));
815 }
816 optional<std::string> WindowManager::lookup_name(int id)
817 {
818     return this->id_alloc.lookup(id);
819 }
820
821 /**
822  * init_layers()
823  */
824 int WindowManager::init_layers()
825 {
826     if (!this->controller)
827     {
828         HMI_ERROR("wm", "ivi_controller global not available");
829         return -1;
830     }
831
832     if (this->outputs.empty())
833     {
834         HMI_ERROR("wm", "no output was set up!");
835         return -1;
836     }
837
838     WMConfig wm_config;
839     wm_config.loadConfigs();
840
841     auto &c = this->controller;
842
843     auto &o = this->outputs.front();
844     auto &s = c->screens.begin()->second;
845     auto &layers = c->layers;
846
847     this->layers.loadAreaDb();
848     const compositor::rect base = this->layers.getAreaSize("fullscreen");
849
850     const std::string aspect_setting = wm_config.getConfigAspect();
851     const compositor::rect scale_rect =
852         this->layers.getScaleDestRect(o->width, o->height, aspect_setting);
853
854     // Write output dimensions to ivi controller...
855     c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)};
856     c->physical_size = compositor::size{uint32_t(o->physical_width),
857                                         uint32_t(o->physical_height)};
858
859     // Clear scene
860     layers.clear();
861
862     // Clear screen
863     s->clear();
864
865     // Quick and dirty setup of layers
866     for (auto const &i : this->layers.mapping)
867     {
868         c->layer_create(i.second.layer_id, scale_rect.w, scale_rect.h);
869         auto &l = layers[i.second.layer_id];
870         l->set_source_rectangle(0, 0, base.w, base.h);
871         l->set_destination_rectangle(
872             scale_rect.x, scale_rect.y, scale_rect.w, scale_rect.h);
873         l->set_visibility(1);
874         HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"",
875                   i.second.name.c_str(), i.second.layer_id, i.second.role.c_str());
876     }
877
878     // Add layers to screen
879     s->set_render_order(this->layers.layers);
880
881     this->layout_commit();
882
883     return 0;
884 }
885
886 void WindowManager::surface_set_layout(int surface_id, const std::string& area)
887 {
888     if (!this->controller->surface_exists(surface_id))
889     {
890         HMI_ERROR("wm", "Surface %d does not exist", surface_id);
891         return;
892     }
893
894     auto o_layer_id = this->layers.get_layer_id(surface_id);
895
896     if (!o_layer_id)
897     {
898         HMI_ERROR("wm", "Surface %d is not associated with any layer!", surface_id);
899         return;
900     }
901
902     uint32_t layer_id = *o_layer_id;
903
904     auto const &layer = this->layers.get_layer(layer_id);
905     auto rect = this->layers.getAreaSize(area);
906     HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "%s : x:%d y:%d w:%d h:%d", area.c_str(),
907                     rect.x, rect.y, rect.w, rect.h);
908     auto &s = this->controller->surfaces[surface_id];
909
910     int x = rect.x;
911     int y = rect.y;
912     int w = rect.w;
913     int h = rect.h;
914
915     HMI_DEBUG("wm", "surface_set_layout for surface %u on layer %u", surface_id,
916               layer_id);
917
918     // set destination to the display rectangle
919     s->set_destination_rectangle(x, y, w, h);
920
921     // update area information
922     this->area_info[surface_id].x = x;
923     this->area_info[surface_id].y = y;
924     this->area_info[surface_id].w = w;
925     this->area_info[surface_id].h = h;
926
927     HMI_DEBUG("wm", "Surface %u now on layer %u with rect { %d, %d, %d, %d }",
928               surface_id, layer_id, x, y, w, h);
929 }
930
931 void WindowManager::layout_commit()
932 {
933     this->controller->commit_changes();
934     this->display->flush();
935 }
936
937 void WindowManager::emit_activated(char const *label)
938 {
939     this->send_event(kListEventName[Event_Active], label);
940 }
941
942 void WindowManager::emit_deactivated(char const *label)
943 {
944     this->send_event(kListEventName[Event_Inactive], label);
945 }
946
947 void WindowManager::emit_syncdraw(char const *label, char const *area, int x, int y, int w, int h)
948 {
949     this->send_event(kListEventName[Event_SyncDraw], label, area, x, y, w, h);
950 }
951
952 void WindowManager::emit_syncdraw(const std::string &role, const std::string &area)
953 {
954     compositor::rect rect = this->layers.getAreaSize(area);
955     this->send_event(kListEventName[Event_SyncDraw],
956         role.c_str(), area.c_str(), rect.x, rect.y, rect.w, rect.h);
957 }
958
959 void WindowManager::emit_flushdraw(char const *label)
960 {
961     this->send_event(kListEventName[Event_FlushDraw], label);
962 }
963
964 void WindowManager::emit_visible(char const *label, bool is_visible)
965 {
966     this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], label);
967 }
968
969 void WindowManager::emit_invisible(char const *label)
970 {
971     return emit_visible(label, false);
972 }
973
974 void WindowManager::emit_visible(char const *label) { return emit_visible(label, true); }
975
976 void WindowManager::activate(int id)
977 {
978     auto ip = this->controller->sprops.find(id);
979     if (ip != this->controller->sprops.end())
980     {
981         this->controller->surfaces[id]->set_visibility(1);
982         char const *label =
983             this->lookup_name(id).value_or("unknown-name").c_str();
984
985          // FOR CES DEMO >>>
986         if ((0 == strcmp(label, "radio")) ||
987             (0 == strcmp(label, "music")) ||
988             (0 == strcmp(label, "video")) ||
989             (0 == strcmp(label, "map")))
990         {
991             for (auto i = surface_bg.begin(); i != surface_bg.end(); ++i)
992             {
993                 if (id == *i)
994                 {
995                     // Remove id
996                     this->surface_bg.erase(i);
997
998                     // Remove from BG layer (999)
999                     HMI_DEBUG("wm", "Remove %s(%d) from BG layer", label, id);
1000                     this->controller->layers[999]->remove_surface(id);
1001
1002                     // Add to FG layer (1001)
1003                     HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id);
1004                     this->controller->layers[1001]->add_surface(id);
1005
1006                     for (int j : this->surface_bg)
1007                     {
1008                         HMI_DEBUG("wm", "Stored id:%d", j);
1009                     }
1010                     break;
1011                 }
1012             }
1013         }
1014         // <<< FOR CES DEMO
1015
1016         this->layout_commit();
1017
1018         // TODO: application requests by old role,
1019         //       so convert role new to old for emitting event
1020         const char* old_role = this->rolenew2old[label].c_str();
1021
1022         this->emit_visible(old_role);
1023         this->emit_activated(old_role);
1024     }
1025 }
1026
1027 void WindowManager::deactivate(int id)
1028 {
1029     auto ip = this->controller->sprops.find(id);
1030     if (ip != this->controller->sprops.end())
1031     {
1032         char const *label =
1033             this->lookup_name(id).value_or("unknown-name").c_str();
1034
1035         // FOR CES DEMO >>>
1036         if ((0 == strcmp(label, "radio")) ||
1037             (0 == strcmp(label, "music")) ||
1038             (0 == strcmp(label, "video")) ||
1039             (0 == strcmp(label, "map")))
1040         {
1041
1042             // Store id
1043             this->surface_bg.push_back(id);
1044
1045             // Remove from FG layer (1001)
1046             HMI_DEBUG("wm", "Remove %s(%d) from FG layer", label, id);
1047             this->controller->layers[1001]->remove_surface(id);
1048
1049             // Add to BG layer (999)
1050             HMI_DEBUG("wm", "Add %s(%d) to BG layer", label, id);
1051             this->controller->layers[999]->add_surface(id);
1052
1053             for (int j : surface_bg)
1054             {
1055                 HMI_DEBUG("wm", "Stored id:%d", j);
1056             }
1057         }
1058         else
1059         {
1060             this->controller->surfaces[id]->set_visibility(0);
1061         }
1062         // <<< FOR CES DEMO
1063
1064         this->layout_commit();
1065
1066         // TODO: application requests by old role,
1067         //       so convert role new to old for emitting event
1068         const char* old_role = this->rolenew2old[label].c_str();
1069
1070         this->emit_deactivated(old_role);
1071         this->emit_invisible(old_role);
1072     }
1073 }
1074
1075 WMError WindowManager::setRequest(const std::string& appid, const std::string &role, const std::string &area,
1076                             Task task, unsigned* req_num)
1077 {
1078     if (!g_app_list.contains(appid))
1079     {
1080         return WMError::NOT_REGISTERED;
1081     }
1082
1083     auto client = g_app_list.lookUpClient(appid);
1084
1085     /*
1086      * Queueing Phase
1087      */
1088     unsigned current = g_app_list.currentRequestNumber();
1089     unsigned requested_num = g_app_list.getRequestNumber(appid);
1090     if (requested_num != 0)
1091     {
1092         HMI_SEQ_INFO(requested_num,
1093             "%s %s %s request is already queued", appid.c_str(), role.c_str(), area.c_str());
1094         return REQ_REJECTED;
1095     }
1096
1097     WMRequest req = WMRequest(appid, role, area, task);
1098     unsigned new_req = g_app_list.addRequest(req);
1099     *req_num = new_req;
1100     g_app_list.reqDump();
1101
1102     HMI_SEQ_DEBUG(current, "%s start sequence with %s, %s", appid.c_str(), role.c_str(), area.c_str());
1103
1104     return WMError::SUCCESS;
1105 }
1106
1107 WMError WindowManager::doTransition(unsigned req_num)
1108 {
1109     HMI_SEQ_DEBUG(req_num, "check policy");
1110     WMError ret = this->checkPolicy(req_num);
1111     return ret;
1112 }
1113
1114 WMError WindowManager::checkPolicy(unsigned req_num)
1115 {
1116     /*
1117     * Check Policy
1118     */
1119     // get current trigger
1120     bool found = false;
1121     WMError ret = WMError::LAYOUT_CHANGE_FAIL;
1122     auto trigger = g_app_list.getRequest(req_num, &found);
1123     if (!found)
1124     {
1125         ret = WMError::NO_ENTRY;
1126         return ret;
1127     }
1128     std::string req_area = trigger.area;
1129
1130     if (trigger.task == Task::TASK_ALLOCATE)
1131     {
1132         const char *msg = this->check_surface_exist(trigger.role.c_str());
1133
1134         if (msg)
1135         {
1136             HMI_SEQ_ERROR(req_num, msg);
1137             return ret;
1138         }
1139     }
1140
1141     // Input event data to PolicyManager
1142     if (0 > this->pmw.setInputEventData(trigger.task, trigger.role, trigger.area))
1143     {
1144         HMI_SEQ_ERROR(req_num, "Failed to set input event data to PolicyManager");
1145         return ret;
1146     }
1147
1148     // Execute state transition of PolicyManager
1149     if (0 > this->pmw.executeStateTransition())
1150     {
1151         HMI_SEQ_ERROR(req_num, "Failed to execute state transition of PolicyManager");
1152         return ret;
1153     }
1154
1155     ret = WMError::SUCCESS;
1156
1157     g_app_list.reqDump();
1158
1159     return ret;
1160 }
1161
1162 WMError WindowManager::startTransition(unsigned req_num)
1163 {
1164     bool sync_draw_happen = false;
1165     bool found = false;
1166     WMError ret = WMError::SUCCESS;
1167     auto actions = g_app_list.getActions(req_num, &found);
1168     if (!found)
1169     {
1170         ret = WMError::NO_ENTRY;
1171         HMI_SEQ_ERROR(req_num,
1172             "Window Manager bug :%s : Action is not set", errorDescription(ret));
1173         return ret;
1174     }
1175
1176     for (const auto &action : actions)
1177     {
1178         if (action.visible == TaskVisible::VISIBLE)
1179         {
1180             sync_draw_happen = true;
1181
1182             // TODO: application requests by old role,
1183             //       so convert role new to old for emitting event
1184             std::string old_role = this->rolenew2old[action.role];
1185
1186             this->emit_syncdraw(old_role, action.area);
1187             /* TODO: emit event for app not subscriber
1188             if(g_app_list.contains(y.appid))
1189                 g_app_list.lookUpClient(y.appid)->emit_syncdraw(y.role, y.area); */
1190         }
1191     }
1192
1193     if (sync_draw_happen)
1194     {
1195         this->setTimer();
1196     }
1197     else
1198     {
1199         // deactivate only, no syncDraw
1200         // Make it deactivate here
1201         for (const auto &x : actions)
1202         {
1203             if (g_app_list.contains(x.appid))
1204             {
1205                 auto client = g_app_list.lookUpClient(x.appid);
1206                 this->deactivate(client->surfaceID(x.role));
1207             }
1208         }
1209         ret = WMError::NO_LAYOUT_CHANGE;
1210     }
1211     return ret;
1212 }
1213
1214 WMError WindowManager::doEndDraw(unsigned req_num)
1215 {
1216     // get actions
1217     bool found;
1218     auto actions = g_app_list.getActions(req_num, &found);
1219     WMError ret = WMError::SUCCESS;
1220     if (!found)
1221     {
1222         ret = WMError::NO_ENTRY;
1223         return ret;
1224     }
1225
1226     HMI_SEQ_INFO(req_num, "do endDraw");
1227
1228     // layout change and make it visible
1229     for (const auto &act : actions)
1230     {
1231         if(act.visible != TaskVisible::NO_CHANGE)
1232         {
1233             // layout change
1234             if(!g_app_list.contains(act.appid)){
1235                 ret = WMError::NOT_REGISTERED;
1236             }
1237             ret = this->layoutChange(act);
1238             if(ret != WMError::SUCCESS)
1239             {
1240                 HMI_SEQ_WARNING(req_num,
1241                     "Failed to manipulate surfaces while state change : %s", errorDescription(ret));
1242                 return ret;
1243             }
1244             ret = this->visibilityChange(act);
1245             if (ret != WMError::SUCCESS)
1246             {
1247                 HMI_SEQ_WARNING(req_num,
1248                     "Failed to manipulate surfaces while state change : %s", errorDescription(ret));
1249                 return ret;
1250             }
1251             HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str());
1252             //this->lm_enddraw(act.role.c_str());
1253         }
1254     }
1255
1256     HMI_SEQ_INFO(req_num, "emit flushDraw");
1257
1258     for(const auto &act_flush : actions)
1259     {
1260         if(act_flush.visible == TaskVisible::VISIBLE)
1261         {
1262             // TODO: application requests by old role,
1263             //       so convert role new to old for emitting event
1264             std::string old_role = this->rolenew2old[act_flush.role];
1265
1266             this->emit_flushdraw(old_role.c_str());
1267         }
1268     }
1269
1270     return ret;
1271 }
1272
1273 WMError WindowManager::layoutChange(const WMAction &action)
1274 {
1275     if (action.visible == TaskVisible::INVISIBLE)
1276     {
1277         // Visibility is not change -> no redraw is required
1278         return WMError::SUCCESS;
1279     }
1280     auto client = g_app_list.lookUpClient(action.appid);
1281     unsigned surface = client->surfaceID(action.role);
1282     if (surface == 0)
1283     {
1284         HMI_SEQ_ERROR(g_app_list.currentRequestNumber(),
1285                       "client doesn't have surface with role(%s)", action.role.c_str());
1286         return WMError::NOT_REGISTERED;
1287     }
1288     // Layout Manager
1289     WMError ret = this->setSurfaceSize(surface, action.area);
1290     return ret;
1291 }
1292
1293 WMError WindowManager::visibilityChange(const WMAction &action)
1294 {
1295     HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "Change visibility");
1296     if(!g_app_list.contains(action.appid)){
1297         return WMError::NOT_REGISTERED;
1298     }
1299     auto client = g_app_list.lookUpClient(action.appid);
1300     unsigned surface = client->surfaceID(action.role);
1301     if(surface == 0)
1302     {
1303         HMI_SEQ_ERROR(g_app_list.currentRequestNumber(),
1304                       "client doesn't have surface with role(%s)", action.role.c_str());
1305         return WMError::NOT_REGISTERED;
1306     }
1307
1308     if (action.visible != TaskVisible::INVISIBLE)
1309     {
1310         this->activate(surface); // Layout Manager task
1311     }
1312     else
1313     {
1314         this->deactivate(surface); // Layout Manager task
1315     }
1316     return WMError::SUCCESS;
1317 }
1318
1319 WMError WindowManager::setSurfaceSize(unsigned surface, const std::string &area)
1320 {
1321     this->surface_set_layout(surface, area);
1322
1323     return WMError::SUCCESS;
1324 }
1325
1326 void WindowManager::emitScreenUpdated(unsigned req_num)
1327 {
1328     // Get visible apps
1329     HMI_SEQ_DEBUG(req_num, "emit screen updated");
1330     bool found = false;
1331     auto actions = g_app_list.getActions(req_num, &found);
1332
1333     // create json object
1334     json_object *j = json_object_new_object();
1335     json_object *jarray = json_object_new_array();
1336
1337     for(const auto& action: actions)
1338     {
1339         if(action.visible != TaskVisible::INVISIBLE)
1340         {
1341             json_object_array_add(jarray, json_object_new_string(action.appid.c_str()));
1342         }
1343     }
1344     json_object_object_add(j, kKeyIds, jarray);
1345     HMI_SEQ_INFO(req_num, "Visible app: %s", json_object_get_string(j));
1346
1347     int ret = afb_event_push(
1348         this->map_afb_event[kListEventName[Event_ScreenUpdated]], j);
1349     if (ret != 0)
1350     {
1351         HMI_DEBUG("wm", "afb_event_push failed: %m");
1352     }
1353     json_object_put(jarray);
1354 }
1355
1356 void WindowManager::setTimer()
1357 {
1358     HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "Timer set activate");
1359     if (g_timer_ev_src == nullptr)
1360     {
1361         // firsttime set into sd_event
1362         int ret = sd_event_add_time(afb_daemon_get_event_loop(), &g_timer_ev_src,
1363             CLOCK_REALTIME, time(NULL) * (1000000UL) + kTimeOut, 1, processTimerHandler, this);
1364         if (ret < 0)
1365         {
1366             HMI_ERROR("wm", "Could't set timer");
1367         }
1368     }
1369     else
1370     {
1371         // update timer limitation after second time
1372         sd_event_source_set_time(g_timer_ev_src, time(NULL) * (1000000UL) + kTimeOut);
1373         sd_event_source_set_enabled(g_timer_ev_src, SD_EVENT_ONESHOT);
1374     }
1375 }
1376
1377 void WindowManager::stopTimer()
1378 {
1379     unsigned req_num = g_app_list.currentRequestNumber();
1380     HMI_SEQ_DEBUG(req_num, "Timer stop");
1381     int rc = sd_event_source_set_enabled(g_timer_ev_src, SD_EVENT_OFF);
1382     if (rc < 0)
1383     {
1384         HMI_SEQ_ERROR(req_num, "Timer stop failed");
1385     }
1386 }
1387
1388 void WindowManager::processNextRequest()
1389 {
1390     g_app_list.next();
1391     g_app_list.reqDump();
1392     unsigned req_num = g_app_list.currentRequestNumber();
1393     if (g_app_list.haveRequest())
1394     {
1395         HMI_SEQ_DEBUG(req_num, "Process next request");
1396         WMError rc = doTransition(req_num);
1397         if (rc != WMError::SUCCESS)
1398         {
1399             HMI_SEQ_ERROR(req_num, errorDescription(rc));
1400         }
1401     }
1402     else
1403     {
1404         HMI_SEQ_DEBUG(req_num, "Nothing Request. Waiting Request");
1405     }
1406 }
1407
1408 const char* WindowManager::convertRoleOldToNew(char const *old_role)
1409 {
1410     const char *new_role = nullptr;
1411
1412     for (auto const &on : this->roleold2new)
1413     {
1414         std::regex regex = std::regex(on.first);
1415         if (std::regex_match(old_role, regex))
1416         {
1417             // role is old. So convert to new.
1418             new_role = on.second.c_str();
1419             break;
1420         }
1421     }
1422
1423     if (nullptr == new_role)
1424     {
1425         // role is new or fallback.
1426         new_role = old_role;
1427     }
1428
1429     HMI_DEBUG("wm", "old:%s -> new:%s", old_role, new_role);
1430
1431     return new_role;
1432 }
1433
1434 int WindowManager::loadOldRoleDb()
1435 {
1436     // Get afm application installed dir
1437     char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR");
1438     HMI_DEBUG("wm", "afm_app_install_dir:%s", afm_app_install_dir);
1439
1440     std::string file_name;
1441     if (!afm_app_install_dir)
1442     {
1443         HMI_ERROR("wm", "AFM_APP_INSTALL_DIR is not defined");
1444     }
1445     else
1446     {
1447         file_name = std::string(afm_app_install_dir) + std::string("/etc/old_roles.db");
1448     }
1449
1450     // Load old_role.db
1451     json_object* json_obj;
1452     int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj);
1453     if (0 > ret)
1454     {
1455         HMI_ERROR("wm", "Could not open old_role.db, so use default old_role information");
1456         json_obj = json_tokener_parse(kDefaultOldRoleDb);
1457     }
1458     HMI_DEBUG("wm", "json_obj dump:%s", json_object_get_string(json_obj));
1459
1460     // Perse apps
1461     json_object* json_cfg;
1462     if (!json_object_object_get_ex(json_obj, "old_roles", &json_cfg))
1463     {
1464         HMI_ERROR("wm", "Parse Error!!");
1465         return -1;
1466     }
1467
1468     int len = json_object_array_length(json_cfg);
1469     HMI_DEBUG("wm", "json_cfg len:%d", len);
1470     HMI_DEBUG("wm", "json_cfg dump:%s", json_object_get_string(json_cfg));
1471
1472     for (int i=0; i<len; i++)
1473     {
1474         json_object* json_tmp = json_object_array_get_idx(json_cfg, i);
1475
1476         const char* old_role = jh::getStringFromJson(json_tmp, "name");
1477         if (nullptr == old_role)
1478         {
1479             HMI_ERROR("wm", "Parse Error!!");
1480             return -1;
1481         }
1482
1483         const char* new_role = jh::getStringFromJson(json_tmp, "new");
1484         if (nullptr == new_role)
1485         {
1486             HMI_ERROR("wm", "Parse Error!!");
1487             return -1;
1488         }
1489
1490         this->roleold2new[old_role] = std::string(new_role);
1491     }
1492
1493     // Check
1494     for(auto itr = this->roleold2new.begin();
1495       itr != this->roleold2new.end(); ++itr)
1496     {
1497         HMI_DEBUG("wm", ">>> role old:%s new:%s",
1498                   itr->first.c_str(), itr->second.c_str());
1499     }
1500
1501     // Release json_object
1502     json_object_put(json_obj);
1503
1504     return 0;
1505 }
1506
1507 const char *WindowManager::check_surface_exist(const char *drawing_name)
1508 {
1509     auto const &surface_id = this->lookup_id(drawing_name);
1510     if (!surface_id)
1511     {
1512         return "Surface does not exist";
1513     }
1514
1515     if (!this->controller->surface_exists(*surface_id))
1516     {
1517         return "Surface does not exist in controller!";
1518     }
1519
1520     auto layer_id = this->layers.get_layer_id(*surface_id);
1521
1522     if (!layer_id)
1523     {
1524         return "Surface is not on any layer!";
1525     }
1526
1527     HMI_DEBUG("wm", "surface %d is detected", *surface_id);
1528     return nullptr;
1529 }
1530
1531 const char* WindowManager::kDefaultOldRoleDb = "{ \
1532     \"old_roles\": [ \
1533         { \
1534             \"name\": \"HomeScreen\", \
1535             \"new\": \"homescreen\" \
1536         }, \
1537         { \
1538             \"name\": \"Music\", \
1539             \"new\": \"music\" \
1540         }, \
1541         { \
1542             \"name\": \"MediaPlayer\", \
1543             \"new\": \"music\" \
1544         }, \
1545         { \
1546             \"name\": \"Video\", \
1547             \"new\": \"video\" \
1548         }, \
1549         { \
1550             \"name\": \"VideoPlayer\", \
1551             \"new\": \"video\" \
1552         }, \
1553         { \
1554             \"name\": \"WebBrowser\", \
1555             \"new\": \"browser\" \
1556         }, \
1557         { \
1558             \"name\": \"Radio\", \
1559             \"new\": \"radio\" \
1560         }, \
1561         { \
1562             \"name\": \"Phone\", \
1563             \"new\": \"phone\" \
1564         }, \
1565         { \
1566             \"name\": \"Navigation\", \
1567             \"new\": \"map\" \
1568         }, \
1569         { \
1570             \"name\": \"HVAC\", \
1571             \"new\": \"hvac\" \
1572         }, \
1573         { \
1574             \"name\": \"Settings\", \
1575             \"new\": \"settings\" \
1576         }, \
1577         { \
1578             \"name\": \"Dashboard\", \
1579             \"new\": \"dashboard\" \
1580         }, \
1581         { \
1582             \"name\": \"POI\", \
1583             \"new\": \"poi\" \
1584         }, \
1585         { \
1586             \"name\": \"Mixer\", \
1587             \"new\": \"mixer\" \
1588         }, \
1589         { \
1590             \"name\": \"Restriction\", \
1591             \"new\": \"restriction\" \
1592         }, \
1593         { \
1594             \"name\": \"^OnScreen.*\", \
1595             \"new\": \"on_screen\" \
1596         } \
1597     ] \
1598 }";
1599
1600 /**
1601  * controller_hooks
1602  */
1603 void controller_hooks::surface_created(uint32_t surface_id)
1604 {
1605     this->app->surface_created(surface_id);
1606 }
1607
1608 void controller_hooks::surface_removed(uint32_t surface_id)
1609 {
1610     this->app->surface_removed(surface_id);
1611 }
1612
1613 void controller_hooks::surface_visibility(uint32_t /*surface_id*/,
1614                                           uint32_t /*v*/) {}
1615
1616 void controller_hooks::surface_destination_rectangle(uint32_t /*surface_id*/,
1617                                                      uint32_t /*x*/,
1618                                                      uint32_t /*y*/,
1619                                                      uint32_t /*w*/,
1620                                                      uint32_t /*h*/) {}
1621
1622 } // namespace wm