Revert "Corresponding to TizenIVI3.0 M14.3, GENIVI-LayerManagement was used instead...
[profile/ivi/ico-uxf-homescreen.git] / lib / system-controller / CicoSCWindowController.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 //==========================================================================
11 /**
12  *  @file   CicoSCWindowController.cpp
13  *
14  *  @brief  This file implementation of CicoSCWindowController class
15  */
16 //==========================================================================
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <signal.h>
23 #include <errno.h>
24 #include <sys/types.h>
25 #include <sys/ioctl.h>
26 #include <sys/stat.h>
27 #include <fcntl.h>
28
29 #include <vector>
30 #include <algorithm>
31 using namespace std;
32
33 #include "CicoSCWindow.h"
34 #include "CicoSCWayland.h"
35 #include "CicoSCWindowController.h"
36 #include "CicoLog.h"
37
38 #include "CicoSystemConfig.h"
39 #include "CicoConf.h"
40 #include "CicoSCDisplay.h"
41 #include "CicoSCLayer.h"
42 #include "CicoSCDisplayZone.h"
43 #include "ico_syc_error.h"
44 #include "ico_syc_type.h"
45 #include "ico_syc_winctl.h"
46 #include "CicoSCCommand.h"
47 #include "ico_syc_msg_cmd_def.h"
48 #include "CicoSCServer.h"
49 #include "CicoSCMessage.h"
50 #include "CicoSCMessageRes.h"
51 #include "CicoSCLifeCycleController.h"
52 #include "CicoSCResourceManager.h"
53
54 //==========================================================================
55 //  private static variable
56 //==========================================================================
57 CicoSCWindowController* CicoSCWindowController::ms_myInstance = NULL;
58
59 //--------------------------------------------------------------------------
60 /**
61  *  @brief  get instance of CicoSCWindowController
62  *
63  *  @return instance of CicoSCWindowController
64  */
65 //--------------------------------------------------------------------------
66 CicoSCWindowController*
67 CicoSCWindowController::getInstance(void)
68 {
69     if (NULL == ms_myInstance) {
70         ms_myInstance = new CicoSCWindowController();
71     }
72     return ms_myInstance;
73 }
74
75 //--------------------------------------------------------------------------
76 /**
77  *  @brief  default constructor
78  */
79 //--------------------------------------------------------------------------
80 CicoSCWindowController::CicoSCWindowController()
81     : m_resMgr(NULL), m_physicalDisplayTotal(0)
82 {
83     CicoSCWayland* wayland = CicoSCWayland::getInstance();
84     wayland->getInstance()->addWaylandIF(ICO_WL_WIN_MGR_IF, this);
85     wayland->getInstance()->addWaylandIF(ICO_WL_IVI_APPLICATION_IF, this);
86     wayland->getInstance()->addWaylandIF(ICO_WL_IVI_CONTROLLER_IF, this);
87     wayland->getInstance()->addWaylandIF(ICO_WL_OUTPUT_IF, this);
88     initDB();
89
90     CicoSCWindowController::ms_myInstance = this;
91 }
92
93 //--------------------------------------------------------------------------
94 /**
95  *  @brief  destructor
96  */
97 //--------------------------------------------------------------------------
98 CicoSCWindowController::~CicoSCWindowController()
99 {
100     CicoSCWindowController::ms_myInstance = NULL;
101 }
102
103 //--------------------------------------------------------------------------
104 /**
105  *  @brief  initialize display and window database
106  */
107 //--------------------------------------------------------------------------
108 int
109 CicoSCWindowController::initDB(void)
110 {
111     ICO_TRA("CicoSCWindowController::initDB: Enter");
112
113     const vector<CicoSCDisplayConf*>& displayList =
114             CicoSystemConfig::getInstance()->getDisplayConfList();
115     vector<CicoSCDisplayConf*>::const_iterator itr;
116     itr = displayList.begin();
117     for (; itr != displayList.end(); ++itr) {
118         CicoSCDisplay *display = new CicoSCDisplay();
119         display->displayid = (*itr)->id;
120         display->type      = (*itr)->type;
121         display->nodeid    = (*itr)->node;
122         display->displayno = (*itr)->no;
123         display->width     = (*itr)->width;
124         display->height    = (*itr)->height;
125         display->name      = (*itr)->name;
126
127         vector<CicoSCLayerConf*>::const_iterator itr2;
128         itr2 = (*itr)->layerConfList.begin();
129         for (; itr2 != (*itr)->layerConfList.end(); ++itr2) {
130             CicoSCLayer *layer = new CicoSCLayer();
131             layer->layerid     = (*itr2)->id;
132             layer->type        = (*itr2)->type;
133             layer->width       = display->width;
134             layer->height      = display->height;
135             layer->displayid   = display->displayid;
136             layer->menuoverlap = (*itr2)->menuoverlap;
137             display->layerList.push_back(layer);
138         }
139
140         vector<CicoSCDisplayZoneConf*>::const_iterator itr3;
141         itr3 = (*itr)->zoneConfList.begin();
142         for (; itr3 != (*itr)->zoneConfList.end(); ++itr3) {
143             CicoSCDisplayZone *zone = new CicoSCDisplayZone();
144             zone->zoneid   = (*itr3)->id;
145             zone->x        = (*itr3)->x;
146             zone->y        = (*itr3)->y;
147             zone->width    = (*itr3)->w;
148             zone->height   = (*itr3)->h;
149             zone->fullname = (*itr3)->fullname;
150             zone->aspectFixed       = (*itr3)->aspectFixed;
151             zone->aspectAlignLeft   = (*itr3)->aspectAlignLeft;
152             zone->aspectAlignRight  = (*itr3)->aspectAlignRight;
153             zone->aspectAlignTop    = (*itr3)->aspectAlignTop;
154             zone->aspectAlignBottom = (*itr3)->aspectAlignBottom;
155             display->zoneList[zone->zoneid] = zone;
156         }
157         display->dump();
158         m_displayList.push_back(display);
159     }
160
161     ICO_TRA("CicoSCWindowController::initDB: Leave");
162     return ICO_SYC_EOK;
163 }
164
165 //--------------------------------------------------------------------------
166 /**
167  *  @brief   set resource manager instance
168  *
169  *  @param [in] resMgr  resource manager instance
170  */
171 //--------------------------------------------------------------------------
172 void
173 CicoSCWindowController::setResourceManager(CicoSCResourceManager *resMgr)
174 {
175     m_resMgr = resMgr;
176 }
177
178 //--------------------------------------------------------------------------
179 /**
180  *  @brief   show a target window
181  *
182  *  @param [in] surfaceid       wayland surface id
183  *  @param [in] animation       animation name
184  *  @param [in] animationTime   animation time
185  *
186  *  @return ICO_SYC_EOK on success, other on error
187  *  @retval ICO_SYC_EOK         success
188  *  @retval ICO_SYC_ESRCH       error(not initialized)
189  *  @retval ICO_SYC_ENOENT      error(not exist)
190  */
191 //--------------------------------------------------------------------------
192 int
193 CicoSCWindowController::show(int        surfaceid,
194                              const char *animation,
195                              int        animationTime)
196 {
197     int     type = animationTime & ICO_SYC_WIN_SURF_FLAGS;
198     animationTime &= ~ICO_SYC_WIN_SURF_FLAGS;
199
200     ICO_TRA("CicoSCWindowController::show Enter"
201             "(surfaceid=%08x animation=%s type=%x animationTime=%d)",
202             surfaceid, animation, type, animationTime);
203
204     // find window information in window list
205     CicoSCWindow *window = findWindow(surfaceid);
206     if (NULL == window) {
207         ICO_WRN("not found window information");
208         ICO_TRA("CicoSCWindowController::show Leave(ENOENT)");
209         return ICO_SYC_ENOENT;
210     }
211
212     // update visible attr
213     window->visible = true;
214
215     // update current displayed window at display zone
216     CicoSCDisplayZone* zone = (CicoSCDisplayZone*)findDisplayZone(window->zoneid);
217     if (NULL != zone) {
218         CicoSCLayer *layer = findLayer(window->displayid, window->layerid);
219         if ((NULL != layer) && (layer->type == ICO_LAYER_TYPE_APPLICATION)) {
220             ICO_DBG("Entry display zone[%d] current displayed window"
221                     "(%08x:\"%s\")",
222                     zone->zoneid, window->surfaceid, window->appid.c_str());
223             zone->displayedWindow = window;
224         }
225     }
226
227     // set animation request to Multi Window Manager
228     int raiseFlag = ICO_SYC_WIN_RAISE_NOCHANGE;
229     if (type & ICO_SYC_WIN_SURF_RAISE)  {
230         raiseFlag = ICO_SYC_WIN_RAISE_RAISE;
231     }
232     else if (type & ICO_SYC_WIN_SURF_LOWER) {
233         raiseFlag = ICO_SYC_WIN_RAISE_LOWER;
234     }
235     else if (((type & ICO_SYC_WIN_SURF_NOCHANGE) == 0) &&
236              (false == window->raise))   {
237         raiseFlag = ICO_SYC_WIN_RAISE_RAISE;
238     }
239     if ((NULL != animation) && (animation[0] != '\0')) {
240         // set animation request to Multi Window Manager
241         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
242                                        (type & ICO_SYC_WIN_SURF_ONESHOT) ?
243                                          ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW |
244                                            ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT :
245                                          ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW,
246                                        animation, animationTime);
247     }
248
249     // set raise/lower request (if need)
250     if (raiseFlag != ICO_SYC_WIN_RAISE_NOCHANGE)    {
251         raiselower(window, (raiseFlag == ICO_SYC_WIN_RAISE_RAISE));
252     }
253
254     // set visible request to Multi Window Manager
255     CicoSCWlWinMgrIF::setVisible(window->surfaceid, ICO_SYC_WIN_VISIBLE_SHOW);
256
257     // flush display
258     CicoSCWayland::getInstance()->flushDisplay();
259
260     ICO_TRA("CicoSCWindowController::show Leave(EOK)");
261     return ICO_SYC_EOK;
262 }
263
264 //--------------------------------------------------------------------------
265 /**
266  *  @brief   raise/lower a target window
267  *
268  *  @param [in] window          target window
269  *  @param [in] raise           raise(true)/lower(false)
270  *
271  *  @return nothing
272  */
273 //--------------------------------------------------------------------------
274 void
275 CicoSCWindowController::raiselower(CicoSCWindow *window, bool raise)
276 {
277     ICO_TRA("CicoSCWindowController::raiselower(%08x,%d)", window->surfaceid, raise);
278
279     window->raise = raise;
280
281     CicoSCLayer* layer = findLayer(window->displayid, window->layerid);
282     if (! layer)    {
283         ICO_ERR("CicoSCWindowController::raiselower: surface.%08x has no layer(%d)",
284                 window->surfaceid, window->layerid);
285         return;
286     }
287     if ((raise) && (layer->is_topSurface(window->surfaceid)))   {
288         ICO_DBG("CicoSCWindowController::raiselower %08x raise but top",
289                 window->surfaceid);
290     }
291     else if ((! raise) && (layer->is_buttomSurface(window->surfaceid))) {
292         ICO_DBG("CicoSCWindowController::raiselower %08x lower but buttom",
293                 window->surfaceid);
294     }
295     else    {
296         layer->addSurface(window->surfaceid, raise);
297
298         int nsurf;
299         const int *surfs = layer->getSurfaces(&nsurf);
300         ICO_TRA("CicoSCWindowControllerCicoSCWindowController layer.%d %d.%x %x %x %x",
301                 window->layerid, nsurf, surfs[0], surfs[1], surfs[2], surfs[3]);
302         if (nsurf > 4)  {
303             ICO_TRA("CicoSCWindowControllerCicoSCWindowController          .%x %x %x %x",
304                     surfs[4], surfs[5], surfs[6], surfs[7]);
305         }
306         if (ilm_layerSetRenderOrder(window->layerid, (t_ilm_layer *)surfs, nsurf)
307             != ILM_SUCCESS) {
308             ICO_ERR("CicoSCWindowController::raiselower "
309                     "ilm_layerSetRenderOrder(%d,,%d) Error", window->layerid, nsurf);
310         }
311     }
312 }
313
314 //--------------------------------------------------------------------------
315 /**
316  *  @brief   hide a target window
317  *
318  *  @param [in] surfaceid       wayland surface id
319  *  @param [in] animation       animation name
320  *  @param [in] animationTime   animation time
321  *
322  *  @return ICO_SYC_EOK on success, other on error
323  *  @retval ICO_SYC_EOK         success
324  *  @retval ICO_SYC_ESRCH       error(not initialized)
325  *  @retval ICO_SYC_ENOENT      error(not exist)
326  */
327 //--------------------------------------------------------------------------
328 int
329 CicoSCWindowController::hide(int        surfaceid,
330                              const char *animation,
331                              int        animationTime)
332 {
333     int     type = animationTime & ICO_SYC_WIN_SURF_FLAGS;
334     animationTime &= ~ICO_SYC_WIN_SURF_FLAGS;
335
336     ICO_TRA("CicoSCWindowController::hide Enter"
337             "(surfaceid=%08x animation=%s type=%x animationTime=%d)",
338             surfaceid, animation, type, animationTime);
339
340     // find window information in window list
341     CicoSCWindow *window = findWindow(surfaceid);
342     if (NULL == window) {
343         ICO_WRN("not found window information");
344         ICO_TRA("CicoSCWindowController::hide Leave(ENOENT)");
345         return ICO_SYC_ENOENT;
346     }
347
348     if (false == window->visible) {
349         ICO_DBG("already hide state");
350         ICO_TRA("CicoSCWindowController::hide Leave(EOK)");
351         return ICO_SYC_EOK;
352     }
353
354     // update window attr
355     window->visible = false;
356
357     // update current displayed window at display zone
358     CicoSCDisplayZone* zone = (CicoSCDisplayZone*)findDisplayZone(window->zoneid);
359     if (NULL != zone) {
360         CicoSCLayer *layer = findLayer(window->displayid, window->layerid);
361         if ((NULL != layer) && (layer->type == ICO_LAYER_TYPE_APPLICATION) &&
362             (getDisplayedWindow(zone->zoneid) == surfaceid)) {
363             ICO_DBG("Exit  display zone[%d] current displayed window"
364                     "(%08x:\"%s\")",
365                     zone->zoneid, window->surfaceid, window->appid.c_str());
366             zone->displayedWindow = NULL;
367         }
368     }
369
370     // set animation request to Multi Window Manager
371     if ((NULL != animation) && (animation[0] != '\0')) {
372         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
373                                        (type & ICO_SYC_WIN_SURF_ONESHOT) ?
374                                          ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE |
375                                            ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT :
376                                          ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE,
377                                        animation, animationTime);
378     }
379
380     // set visible request to Multi Window Manager
381     CicoSCWlWinMgrIF::setVisible(window->surfaceid, ICO_SYC_LAYER_VISIBLE_HIDE);
382
383     // flush display
384     CicoSCWayland::getInstance()->flushDisplay();
385
386     ICO_TRA("CicoSCWindowController::hide Leave(EOK)");
387     return ICO_SYC_EOK;
388 }
389
390 //--------------------------------------------------------------------------
391 /**
392  *  @brief   resize window(surface) size
393  *
394  *  @param [in] surfaceid       wayland surface id
395  *  @param [in] w               window width
396  *  @param [in] h               window height
397  *  @param [in] animation       animation name
398  *  @param [in] animationTime   animation time
399  *
400  *  @return ICO_SYC_EOK on success, other on error
401  *  @retval ICO_SYC_EOK         success
402  *  @retval ICO_SYC_ESRCH       error(not initialized)
403  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
404  */
405 //--------------------------------------------------------------------------
406 int
407 CicoSCWindowController::resize(int        surfaceid,
408                                int        w,
409                                int        h,
410                                const char *animation,
411                                int        animationTime)
412 {
413     int     type = animationTime & ICO_SYC_WIN_SURF_FLAGS;
414     animationTime &= ~ICO_SYC_WIN_SURF_FLAGS;
415
416     ICO_TRA("CicoSCWindowController::resize Enter"
417             "(surfaceid=%08x h=%d w=%d animation=%s type=%x animationTime=%d)",
418             surfaceid, w, h, animation, type, animationTime);
419
420     // find window information in window list
421     CicoSCWindow *window = findWindow(surfaceid);
422     if (NULL == window) {
423         ICO_WRN("not found window information");
424         ICO_TRA("CicoSCWindowController::resize Leave(ENOENT)");
425         return ICO_SYC_ENOENT;
426     }
427
428     // set animation request to Multi Window Manager
429     if ((NULL != animation) && (animation[0] != '\0')) {
430         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
431                                        (type & ICO_SYC_WIN_SURF_ONESHOT) ?
432                                          ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE |
433                                            ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT :
434                                          ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE,
435                                        animation, animationTime);
436     }
437
438     // set visible request to Multi Window Manager
439     window->width = w;
440     window->height = h;
441     CicoSCWlWinMgrIF::setPositionsize(window->surfaceid, window->nodeid,
442                                       window->x, window->y, w, h);
443
444     // flush display
445     CicoSCWayland::getInstance()->flushDisplay();
446
447     ICO_TRA("CicoSCWindowController::resize Leave(EOK)");
448     return ICO_SYC_EOK;
449 }
450
451 //--------------------------------------------------------------------------
452 /**
453  *  @brief  move window(surface) position
454  *
455  *  @param [in] surfaceid       wayland surface id
456  *  @param [in] nodeid          node id
457  *  @param [in] x               window width
458  *  @param [in] y               window height
459  *  @param [in] animation       animation name
460  *  @param [in] animationTime   animation time
461  *
462  *  @return ICO_SYC_EOK on success, other on error
463  *  @retval ICO_SYC_EOK         success
464  *  @retval ICO_SYC_ESRCH       error(not initialized)
465  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
466  */
467 //--------------------------------------------------------------------------
468 int
469 CicoSCWindowController::move(int        surfaceid,
470                              int        nodeid,
471                              int        x,
472                              int        y,
473                              const char *animation,
474                              int        animationTime)
475 {
476     int     type = animationTime & ICO_SYC_WIN_SURF_FLAGS;
477     animationTime &= ~ICO_SYC_WIN_SURF_FLAGS;
478
479     ICO_TRA("CicoSCWindowController::move Enter"
480             "(surfaceid=%08x nodeid=%d x=%d y=%d "
481             "animation=%s type=%x animationTime=%d)",
482             surfaceid, nodeid, x, y, animation, type, animationTime);
483
484     // find window information in window list
485     CicoSCWindow *window = findWindow(surfaceid);
486     if (NULL == window) {
487         ICO_WRN("CicoSCWindowController::move not found window(%08x)", surfaceid);
488         ICO_TRA("CicoSCWindowController::move Leave(ENOENT)");
489         return ICO_SYC_ENOENT;
490     }
491     // check nodeid
492     if (nodeid >= (int)m_physicalDisplayTotal)  {
493         ICO_WRN("CicoSCWindowController::move not found node(%d)", nodeid);
494         ICO_TRA("CicoSCWindowController::move Leave(ENOENT)");
495         return ICO_SYC_ENOENT;
496     }
497
498     // set animation request to Multi Window Manager
499     if ((NULL != animation) && (animation[0] != '\0')) {
500         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
501                                        (type & ICO_SYC_WIN_SURF_ONESHOT) ?
502                                          ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE |
503                                            ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT :
504                                          ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE,
505                                        animation, animationTime);
506     }
507
508     int moveNodeId = ICO_SYC_WIN_NOCHANGE;
509     if (nodeid >= 0) {
510         moveNodeId = nodeid;
511     }
512
513     // set visible request to Multi Window Manager
514     window->x = x;
515     window->y = y;
516     CicoSCWlWinMgrIF::setPositionsize(window->surfaceid,
517                                       moveNodeId, x, y,
518                                       window->width, window->height);
519
520     // flush display
521     CicoSCWayland::getInstance()->flushDisplay();
522
523     ICO_TRA("CicoSCWindowController::move Leave(EOK)");
524     return ICO_SYC_EOK;
525 }
526
527 //--------------------------------------------------------------------------
528 /**
529  *  @brief  raise window(surface)
530  *
531  *  @param [in] surfaceid       wayland surface id
532  *  @param [in] animation       animation name
533  *  @param [in] animationTime   animation time
534  *
535  *  @return ICO_SYC_EOK on success, other on error
536  *  @retval ICO_SYC_EOK         success
537  *  @retval ICO_SYC_ESRCH       error(not initialized)
538  *  @retval ICO_SYC_ENOENT      error(layer dose not exist)
539  */
540 //--------------------------------------------------------------------------
541 int
542 CicoSCWindowController::raise(int        surfaceid,
543                               const char *animation,
544                               int        animationTime)
545 {
546     int     type = animationTime & ICO_SYC_WIN_SURF_FLAGS;
547     animationTime &= ~ICO_SYC_WIN_SURF_FLAGS;
548
549     ICO_TRA("CicoSCWindowController::raise Enter"
550             "(surfaceid=%08x animation=%s type=%x animationTime=%d)",
551             surfaceid, animation, type, animationTime);
552
553     // find window information in window list
554     CicoSCWindow *window = findWindow(surfaceid);
555     if (NULL == window) {
556         ICO_WRN("not found window information");
557         ICO_TRA("CicoSCWindowController::raise Leave(ENOENT)");
558         return ICO_SYC_ENOENT;
559     }
560
561     // set animation request to Multi Window Manager
562     if ((NULL != animation) && (animation[0] != '\0')) {
563         CicoSCWindowController::setAnimation(window->surfaceid,
564                                              (type & ICO_SYC_WIN_SURF_ONESHOT) ?
565                                                ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW |
566                                                  ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT :
567                                                ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW,
568                                              animation, animationTime);
569     }
570     // set raise request to Multi Window Manager
571     raiselower(window, true);
572     if (ilm_commitChanges() != ILM_SUCCESS)    {
573         ICO_ERR("CicoSCWindowController::raise ilm_commitChanges() Error");
574     }
575
576     // flush display
577     CicoSCWayland::getInstance()->flushDisplay();
578
579     ICO_TRA("CicoSCWindowController::raise Leave(EOK)");
580     return ICO_SYC_EOK;
581 }
582
583 //--------------------------------------------------------------------------
584 /**
585  *  @brief  set window(surface) geometry
586  *
587  *  @param [in] surfaceid           wayland surface id
588  *  @param [in] nodeid              node id
589  *  @param [in] layerid             layer id
590  *  @param [in] x                   window x position
591  *  @param [in] y                   window y position
592  *  @param [in] w                   window width
593  *  @param [in] h                   window height
594  *  @param [in] resizeAnimation     resize animation name
595  *  @param [in] resizeAnimationTime resize animation time
596  *  @param [in] moveAnimation       move animation name
597  *  @param [in] moveanimationTime   move animation time
598  *
599  *  @return ICO_SYC_EOK on success, other on error
600  *  @retval ICO_SYC_EOK         success
601  *  @retval ICO_SYC_ESRCH       error(not initialized)
602  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
603  */
604 //--------------------------------------------------------------------------
605 int
606 CicoSCWindowController::setGeometry(int        surfaceid,
607                                     int        nodeid,
608                                     int        layerid,
609                                     int        x,
610                                     int        y,
611                                     int        w,
612                                     int        h,
613                                     const char *resizeAnimation,
614                                     int        resizeAnimationTime,
615                                     const char *moveAnimation,
616                                     int        moveAnimationTime)
617 {
618     ICO_TRA("CicoSCWindowController::setGeometry Enter"
619             "(surfaceid=%08x nodeid=%d layerid=%d x=%d y=%d w=%d h=%d "
620             "resizeAnimation=%s resizeAnimationTime=%d "
621             "moveAnimation=%s moveAnimationTime=%d)",
622             surfaceid, nodeid, layerid, x, y, w, h,
623             resizeAnimation, resizeAnimationTime,
624             moveAnimation, moveAnimationTime);
625
626     // find window information in window list
627     CicoSCWindow *window = findWindow(surfaceid);
628     if (NULL == window) {
629         ICO_WRN("CicoSCWindowController::setGeometry not found window(%08x)", surfaceid);
630         ICO_TRA("CicoSCWindowController::setGeometry Leave(ENOENT)");
631         return ICO_SYC_ENOENT;
632     }
633     // check nodeid
634     if (nodeid >= (int)m_physicalDisplayTotal)  {
635         ICO_WRN("CicoSCWindowController::setGeometry not found node(%d)", nodeid);
636         ICO_TRA("CicoSCWindowController::setGeometry Leave(ENOENT)");
637         return ICO_SYC_ENOENT;
638     }
639
640     // set animation request to Multi Window Manager
641     const char *animation = "";
642     if (NULL != resizeAnimation) {
643         animation = resizeAnimation;
644     }
645     CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
646                                    ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE,
647                                    animation, resizeAnimationTime);
648
649     if (NULL != moveAnimation) {
650         animation = moveAnimation;
651     }
652     CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
653                                    ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE,
654                                    animation, moveAnimationTime);
655
656     int moveNodeId = ICO_SYC_WIN_NOCHANGE;
657     if (nodeid >= 0) {
658         moveNodeId = nodeid;
659     }
660     else {
661         moveNodeId = window->nodeid;
662     }
663
664     if (m_physicalDisplayTotal <= (unsigned int)moveNodeId) {
665         ICO_WRN("nodeid(%d) is over physical display total(%d)",
666                 m_physicalDisplayTotal, nodeid);
667         ICO_TRA("CicoSCWindowController::setGeometry Leave(EINVAL)");
668         return ICO_SYC_EINVAL;
669     }
670
671     int moveX = window->x;
672     if (0 <= x) {
673         moveX = x;
674         window->x = x;
675     }
676
677     int moveY = window->y;
678     if (0 <= y) {
679         moveY = y;
680         window->y = y;
681     }
682
683     int moveW = window->width;
684     if (0 <= w) {
685         moveW = w;
686         window->width = w;
687     }
688
689     int moveH = window->height;
690     if (0 <= h) {
691         moveH = h;
692         window->height = h;
693     }
694
695     // set window layer to Multi Window Manager
696     if (0 <= layerid) {
697         setWindowLayer(window->surfaceid, layerid);
698     }
699
700     // update window attr
701     window->nodeid = moveNodeId;
702
703     // set visible request to Multi Window Manager
704     CicoSCWlWinMgrIF::setPositionsize(window->surfaceid, moveNodeId,
705                                       moveX, moveY, moveW, moveH);
706
707     // flush display
708     CicoSCWayland::getInstance()->flushDisplay();
709
710     ICO_TRA("CicoSCWindowController::setGeometry Leave(EOK)");
711     return ICO_SYC_EOK;
712 }
713
714 //--------------------------------------------------------------------------
715 /**
716  *  @brief  set window(surface) geometry
717  *
718  *  @param [in] surfaceid           wayland surface id
719  *  @param [in] layerid             layer id
720  *  @param [in] nodeid              node id
721  *  @param [in] zone                display zone name
722  *  @param [in] resizeAnimation     resize animation name
723  *  @param [in] resizeAnimationTime resize animation time
724  *  @param [in] moveAnimation       move animation name
725  *  @param [in] moveanimationTime   move animation time
726  *
727  *  @return ICO_SYC_EOK on success, other on error
728  *  @retval ICO_SYC_EOK         success
729  *  @retval ICO_SYC_ESRCH       error(not initialized)
730  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
731  *  @retval ICO_SYC_EINVAL      error(zone is null, zone name is invalid)
732  */
733 //--------------------------------------------------------------------------
734 int
735 CicoSCWindowController::setGeometry(int        surfaceid,
736                                     const char *zone,
737                                     int        layerid,
738                                     const char *resizeAnimation,
739                                     int        resizeAnimationTime,
740                                     const char *moveAnimation,
741                                     int        moveAnimationTime)
742 {
743     ICO_TRA("CicoSCWindowController::setGeometry Enter"
744             "(surfaceid=%08x zone=%s layerid=%d "
745             "resizeAnimation=%s resizeAnimationTime=%d "
746             "moveAnimation=%s moveAnimationTime=%d)",
747             surfaceid, zone, layerid,
748             resizeAnimation, resizeAnimationTime,
749             moveAnimation, moveAnimationTime);
750
751     // find window information in window list
752     CicoSCWindow *window = findWindow(surfaceid);
753     if (NULL == window) {
754         ICO_WRN("CicoSCWindowController::setGeometry not found window(%08x)", surfaceid);
755         ICO_TRA("CicoSCWindowController::setGeometry Leave(ENOENT)");
756         return ICO_SYC_ENOENT;
757     }
758
759     // find zone information
760     if ((NULL == zone) || ('\0' == zone[0])) {
761         ICO_WRN("zone value is invalid");
762         ICO_TRA("CicoSCWindowController::setGeometry Leave(EINVAL)");
763         return ICO_SYC_EINVAL;
764     }
765
766     vector<CicoSCDisplay*>::iterator itr;
767     itr = m_displayList.begin();
768     CicoSCDisplayZone* dispzone = NULL;
769     int displayno = 0;
770     for (; itr != m_displayList.end(); ++itr) {
771         dispzone = (*itr)->findDisplayZonebyFullName(zone);
772         if (NULL != dispzone) {
773             displayno = (*itr)->displayno;
774             break;
775         }
776     }
777     if (NULL == dispzone) {
778         ICO_WRN("display zone name(%s) is invalid.", zone);
779         ICO_TRA("CicoSCWindowController::setGeometry Leave(EINVAL)");
780         return ICO_SYC_EINVAL;
781     }
782     if (m_physicalDisplayTotal <= (unsigned int)displayno) {
783         ICO_WRN("nodeid(%d) is over physical display total(%d)",
784                 m_physicalDisplayTotal, displayno);
785         ICO_TRA("CicoSCWindowController::setGeometry Leave(EINVAL)");
786         return ICO_SYC_EINVAL;
787     }
788
789     if (window->zoneid != dispzone->zoneid) {
790         // update current displayed window at display zone
791         CicoSCDisplayZone* olddispzone = (CicoSCDisplayZone*)findDisplayZone(window->zoneid);
792         if (NULL != olddispzone) {
793             CicoSCLayer *layer = findLayer(window->displayid, window->layerid);
794             if ((NULL != layer) &&
795                 (layer->type == ICO_LAYER_TYPE_APPLICATION) &&
796                 (getDisplayedWindow(olddispzone->zoneid) == surfaceid)) {
797                 ICO_DBG("Exit display zone[%d] current displayed window"
798                         "(%08x:\"%s\")",
799                         olddispzone->zoneid, window->surfaceid,
800                         window->appid.c_str());
801                 olddispzone->displayedWindow = NULL;
802             }
803         }
804
805         CicoSCLayer *layer = findLayer(displayno, window->layerid);
806         if ((NULL != layer) && (layer->type == ICO_LAYER_TYPE_APPLICATION)) {
807             ICO_DBG("Entry display zone[%d] current displayed window"
808                     "(%08x:\"%s\")",
809                     dispzone->zoneid, window->surfaceid, window->appid.c_str());
810             dispzone->displayedWindow = window;
811         }
812     }
813
814     // update window attr
815     window->zoneid = dispzone->zoneid;
816     window->zone = dispzone->fullname;
817     setAttributes(window->surfaceid);
818
819     int ret = setGeometry(surfaceid, displayno, layerid,
820                           dispzone->x, dispzone->y,
821                           dispzone->width, dispzone->height,
822                           resizeAnimation, resizeAnimationTime,
823                           moveAnimation, moveAnimationTime);
824
825     ICO_TRA("CicoSCWindowController::setGeometry Leave(EOK)");
826     return ret;
827 }
828
829 //--------------------------------------------------------------------------
830 /**
831  *  @brief  lower window(surface)
832  *
833  *  @param [in] surfaceid       wayland surface id
834  *  @param [in] animation       animation name
835  *  @param [in] animationTime   animation time
836  *
837  *  @return ICO_SYC_EOK on success, other on error
838  *  @retval ICO_SYC_EOK         success
839  *  @retval ICO_SYC_ESRCH       error(not initialized)
840  *  @retval ICO_SYC_ENOENT      error(layer dose not exist)
841  */
842 //--------------------------------------------------------------------------
843 int
844 CicoSCWindowController::lower(int        surfaceid,
845                               const char *animation,
846                               int        animationTime)
847 {
848     int     type = animationTime & ICO_SYC_WIN_SURF_FLAGS;
849     animationTime &= ~ICO_SYC_WIN_SURF_FLAGS;
850
851     ICO_TRA("CicoSCWindowController::lower Enter"
852             "(surfaceid=08x animation=%s type=%x animationTime=%d)",
853             surfaceid, animation, type, animationTime);
854
855     // find window information in window list
856     CicoSCWindow *window = findWindow(surfaceid);
857     if (NULL == window) {
858         ICO_WRN("not found window information");
859         ICO_TRA("CicoSCWindowController::lower Leave(ENOENT)");
860         return ICO_SYC_ENOENT;
861     }
862
863     // set animation request to Multi Window Manager
864     if ((NULL != animation) && (animation[0] != '\0')) {
865         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
866                                        (type & ICO_SYC_WIN_SURF_ONESHOT) ?
867                                          ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW |
868                                            ICO_WINDOW_MGR_ANIMATION_TYPE_ONESHOT :
869                                          ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW,
870                                        animation, animationTime);
871     }
872
873     // set lower request to Multi Window Manager
874     raiselower(window, false);
875     if (ilm_commitChanges() != ILM_SUCCESS)    {
876         ICO_ERR("CicoSCWindowController::lower ilm_commitChanges() Error");
877     }
878
879     // flush display
880     CicoSCWayland::getInstance()->flushDisplay();
881
882     ICO_TRA("CicoSCWindowController::lower Leave(EOK)");
883     return ICO_SYC_EOK;
884 }
885
886 //--------------------------------------------------------------------------
887 /**
888  *  @brief   set window(surface) animation
889  *
890  *  @param [in] surfaceid   wayland surface id
891  *  @param [in] target      target(pointer and/or keyboard)
892  *  @param [in] type        set animation target
893  *  @param [in] animation   animation information
894  *  @param [in] time        animation time
895  *
896  *  @return ICO_SYC_EOK on success, other on error
897  *  @retval ICO_SYC_EOK     success
898  *  @retval ICO_SYC_ESRCH   error(not initialized)
899  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
900  */
901 //--------------------------------------------------------------------------
902 int
903 CicoSCWindowController::setWindowAnimation(int surfaceid, int type,
904                                            const char *animation, int time)
905 {
906     CicoSCWindow *window = NULL;
907
908     ICO_TRA("CicoSCWindowController::setWindowAnimation Enter"
909             "(surfaceid=%08x, type=%x, animation=<%s>, time=%d)",
910             surfaceid, type, animation ? animation : "(null)", time);
911
912     // find window information in window list
913     window = findWindow(surfaceid);
914     if (NULL == window) {
915         ICO_WRN("not found window information");
916         ICO_TRA("CicoSCWindowController::setWindowAnimation Leave(ENOENT)");
917         return ICO_SYC_ENOENT;
918     }
919
920     // set animation request to Multi Window Manager
921     CicoSCWlWinMgrIF::setAnimation(surfaceid, type, animation, time);
922
923     // flush display
924     CicoSCWayland::getInstance()->flushDisplay();
925
926     ICO_TRA("CicoSCWindowController::setWindowAnimation Leave(EOK)");
927     return ICO_SYC_EOK;
928 }
929
930 //--------------------------------------------------------------------------
931 /**
932  *  @brief  set window layer
933  *
934  *  @param [in] surfaceid       wayland surface id
935  *  @param [in] layer           layer id
936  *
937  *  @return ICO_SYC_EOK on success, other on error
938  *  @retval ICO_SYC_EOK         success
939  *  @retval ICO_SYC_ESRCH       error(not initialized)
940  *  @retval ICO_SYC_ENOENT      error(window or layer dose not exist)
941  */
942 //--------------------------------------------------------------------------
943 int
944 CicoSCWindowController::setWindowLayer(int surfaceid, int layerid)
945 {
946     ICO_TRA("CicoSCWindowController::setWindowLayer Enter"
947             "(surfaceid=%08x layerid=%x)", surfaceid, layerid);
948
949     // find window information in window list
950     CicoSCWindow* window = findWindow(surfaceid);
951     if (NULL == window) {
952         ICO_WRN("not found window information");
953         ICO_TRA("CicoSCWindowController::setWindowLayer Leave(ENOENT)");
954         return ICO_SYC_ENOENT;
955     }
956     if (window->layerid == layerid) {
957         ICO_TRA("CicoSCWindowController::setWindowLayer Leave(same layer %d)", layerid);
958         return ICO_SYC_EOK;
959     }
960
961     // find new layer information in layer list
962     CicoSCLayer* layer = findLayer(window->displayid, layerid);
963     if (NULL == layer) {
964         ICO_TRA("CicoSCWindowController::setWindowLayer Leave(ENOENT[disp=%d,layer=%d])",
965                 window->displayid, layerid);
966         return ICO_SYC_ENOENT;
967     }
968
969     // find old layer information and remove surface if need
970     CicoSCLayer* oldlayer = findLayer(window->displayid, window->layerid);
971     if (oldlayer)   {
972         if (ilm_layerRemoveSurface(window->layerid, window->surfaceid) != ILM_SUCCESS)  {
973             ICO_ERR("CicoSCWindowController::setWindowLayer ilm_layerRemoveSurface(%d,%08x)"
974                     " Error", window->layerid, window->surfaceid);
975         }
976         // must need ilm_commitChanges() after ilm_layerRemoveSurface()
977         if (ilm_commitChanges() != ILM_SUCCESS) {
978             ICO_ERR("CicoSCWindowController::setWindowLayer ilm_commitChanges Error");
979         }
980
981         oldlayer->removeSurface(window->surfaceid);
982         int noldsurf;
983         const int *oldsurfs = oldlayer->getSurfaces(&noldsurf);
984         if (ilm_layerSetRenderOrder(window->layerid, (t_ilm_layer *)oldsurfs, noldsurf)
985             != ILM_SUCCESS)   {
986             ICO_ERR("CicoSCWindowController::setWindowLayer "
987                 "ilm_layerSetRenderOrder(%d,,%d) Error", window->layerid, noldsurf);
988         }
989         if (ilm_commitChanges() != ILM_SUCCESS) {
990             ICO_ERR("CicoSCWindowController::setWindowLayer ilm_commitChanges Error");
991         }
992     }
993
994     // update window attr
995     window->layerid = layerid;
996
997     // set window layer request
998     if (ilm_layerAddSurface(window->layerid, window->surfaceid) != ILM_SUCCESS) {
999         ICO_ERR("CicoSCWindowController::setWindowLayer ilm_layerAddSurface(%d,%08x) Error",
1000                 window->layerid, window->surfaceid);
1001     }
1002     if (ilm_commitChanges() != ILM_SUCCESS)    {
1003         ICO_ERR("CicoSCWindowController::setWindowLayer ilm_commitChanges() Error");
1004     }
1005
1006     // add surface to new layer
1007     layer->addSurface(window->surfaceid, true);
1008     int nsurf;
1009     const int *surfs = layer->getSurfaces(&nsurf);
1010     if (ilm_layerSetRenderOrder(window->layerid, (t_ilm_layer *)surfs, nsurf)
1011         != ILM_SUCCESS)   {
1012         ICO_ERR("CicoSCWindowController::setWindowLayer "
1013                 "ilm_layerSetRenderOrder(%d,,%d) Error", window->layerid, nsurf);
1014     }
1015     if (ilm_commitChanges() != ILM_SUCCESS)    {
1016         ICO_ERR("CicoSCWindowController::setWindowLayer ilm_commitChanges() Error");
1017     }
1018
1019     // flush display
1020     CicoSCWayland::getInstance()->flushDisplay();
1021
1022     ICO_TRA("CicoSCWindowController::setWindowLayer Leave(EOK)");
1023     return ICO_SYC_EOK;
1024 }
1025
1026 //--------------------------------------------------------------------------
1027 /**
1028  *  @brief   show layer
1029  *
1030  *  @param [in] displayid   display id
1031  *  @param [in] layerid     layer id
1032  *
1033  *  @return ICO_SYC_EOK on success, other on error
1034  *  @retval ICO_SYC_EOK     success
1035  *  @retval ICO_SYC_ESRCH   error(not initialized)
1036  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
1037  */
1038 //--------------------------------------------------------------------------
1039 int
1040 CicoSCWindowController::showLayer(int displayid, int layerid)
1041 {
1042     ICO_TRA("CicoSCWindowController::showLayer Enter"
1043             "(displayid=%d layerid=%d)", displayid, layerid);
1044
1045     // find layer information in layer list
1046     CicoSCLayer* layer = findLayer(displayid, layerid);
1047     if (NULL == layer) {
1048         ICO_WRN("not found layer information");
1049         ICO_TRA("CicoSCWindowController::showLayer Leave(ENOENT)");
1050         return ICO_SYC_ENOENT;
1051     }
1052
1053     CicoSCWlWinMgrIF::setLayerVisible(layerid, ICO_SYC_LAYER_VISIBLE_SHOW);
1054
1055     // flush display
1056     CicoSCWayland::getInstance()->flushDisplay();
1057
1058     ICO_TRA("CicoSCWindowController::showLayer Leave(EOK)");
1059     return ICO_SYC_EOK;
1060 }
1061
1062 //--------------------------------------------------------------------------
1063 /**
1064  *  @brief   show layer
1065  *
1066  *  @param [in] displayid   display id
1067  *  @param [in] layerid     layer id
1068  *
1069  *  @return ICO_SYC_EOK on success, other on error
1070  *  @retval ICO_SYC_EOK     success
1071  *  @retval ICO_SYC_ESRCH   error(not initialized)
1072  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
1073  */
1074 //--------------------------------------------------------------------------
1075 int
1076 CicoSCWindowController::hideLayer(int displayid, int layerid)
1077 {
1078     ICO_TRA("CicoSCWindowController::hideLayer Enter"
1079             "displayid=%d layerid=%d)",
1080             displayid, layerid);
1081
1082     // find layer information in layer list
1083     CicoSCLayer* layer = findLayer(displayid, layerid);
1084     if (NULL == layer) {
1085         ICO_WRN("not found layer information");
1086         ICO_TRA("CicoSCWindowController::hideLayer Leave(ENOENT)");
1087         return ICO_SYC_ENOENT;
1088     }
1089
1090     CicoSCWlWinMgrIF::setLayerVisible(layerid, ICO_SYC_LAYER_VISIBLE_HIDE);
1091
1092     // flush display
1093     CicoSCWayland::getInstance()->flushDisplay();
1094
1095     ICO_TRA("CicoSCWindowController::hideVisible Leave(EOK)");
1096     return ICO_SYC_EOK;
1097 }
1098
1099 //--------------------------------------------------------------------------
1100 /**
1101  *  @brief   active window(surface)
1102  *
1103  *  @param [in] surfaceid   wayland surface id
1104  *  @param [in] target      target(pointer and/or keyboard)
1105  *
1106  *  @return ICO_SYC_EOK on success, other on error
1107  *  @retval ICO_SYC_EOK     success
1108  *  @retval ICO_SYC_ESRCH   error(not initialized)
1109  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
1110  */
1111 //--------------------------------------------------------------------------
1112 int
1113 CicoSCWindowController::active(int surfaceid, int target)
1114 {
1115     CicoSCWindow *window = NULL;
1116
1117     ICO_TRA("CicoSCWindowController::active Enter"
1118             "(surfaceid=%08x, target=%08x)", surfaceid, target);
1119
1120     // find window information in window list
1121     if (surfaceid) {
1122         window = findWindow(surfaceid);
1123         if (NULL == window) {
1124             ICO_WRN("not found window information");
1125             ICO_TRA("CicoSCWindowController::active Leave(ENOENT)");
1126             return ICO_SYC_ENOENT;
1127         }
1128     }
1129
1130     if (target < 0) {
1131         target = 0xffff;
1132     }
1133
1134     // set active request to Multi Window Manager
1135     CicoSCWlWinMgrIF::setActive(surfaceid, target);
1136
1137     // flush display
1138     CicoSCWayland::getInstance()->flushDisplay();
1139
1140     // update visible attr
1141     if (window) {
1142         window->raise = true;
1143     }
1144
1145     // update active window
1146     map<unsigned int, CicoSCWindow*>::iterator itr;
1147     itr = m_windowList.begin();
1148     for (; itr != m_windowList.end(); ++itr) {
1149         CicoSCWindow* window = itr->second;
1150         if ((surfaceid != 0) && (window->surfaceid == surfaceid)) {
1151             window->active = target;
1152         }
1153         else {
1154             if (target == 0) {
1155                 window->active = 0;
1156             }
1157             else {
1158                 window->active &= ~target;
1159             }
1160         }
1161     }
1162
1163     ICO_TRA("CicoSCWindowController::active Leave(EOK)");
1164     return ICO_SYC_EOK;
1165 }
1166
1167 //--------------------------------------------------------------------------
1168 /**
1169  *  @brief   set surface map get
1170  *
1171  *  @param [in] surfaceid   wayland surface id
1172  *  @param [in] filepath    surface image pixel file path
1173  *
1174  *  @return ICO_SYC_EOK on success, other on error(currently EOK only)
1175  *  @retval ICO_SYC_EOK     success
1176  */
1177 //--------------------------------------------------------------------------
1178 int
1179 CicoSCWindowController::setmapGet(int surfaceid, const char *filepath)
1180 {
1181     ICO_TRA("CicoSCWindowController::setmapGet Enter");
1182
1183     CicoSCWlWinMgrIF::setmapGet(surfaceid, filepath);
1184     CicoSCWayland::getInstance()->flushDisplay();
1185
1186     ICO_TRA("CicoSCWindowController::setmapGet Leave(EOK)");
1187     return ICO_SYC_EOK;
1188 }
1189
1190 //--------------------------------------------------------------------------
1191 /**
1192  *  @brief   map surface
1193  *
1194  *  @param [in] surfaceid   wayland surface id
1195  *  @param [in] framerate   surface change frame rate(frames par sec)
1196  *  @param [in] filepath    surface image pixel file path
1197  *
1198  *  @return ICO_SYC_EOK on success, other on error
1199  *  @retval ICO_SYC_EOK     success
1200  *  @retval ICO_SYC_ESRCH   error(not initialized)
1201  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
1202  */
1203 //--------------------------------------------------------------------------
1204 int
1205 CicoSCWindowController::mapSurface(int surfaceid, int framerate, const char *filepath)
1206 {
1207     ICO_TRA("CicoSCWindowController::mapSurface Enter(%08x,%d,%s)",
1208             surfaceid, framerate, filepath ? filepath : "(null)");
1209
1210     // find window information in window list
1211     CicoSCWindow *window = findWindow(surfaceid);
1212     if (NULL == window) {
1213         ICO_WRN("not found window information");
1214         ICO_TRA("CicoSCWindowController::mapSurface Leave(ENOENT)");
1215         return ICO_SYC_ENOENT;
1216     }
1217
1218     CicoSCWlWinMgrIF::mapSurface(surfaceid, framerate, filepath);
1219     CicoSCWayland::getInstance()->flushDisplay();
1220
1221     ICO_TRA("CicoSCWindowController::mapSurface Leave(EOK)");
1222     return ICO_SYC_EOK;
1223 }
1224
1225 //--------------------------------------------------------------------------
1226 /**
1227  *  @brief   unmap surface
1228  *
1229  *  @param [in] surfaceid   wayland surface id
1230  *
1231  *  @return ICO_SYC_EOK on success, other on error
1232  *  @retval ICO_SYC_EOK     success
1233  *  @retval ICO_SYC_ESRCH   error(not initialized)
1234  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
1235  */
1236 //--------------------------------------------------------------------------
1237 int
1238 CicoSCWindowController::unmapSurface(int surfaceid)
1239 {
1240     ICO_TRA("CicoSCWindowController::unmapSurface Enter(%08x)", surfaceid);
1241
1242     // find window information in window list
1243     CicoSCWindow *window = findWindow(surfaceid);
1244     if (NULL == window) {
1245         ICO_WRN("not found window information");
1246         ICO_TRA("CicoSCWindowController::unmapSurface Leave(ENOENT)");
1247         return ICO_SYC_ENOENT;
1248     }
1249
1250     CicoSCWlWinMgrIF::unmapSurface(surfaceid);
1251     CicoSCWayland::getInstance()->flushDisplay();
1252
1253     ICO_TRA("CicoSCWindowController::unmapSurface Leave(EOK)");
1254     return ICO_SYC_EOK;
1255 }
1256
1257 //--------------------------------------------------------------------------
1258 /**
1259  *  @brief   get displayed window by display zone id
1260  *
1261  *  @param [in] zoneid  display zone id
1262  *
1263  *  @return surface id on success, -1 on not displayed
1264  */
1265 //--------------------------------------------------------------------------
1266 int
1267 CicoSCWindowController::getDisplayedWindow(int zoneid)
1268 {
1269     const CicoSCDisplayZone* zone = findDisplayZone(zoneid);
1270     if (NULL == zone) {
1271         return -1;
1272     }
1273
1274     if (NULL == zone->displayedWindow) {
1275         return -1;
1276     }
1277
1278     return zone->displayedWindow->surfaceid;
1279 }
1280
1281 //--------------------------------------------------------------------------
1282 /**
1283  *  @brief  set surface attributes
1284  *
1285  *  @param [in] surfaceid   surface id
1286  *
1287  *  @retval ICO_SYC_EOK     success
1288  *  @retval ICO_SYC_ESRCH   error(not initialized)
1289  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
1290  */
1291 //--------------------------------------------------------------------------
1292 int
1293 CicoSCWindowController::setAttributes(int surfaceid)
1294 {
1295     ICO_TRA("CicoSCWindowController::setAttributes Enter"
1296             "(surfaceid=%08x)", surfaceid);
1297
1298     // find window information in window list
1299     CicoSCWindow *window = findWindow(surfaceid);
1300     if (NULL == window) {
1301         ICO_WRN("not found window information");
1302         ICO_TRA("CicoSCWindowController::setAttributes Leave(ENOENT)");
1303         return ICO_SYC_ENOENT;
1304     }
1305
1306     // find zone
1307     const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1308     if (NULL == zone) {
1309         ICO_WRN("not found zone information");
1310         ICO_TRA("CicoSCWindowController::setAttributes Leave(ENOENT)");
1311         return ICO_SYC_ENOENT;
1312     }
1313
1314     uint32_t attributes = 0;
1315     if (true == zone->aspectFixed) {
1316         attributes |= ICO_SYC_WIN_ASPECT_FIXED;
1317         if (true == zone->aspectAlignLeft) {
1318             attributes |= ICO_SYC_WIN_ASPECT_ALIGN_LEFT;
1319         }
1320         if (true == zone->aspectAlignRight) {
1321             attributes |= ICO_SYC_WIN_ASPECT_ALIGN_RIGHT;
1322         }
1323         if (true == zone->aspectAlignTop) {
1324             attributes |= ICO_SYC_WIN_ASPECT_ALIGN_TOP;
1325         }
1326         if (true == zone->aspectAlignBottom) {
1327             attributes |= ICO_SYC_WIN_ASPECT_ALIGN_BOTTOM;
1328         }
1329     }
1330     ICO_TRA("CicoSCWindowController::setAttributes Leave(EOK)");
1331     return ICO_SYC_EOK;
1332 }
1333
1334 //--------------------------------------------------------------------------
1335 /**
1336  *  @brief  wayland surface active callback
1337  *
1338  *  @param [in] data            user data(unused)
1339  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1340  *  @param [in] surfaceid       ico_window_mgr surface Id
1341  *  @param [in] select          select device(unused)
1342  *                              (0=not active/1=pointer/2=touch)
1343  */
1344 //--------------------------------------------------------------------------
1345 void
1346 CicoSCWindowController::activeCB(void                  *data,
1347                                  struct ico_window_mgr *ico_window_mgr,
1348                                  uint32_t              surfaceid,
1349                                  int32_t               select)
1350 {
1351     ICO_TRA("CicoSCWindowController::activeCB Enter"
1352             "(surfaceid=%08x select=%d)", surfaceid, select);
1353
1354     CicoSCWindow *window = findWindow(surfaceid);
1355     if (NULL == window) {
1356         ICO_WRN("not found window information");
1357         ICO_TRA("CicoSCWindowController::activeCB Leave(not found window)");
1358         return;
1359     }
1360
1361     if (0 == select) {
1362         ICO_TRA("CicoSCWindowController::activeCB Leave(not active)");
1363         return;
1364     }
1365
1366     if (0 != window->active) {
1367         ICO_TRA("CicoSCWindowController::activeCB Leave(already active)");
1368         return;
1369     }
1370
1371     // send message
1372     CicoSCMessage *message = new CicoSCMessage();
1373     message->addRootObject("command", MSG_CMD_CHANGE_ACTIVE);
1374     message->addRootObject("appid", window->appid);
1375     message->addRootObject("pid", window->pid);
1376     message->addArgObject("surface", window->surfaceid);
1377     message->addArgObject("winname", window->name);
1378     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1379
1380     ICO_TRA("CicoSCWindowController::activeCB Leave");
1381 }
1382
1383 //--------------------------------------------------------------------------
1384 /**
1385  *  @brief   surface map event callback
1386  *
1387  *  @param [in] data            user data(unused)
1388  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1389  *  @param [in] event           event
1390  *  @param [in] surfaceid       surface Id
1391  *  @param [in] type            surface type (EGL buffer/Shared memory)
1392  *  @param [in] width           surface width
1393  *  @param [in] height          surface height
1394  *  @param [in] stride          surface buffer(frame buffer) stride
1395  *  @param [in] format          surface buffer format
1396  */
1397 //--------------------------------------------------------------------------
1398 void
1399 CicoSCWindowController::mapSurfaceCB(void                  *data,
1400                                      struct ico_window_mgr *ico_window_mgr,
1401                                      int32_t               event,
1402                                      uint32_t              surfaceid,
1403                                      uint32_t              type,
1404                                      int32_t               width,
1405                                      int32_t               height,
1406                                      int32_t               stride,
1407                                      uint32_t               format)
1408 {
1409     int command;
1410
1411     ICO_TRA("CicoSCWindowController::mapSurfaceCB Enter(ev=%d surf=%x "
1412             "type=%d w/h=%d/%d stride=%d form=%x)",
1413             event, surfaceid, type, width, height, stride, format);
1414
1415     CicoSCWindow *window = findWindow(surfaceid);
1416     if (NULL == window) {
1417         return;
1418     }
1419
1420     // convert event to command
1421     switch (event)  {
1422     case ICO_WINDOW_MGR_MAP_SURFACE_EVENT_CONTENTS:
1423     case ICO_WINDOW_MGR_MAP_SURFACE_EVENT_RESIZE:
1424     case ICO_WINDOW_MGR_MAP_SURFACE_EVENT_MAP:
1425         command = MSG_CMD_MAP_THUMB;
1426         break;
1427     case ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP:
1428     case ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR:
1429         command = MSG_CMD_UNMAP_THUMB;
1430         break;
1431     default:
1432         ICO_TRA("CicoSCWindowController::mapSurfaceCB Leave(Unknown event(%d))", event);
1433         return;
1434     }
1435
1436     // send message
1437     CicoSCMessage *message = new CicoSCMessage();
1438     message->addRootObject("command", command);
1439     message->addRootObject("appid", window->appid);
1440     message->addArgObject("surface", window->surfaceid);
1441     message->addArgObject("attr", type);
1442     message->addArgObject("width", width);
1443     message->addArgObject("height", height);
1444     message->addArgObject("stride", stride);
1445     message->addArgObject("format", format);
1446     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1447
1448     ICO_TRA("CicoSCWindowController::mapSurfaceCB Leave");
1449 }
1450
1451 //--------------------------------------------------------------------------
1452 /**
1453  *  @brief   surface update event callback
1454  *
1455  *  @param [in] data            user data(unused)
1456  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1457  *  @param [in] surfaceid       surface Id
1458  *  @param [in] visible         visibility
1459  *  @param [in] srcwidth        application buffer width
1460  *  @param [in] srcheight       application buffer height
1461  *  @param [in] x               X
1462  *  @param [in] y               Y
1463  *  @param [in] width           width
1464  *  @param [in] height          height
1465  */
1466 //--------------------------------------------------------------------------
1467 void
1468 CicoSCWindowController::updateSurfaceCB(void                  *data,
1469                                         struct ico_window_mgr *ico_window_mgr,
1470                                         uint32_t              surfaceid,
1471                                         int                   visible,
1472                                         int                   srcwidth,
1473                                         int                   srcheight,
1474                                         int                   x,
1475                                         int                   y,
1476                                         int                   width,
1477                                         int                   height)
1478 {
1479     ICO_TRA("CicoSCWindowController::updateSurfaceCB: Enter(%08x %d,%d,%d,%d,%d,%d,%d)",
1480             surfaceid, visible, srcwidth, srcheight, x, y, width, height);
1481
1482     CicoSCWindow *window = findWindow(surfaceid);
1483     if (NULL == window) {
1484         ICO_WRN("CicoSCWindowController::updateSurfaceCB: not found window(%08x)",
1485                 surfaceid);
1486         ICO_TRA("CicoSCWindowController::updateSurfaceCB: Leave");
1487         return;
1488     }
1489
1490     // update attr
1491     window->visible = visible;
1492     window->srcwidth = srcwidth;
1493     window->srcheight = srcheight;
1494     window->x = x;
1495     window->y = y;
1496     window->width = width;
1497     window->height = height;
1498     window->nodeid = window->layerid / ICO_SC_LAYERID_SCREENBASE;
1499
1500     // notify to homescreen
1501     CicoSCMessage *message = new CicoSCMessage();
1502     message->addRootObject("command", MSG_CMD_CHANGE_ATTR);
1503     message->addRootObject("appid", window->appid);
1504     const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1505     if (NULL != zone) {
1506         message->addArgObject("zone", zone->fullname);
1507     }
1508     else {
1509         message->addArgObject("zone", "");
1510     }
1511     message->addArgObject("surface", window->surfaceid);
1512     message->addArgObject("winname", window->name);
1513     message->addArgObject("node", window->nodeid);
1514     message->addArgObject("layer", window->layerid);
1515     message->addArgObject("pos_x", window->x);
1516     message->addArgObject("pos_y", window->y);
1517     message->addArgObject("width", window->width);
1518     message->addArgObject("height", window->height);
1519     message->addArgObject("raise", window->raise ? 1 : 0);
1520     message->addArgObject("visible", window->visible ? 1 : 0);
1521     message->addArgObject("active", window->active ? 1 : 0);
1522     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1523
1524     ICO_TRA("CicoSCWindowController::updateSurfaceCB: Leave");
1525 }
1526
1527 //--------------------------------------------------------------------------
1528 /**
1529  *  @brief  wayland surface destroy callback
1530  *
1531  *  @param [in] data            user data(unused)
1532  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1533  *  @param [in] surfaceid       ico_window_mgr surface Id
1534  */
1535 //--------------------------------------------------------------------------
1536 void
1537 CicoSCWindowController::destroySurfaceCB(void                  *data,
1538                                          struct ico_window_mgr *ico_window_mgr,
1539                                          uint32_t              surfaceid)
1540 {
1541     ICO_TRA("CicoSCWindowController::destroySurfaceCB: Enter(%08x)", surfaceid);
1542
1543     CicoSCWindow *window = findWindow(surfaceid);
1544     if (NULL == window) {
1545         ICO_WRN("not found window(%08x)", surfaceid);
1546         ICO_TRA("CicoSCWindowController::destroySurfaceCB Leave");
1547         return;
1548     }
1549
1550     // delete surface from layer
1551     CicoSCLayer* layer = findLayer(window->displayid, window->layerid);
1552     if (NULL == layer) {
1553         ICO_TRA("CicoSCWindowController::destroySurfaceCB: surf.%08x not exist in layer.%d",
1554                 surfaceid, window->layerid);
1555     }
1556     else    {
1557         layer->removeSurface(surfaceid);
1558     }
1559
1560     // send message
1561     CicoSCMessage *message = new CicoSCMessage();
1562     message->addRootObject("command", MSG_CMD_DESTROY);
1563     message->addRootObject("appid", window->appid);
1564     message->addRootObject("pid", window->pid);
1565     message->addArgObject("surface", window->surfaceid);
1566     message->addArgObject("winname", window->name);
1567     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1568
1569     // TODO delete window in application
1570     if (NULL != m_resMgr) {
1571         CicoSCCommand cmd;
1572         CicoSCCmdResCtrlOpt *opt = new CicoSCCmdResCtrlOpt();
1573
1574         cmd.cmdid = MSG_CMD_DESTORY_RES;
1575         cmd.appid = window->appid;
1576         cmd.pid   = window->pid;
1577         cmd.opt = opt;
1578
1579         opt->dispres   = true;
1580         opt->winname   = window->name;
1581         opt->surfaceid = window->surfaceid;
1582
1583         string fullname;
1584         const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1585         if (NULL != zone) {
1586             opt->dispzone = zone->fullname;
1587         }
1588
1589         opt->soundres  = true;
1590         opt->soundname = window->appid;
1591         opt->soundid   = 0;
1592         CicoSystemConfig *sysconf = CicoSystemConfig::getInstance();
1593         const CicoSCDefaultConf *defconf = sysconf->getDefaultConf();
1594         if (NULL != defconf) {
1595             const CicoSCSoundZoneConf *zoneconf =
1596                 sysconf->findSoundZoneConfbyId(defconf->soundzone);
1597             if (NULL != zoneconf) {
1598                 opt->soundzone = zoneconf->fullname;
1599             }
1600         }
1601         m_resMgr->handleCommand((const CicoSCCommand&)cmd, true);
1602     }
1603     // delete window in list
1604     m_windowList.erase(window->surfaceid);
1605     delete(window);
1606
1607     ICO_TRA("CicoSCWindowController::destroySurfaceCB: Leave");
1608 }
1609
1610 //--------------------------------------------------------------------------
1611 /**
1612  *  @brief  wayland update surface name callback
1613  *
1614  *  @param [in] surfaceid       surface Id
1615  *  @param [in] winname         surface name (title)
1616  */
1617 //--------------------------------------------------------------------------
1618 void
1619 CicoSCWindowController::updateWinnameCB(uint32_t surfaceid,
1620                                         const char *winname)
1621 {
1622     ICO_TRA("CicoSCWindowController::updateWinnameCB: Enter(%08x,<%s>)",
1623             surfaceid, winname ? winname : "(null)");
1624
1625     CicoSCWindow *window = findWindow(surfaceid);
1626     if (NULL == window) {
1627         ICO_WRN("CicoSCWindowController::updateWinnameCB: not found window(%08x)",
1628                 surfaceid);
1629         ICO_TRA("CicoSCWindowController::updateWinnameCB Leave");
1630         return;
1631     }
1632
1633     window->name = winname;
1634
1635     // send message
1636     CicoSCMessage *message = new CicoSCMessage();
1637     message->addRootObject("command", MSG_CMD_NAME);
1638     message->addRootObject("appid", window->appid);
1639     message->addRootObject("pid", window->pid);
1640     message->addArgObject("surface", window->surfaceid);
1641     message->addArgObject("winname", window->name);
1642     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1643
1644     ICO_TRA("CicoSCWindowController::updateWinnameCB: Leave");
1645 }
1646
1647 //--------------------------------------------------------------------------
1648 /**
1649  *  @brief   wayland display attribute callback
1650  *
1651  *  @param [in] data            user data(unused)
1652  *  @param [in] wl_output       wayland wl_output interface
1653  *  @param [in] x               display upper-left X coordinate
1654  *  @param [in] y               display upper-left Y coordinate
1655  *  @param [in] physical_width  display physical width
1656  *  @param [in] physical_height display physical height
1657  *  @param [in] subpixel        display sub pixel
1658  *  @param [in] make            display maker
1659  *  @param [in] model           display model
1660  *  @param [in] transform       transform
1661  */
1662 //--------------------------------------------------------------------------
1663 void
1664 CicoSCWindowController::outputGeometryCB(void             *data,
1665                                          struct wl_output *wl_output,
1666                                          int32_t          x,
1667                                          int32_t          y,
1668                                          int32_t          physical_width,
1669                                          int32_t          physical_height,
1670                                          int32_t          subpixel,
1671                                          const char       *make,
1672                                          const char       *model,
1673                                          int32_t          transform)
1674 {
1675     ICO_TRA("CicoSCWindowController::outputGeometryCB Enter"
1676             "(x=%d y=%d physical_width=%d physical_height=%d "
1677             "subpixel=%d make=%s model=%s transform=%d)",
1678             x, y, physical_width, physical_height,
1679             subpixel, make, model, transform);
1680
1681     ++m_physicalDisplayTotal;
1682     if (0 == m_displayList.size()) {
1683         ICO_TRA("CicoSCWindowController::outputGeometryCB Leave"
1684                 "(display is zero)");
1685         return;
1686     }
1687
1688     if (m_displayList.size() < m_physicalDisplayTotal) {
1689         ICO_TRA("CicoSCWindowController::outputGeometryCB Leave"
1690                 "(display total unmatch)");
1691         return;
1692     }
1693
1694     CicoSCDisplay* display = m_displayList.at(m_physicalDisplayTotal-1);
1695     switch (transform) {
1696     case WL_OUTPUT_TRANSFORM_90:
1697     case WL_OUTPUT_TRANSFORM_270:
1698     case WL_OUTPUT_TRANSFORM_FLIPPED_90:
1699     case WL_OUTPUT_TRANSFORM_FLIPPED_270:
1700         display->pWidth      = physical_height;
1701         display->pHeight     = physical_width;
1702         display->orientation = CicoSCDisplay::ORIENTATION_VERTICAL;
1703         break;
1704     case WL_OUTPUT_TRANSFORM_NORMAL:
1705     case WL_OUTPUT_TRANSFORM_180:
1706     case WL_OUTPUT_TRANSFORM_FLIPPED:
1707     case WL_OUTPUT_TRANSFORM_FLIPPED_180:
1708     default:
1709         display->pWidth      = physical_width;
1710         display->pHeight     = physical_height;
1711         display->orientation = CicoSCDisplay::ORIENTATION_HORIZONTAL;
1712         break;
1713     }
1714     display->dump();
1715
1716     ICO_TRA("CicoSCWindowController::outputGeometryCB Leave");
1717 }
1718
1719 //--------------------------------------------------------------------------
1720 /**
1721  *  @brief  wayland display mode callback
1722  *
1723  *  @param [in] data        user data(unused)
1724  *  @param [in] wl_output   wayland wl_output interface
1725  *  @param [in] flags       flags
1726  *  @param [in] width       display width
1727  *  @param [in] height      display height
1728  *  @param [in] refresh     display refresh rate
1729  */
1730 //--------------------------------------------------------------------------
1731 void
1732 CicoSCWindowController::outputModeCB(void             *data,
1733                                      struct wl_output *wl_output,
1734                                      uint32_t         flags,
1735                                      int32_t          width,
1736                                      int32_t          height,
1737                                      int32_t          refresh)
1738 {
1739     ICO_TRA("CicoSCWindowController::outputModeCB Enter"
1740             "(flags=%d width=%d height=%d refresh=%d)",
1741             flags, width, height, refresh);
1742
1743     if (0 == m_displayList.size()) {
1744         ICO_TRA("CicoSCWindowController::outputModeCB Leave(display is zero)");
1745         return;
1746     }
1747
1748     CicoSCDisplay* display = m_displayList.at(0);
1749     if (flags & WL_OUTPUT_MODE_CURRENT) {
1750         if (display->orientation == CicoSCDisplay::ORIENTATION_VERTICAL) {
1751             display->pWidth  = height;
1752             display->pHeight = width;
1753         }
1754         else {
1755             display->pWidth  = width;
1756             display->pHeight = height;
1757         }
1758         display->dump();
1759     }
1760
1761     ICO_TRA("CicoSCWindowController::outputModeCB Leave");
1762 }
1763
1764 //--------------------------------------------------------------------------
1765 /**
1766  *  @brief  wayland genivi ivi-shell surface create callback
1767  *
1768  *  @param [in] data        user data
1769  *  @param [in] ivi_controller  wayland ivi-controller plugin interface
1770  *  @param [in] id_surface      surface id
1771  */
1772 //--------------------------------------------------------------------------
1773 void
1774 CicoSCWindowController::createSurfaceCB(void *data,
1775                                         struct ivi_controller *ivi_controller,
1776                                         uint32_t id_surface)
1777 {
1778     int     pid;
1779     struct ilmSurfaceProperties SurfaceProperties;
1780
1781     ICO_TRA("CicoSCWindowController::createSurfaceCB Enter"
1782             "(surfaceid=%08x)", id_surface);
1783
1784     if (ilm_getPropertiesOfSurface(id_surface, &SurfaceProperties) != ILM_SUCCESS)  {
1785         ICO_ERR("CicoSCWindowController::createSurfaceCB: ilm_getPropertiesOfSurface(%x) Error",
1786                 id_surface);
1787         return;
1788     }
1789     ICO_TRA("createSurfaceCB: surface=%08x w/h=%d/%d->%d/%d",
1790             id_surface, SurfaceProperties.sourceWidth, SurfaceProperties.sourceHeight,
1791             SurfaceProperties.destWidth, SurfaceProperties.destHeight);
1792
1793     CicoSCWindow* window = new CicoSCWindow();
1794     window->surfaceid = id_surface;
1795     window->name = CicoSCWlWinMgrIF::wlIviCtrlGetSurfaceWaiting(id_surface, &pid);
1796     window->pid       = pid;
1797     window->displayid = 0;              // currently fixed 0
1798     window->raise = 1;                  // created surface is top of layer
1799     window->srcwidth = SurfaceProperties.sourceWidth;
1800     window->srcheight = SurfaceProperties.sourceHeight;
1801     window->width = SurfaceProperties.destWidth;
1802     window->height = SurfaceProperties.destHeight;
1803     window->layerid = 0;
1804
1805     CicoSCLifeCycleController* appctrl;
1806     appctrl = CicoSCLifeCycleController::getInstance();
1807     const CicoAilItems* ailItem = NULL;
1808     const CicoAulItems* aulitem = appctrl->findAUL(window->pid);
1809     if (NULL == aulitem) {
1810         /* client does not exist in AppCore, search parent process  */
1811         ICO_DBG("application information not found. search parent process");
1812
1813         int     fd;
1814         int     cpid = pid;
1815         int     ppid;
1816         int     size;
1817         char    *ppid_line;
1818         char    procpath[PATH_MAX];
1819
1820         while ((cpid > 1) && (aulitem == NULL)) {
1821             snprintf(procpath, sizeof(procpath)-1, "/proc/%d/status", cpid);
1822
1823             fd = open(procpath, O_RDONLY);
1824             if (fd < 0)     break;
1825
1826             size = read(fd, procpath, sizeof(procpath));
1827             close(fd);
1828
1829             if (size <= 0)  break;
1830             ppid_line = strstr(procpath, "PPid");
1831
1832             if (ppid_line == NULL)  break;
1833             ppid = 0;
1834             sscanf(ppid_line, "PPid:    %d", &ppid);
1835             if (ppid <= 1)  break;
1836             ICO_DBG("application pid=%d parent=%d", cpid, ppid);
1837             cpid = ppid;
1838             aulitem = appctrl->findAUL(cpid);
1839         }
1840     }
1841     if (NULL != aulitem) {
1842         window->appid = aulitem->m_appid;
1843         ICO_DBG("appid=%s", window->appid.c_str());
1844         ailItem = appctrl->findAIL(window->appid.c_str());
1845
1846         window->layerid = ailItem->m_layer;
1847         window->zoneid  = ailItem->m_displayZone;
1848         window->nodeid  = ailItem->m_nodeID;
1849         if ((window->displayid >= 0) && (window->zoneid >= 0)) {
1850
1851             const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1852             if (NULL != zone) {
1853                 window->zone   = zone->fullname;
1854                 window->x      = zone->x;
1855                 window->y      = zone->y;
1856                 window->width  = zone->width;
1857                 window->height = zone->height;
1858             }
1859         }
1860     }
1861     else{
1862         delete window;
1863         ICO_WRN("ail item not found.");
1864         ICO_TRA("CicoSCWindowController::createSurfaceCB Leave(ENOENT)");
1865         return;
1866     }
1867
1868     if (ilm_surfaceSetDestinationRectangle(window->surfaceid, window->x, window->y,
1869                  window->width, window->height) != ILM_SUCCESS) {
1870         ICO_ERR("CicoSCWindowController::createSurfaceCB "
1871                 "ilm_surfaceSetDestinationRectangle(%08x) Error", window->surfaceid);
1872     }
1873     else if (ilm_surfaceSetSourceRectangle(window->surfaceid, 0, 0,
1874                  window->width, window->height) != ILM_SUCCESS) {
1875         ICO_ERR("CicoSCWindowController::createSurfaceCB "
1876                 "ilm_surfaceSetSourceRectangle(%08x) Error", window->surfaceid);
1877     }
1878     else if (ilm_surfaceSetOrientation(window->surfaceid, ILM_ZERO) != ILM_SUCCESS) {
1879         ICO_ERR("CicoSCWindowController::createSurfaceCB "
1880                 "ilm_surfaceSetOrientation(%08x) Error", window->surfaceid);
1881     }
1882     else if (ilm_commitChanges() != ILM_SUCCESS)    {
1883         ICO_ERR("CicoSCWindowController::createSurfaceCB ilm_commitChanges() Error");
1884     }
1885
1886     CicoSCLayer *layer = findLayer(window->displayid, window->layerid);
1887     if (layer) {
1888         if (ilm_layerAddSurface(window->layerid, window->surfaceid) != ILM_SUCCESS) {
1889             ICO_ERR("CicoSCWindowController::createSurfaceCB ilm_layerAddSurface(%d,%08x) "
1890                     "Error", window->layerid, window->surfaceid);
1891         }
1892         if (ilm_commitChanges() != ILM_SUCCESS)    {
1893             ICO_ERR("CicoSCWindowController::createSurfaceCB ilm_commitChanges() Error");
1894         }
1895
1896         layer->addSurface(window->surfaceid, true);
1897         int nsurf;
1898         const int *surfs = layer->getSurfaces(&nsurf);
1899         if (ilm_layerSetRenderOrder(window->layerid, (t_ilm_layer *)surfs, nsurf)
1900             != ILM_SUCCESS)   {
1901             ICO_ERR("CicoSCWindowController::createSurfaceCB: "
1902                     "ilm_layerSetRenderOrder(%d,,%d) Error", window->layerid, nsurf);
1903         }
1904         if (ilm_commitChanges() != ILM_SUCCESS)    {
1905             ICO_ERR("CicoSCWindowController::createSurfaceCB ilm_commitChanges() Error");
1906         }
1907     }
1908     // must set surfaceOpacity after surfcaeAddLayer
1909     if (ilm_surfaceSetOpacity(window->surfaceid , (t_ilm_float)1.0f) != ILM_SUCCESS)    {
1910         ICO_ERR("CicoSCWindowController::createSurfaceCB "
1911                             "ilm_surfaceSetOpacity(%08x) Error", window->surfaceid);
1912     }
1913     else if (ilm_commitChanges() != ILM_SUCCESS)    {
1914         ICO_ERR("CicoSCWindowController::createSurfaceCB ilm_commitChanges() Error");
1915     }
1916
1917     appctrl->enterAUL(window->appid.c_str(), window->pid, window);
1918
1919     // dump log window information
1920     window->dump();
1921
1922     m_windowList[window->surfaceid] = window;
1923
1924     // set surface attributes
1925     setAttributes(window->surfaceid);
1926
1927     // send message
1928     CicoSCMessage *message = new CicoSCMessage();
1929     message->addRootObject("command", MSG_CMD_CREATE);
1930     message->addRootObject("appid", window->appid);
1931     message->addRootObject("pid", window->pid);
1932     message->addArgObject("surface", window->surfaceid);
1933     message->addArgObject("winname", window->name);
1934     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1935
1936     if (0 == window->appid.compare(ICO_SC_APPID_DEFAULT_ONS)) {
1937         CicoSCMessageRes *msgOS = new CicoSCMessageRes();
1938         msgOS->addRootObject("command",   MSG_CMD_WINDOW_ID_RES);
1939         msgOS->addRootObject("appid",     window->appid);
1940         msgOS->addRootObject("pid",       window->pid);
1941         msgOS->addWinObject(MSG_PRMKEY_ECU,         "");
1942         msgOS->addWinObject(MSG_PRMKEY_DISPLAY,     "");
1943         msgOS->addWinObject(MSG_PRMKEY_LAYER,       "");
1944         msgOS->addWinObject(MSG_PRMKEY_LAYOUT,      "");
1945         msgOS->addWinObject(MSG_PRMKEY_AREA,        "");
1946         msgOS->addWinObject(MSG_PRMKEY_DISPATCHAPP, "");
1947         msgOS->addWinObject(MSG_PRMKEY_ROLE,        window->name);
1948         msgOS->addWinObject(MSG_PRMKEY_RESOURCEID,  window->surfaceid);
1949         CicoSCServer::getInstance()->sendMessage(window->appid,
1950                                                  (CicoSCMessage*)msgOS);
1951     }
1952
1953     if (NULL != m_resMgr) {
1954         CicoSCCommand cmd;
1955         CicoSCCmdResCtrlOpt *opt = new CicoSCCmdResCtrlOpt();
1956
1957         cmd.cmdid = MSG_CMD_CREATE_RES;
1958         cmd.appid = window->appid;
1959         cmd.pid   = window->pid;
1960         cmd.opt = opt;
1961
1962         opt->dispres   = true;
1963         opt->winname   = window->name;
1964         opt->surfaceid = window->surfaceid;
1965
1966         string fullname;
1967         const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1968         if (NULL != zone) {
1969             opt->dispzone = zone->fullname;
1970         }
1971
1972 #if 1   //TODO
1973         opt->soundres  = true;
1974         opt->soundname = window->appid;
1975         opt->soundid   = 0;
1976         CicoSystemConfig *sysconf = CicoSystemConfig::getInstance();
1977         const CicoSCDefaultConf *defconf = sysconf->getDefaultConf();
1978         if (NULL != defconf) {
1979             const CicoSCSoundZoneConf *zoneconf =
1980                 sysconf->findSoundZoneConfbyId(defconf->soundzone);
1981             if (NULL != zoneconf) {
1982                 opt->soundzone = zoneconf->fullname;
1983             }
1984         }
1985 #endif
1986         m_resMgr->handleCommand((const CicoSCCommand&)cmd, true);
1987     }
1988     else {
1989         show(window->surfaceid, NULL, 0);
1990     }
1991     ICO_TRA("CicoSCWindowController::createSurfaceCB Leave");
1992 }
1993
1994 //--------------------------------------------------------------------------
1995 /**
1996  *  @brief   genivi ivi-shell layer propaty callback
1997  *
1998  *  @param [in] layer           layer id
1999  *  @param [in] LayerProperties layer properties
2000  *  @param [in] mask            change properties
2001  */
2002 //--------------------------------------------------------------------------
2003 void
2004 CicoSCWindowController::wlGeniviLayerNotification(t_ilm_layer layer,
2005                                             struct ilmLayerProperties *LayerProperties,
2006                                             t_ilm_notification_mask mask)
2007 {
2008     ICO_TRA("CicoSCWindowController::wlGeniviLayerNotification Enter(%x,,%x)", layer, mask);
2009
2010     if (mask & ILM_NOTIFICATION_VISIBILITY) {
2011         // change layer visibility, send message to HomeScreen
2012         CicoSCMessage *message = new CicoSCMessage();
2013         message->addRootObject("command", MSG_CMD_CHANGE_LAYER_ATTR);
2014         message->addRootObject("appid", "");
2015         message->addArgObject("layer", layer);
2016         message->addArgObject("visible", LayerProperties->visibility ? 1 : 0);
2017         CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
2018     }
2019     ICO_TRA("CicoSCWindowController::wlGeniviLayerNotification Leave");
2020 }
2021
2022 //--------------------------------------------------------------------------
2023 /**
2024  *  @brief  setup Genivi ivi-shell layer managerment system finctions
2025  *
2026  *  @param      none
2027  */
2028 //--------------------------------------------------------------------------
2029 void
2030 CicoSCWindowController::initializeGeniviLMS(void)
2031 {
2032     t_ilm_uint  NumberOfScreens = 0;
2033     t_ilm_layer *pLayerId, *ppLayerId;
2034     t_ilm_int   LayerNumber;
2035     t_ilm_uint  *pScreenIds;
2036     struct ilmScreenProperties  ScreenProperties;
2037     int                     idxs, idx1, idx2;
2038     int                     DisplayId, LayerId;
2039     const CicoSCDisplayConf *DisplayConf;
2040     const CicoSCLayerConf   *LayerConf;
2041
2042     // get all screen id
2043     if ((ilm_getScreenIDs(&NumberOfScreens, &pScreenIds) != ILM_SUCCESS) ||
2044         (NumberOfScreens <= 0)) {
2045         ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2046                 "ilm_getScreenIDs() Error(num=%d)", NumberOfScreens);
2047         return;
2048     }
2049     ICO_TRA("initializeGeniviLMS: Screens=%d.%x %x", NumberOfScreens, pScreenIds[0],
2050             NumberOfScreens >= 2 ? pScreenIds[1] : 0);
2051     if ((int)NumberOfScreens > CicoSystemConfig::getInstance()->getNumberofDisplay())   {
2052         ICO_WRN("CicoSCWindowController::initializeGeniviLMS # of screens physical=%d config=%d",
2053                 NumberOfScreens, CicoSystemConfig::getInstance()->getNumberofDisplay());
2054         NumberOfScreens = (t_ilm_uint)CicoSystemConfig::getInstance()->getNumberofDisplay();
2055     }
2056 #if 1           /* At present, GENIVI (ivi-controller) is processing only one Display   */
2057     for (idxs = (int)NumberOfScreens - 1; idxs >= 0; idxs--)
2058 #else
2059     for (idxs = 0; idxs < (int)NumberOfScreens; idxs++)
2060 #endif
2061     {
2062         if (ilm_getPropertiesOfScreen(pScreenIds[idxs], &ScreenProperties) != ILM_SUCCESS)   {
2063             ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2064                     "ilm_getPropertiesOfScreen(%d.%x) Error", idxs, pScreenIds[idxs]);
2065             continue;
2066         }
2067         // It is referred to as Center when there is only one display
2068         if (NumberOfScreens == 1)   {
2069             DisplayId = CicoSystemConfig::getInstance()->getDisplayIdbyType(ICO_NODETYPE_CENTER);
2070         }
2071         else    {
2072             DisplayId = CicoSystemConfig::getInstance()->getDisplayIdbyNo((int)pScreenIds[idxs]);
2073         }
2074         ICO_TRA("CicoSCWindowController::initializeGeniviLMS: "
2075                 "Screen[%d.%x] w/h=%d/%d layers=%d DisplayId=%d",
2076                 idxs, pScreenIds[idxs], ScreenProperties.screenWidth,
2077                 ScreenProperties.screenHeight, ScreenProperties.layerCount, DisplayId);
2078
2079         if ((DisplayId < 0) ||
2080             ((DisplayConf = CicoSystemConfig::getInstance()->findDisplayConfbyId(DisplayId))
2081                 == NULL))   {
2082             ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2083                     "ScreenId.%x not found", pScreenIds[idxs]);
2084         }
2085         else    {
2086             // set genivi layers
2087             for (idx1 = 0; ; idx1++)  {
2088                 LayerConf = CicoSystemConfig::getInstance()->
2089                                                 findLayerConfbyIdx(DisplayId, idx1);
2090                 if (! LayerConf)    break;
2091             }
2092             pLayerId = (t_ilm_layer *)malloc(sizeof(t_ilm_layer) * idx1);
2093             ppLayerId = pLayerId;
2094             LayerNumber = 0;
2095
2096             for (idx1 = 0; ; idx1++)  {
2097                 LayerConf = CicoSystemConfig::getInstance()->
2098                                                 findLayerConfbyIdx(DisplayId, idx1);
2099                 if (! LayerConf)    break;
2100
2101                 LayerId = LayerConf->id + DisplayId * ICO_SC_LAYERID_SCREENBASE;
2102                 for (idx2 = 0; idx2 < LayerNumber; idx2++)  {
2103                     if (LayerId == (int)pLayerId[idx2]) break;
2104                 }
2105                 if (idx2 < LayerNumber) {
2106                     ICO_TRA("CicoSCWindowController::initializeGeniviLMS: "
2107                             "layer.%d exist, Skip", LayerId);
2108                     continue;
2109                 }
2110
2111                 if (ilm_layerCreateWithDimension((t_ilm_layer *)&LayerId,
2112                             DisplayConf->width, DisplayConf->height) != ILM_SUCCESS)    {
2113                     ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2114                             "ilm_layerCreateWithDimension(%d,%d,%d) Error",
2115                             LayerId, DisplayConf->width, DisplayConf->height);
2116                 }
2117                 else if (ilm_commitChanges() != ILM_SUCCESS) {
2118                     ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2119                             "ilm_commitChanges() Error");
2120                 }
2121                 else if (ilm_layerSetOpacity(LayerId, (t_ilm_float)1.0f) != ILM_SUCCESS) {
2122                     ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2123                             "ilm_layerSetOpacity(%d) Error", LayerId);
2124                 }
2125                 else if (ilm_layerSetSourceRectangle(LayerId, 0, 0,
2126                              DisplayConf->width, DisplayConf->height) != ILM_SUCCESS)   {
2127                     ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2128                             "ilm_layerSetSourceRectangle(%d) Error", LayerId);
2129                 }
2130                 else if (ilm_layerSetDestinationRectangle(LayerId, 0, 0,
2131                              DisplayConf->width, DisplayConf->height) != ILM_SUCCESS)   {
2132                     ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2133                             "ilm_layerSetDestinationRectangle(%d) Error", LayerId);
2134                 }
2135                 else if (ilm_layerSetOrientation(LayerId, ILM_ZERO) != ILM_SUCCESS) {
2136                     ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2137                             "ilm_layerSetOrientation(%d) Error", LayerId);
2138                 }
2139                 else    {
2140                     if (ilm_commitChanges() != ILM_SUCCESS) {
2141                         ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2142                                 "ilm_commitChanges() Error");
2143                     }
2144                     // SystemController default is layer visible
2145                     if ((ilm_layerSetVisibility(LayerId, 1) != ILM_SUCCESS) ||
2146                         (ilm_commitChanges() != ILM_SUCCESS))   {
2147                         ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2148                                 "ilm_layerSetVisibility() Error");
2149                     }
2150                     ICO_TRA("initializeGeniviLMS: layer=%d created(%d,%d)",
2151                             LayerId, DisplayConf->width, DisplayConf->height);
2152                     *ppLayerId = LayerId;
2153                     ppLayerId ++;
2154                     LayerNumber ++;
2155                 }
2156             }
2157             if (LayerNumber > 0)    {
2158                 ICO_TRA("initializeGeniviLMS: layers %d.%d %d %d %d set to screen %x",
2159                         LayerNumber, pLayerId[0], pLayerId[1], pLayerId[2], pLayerId[3],
2160                         pScreenIds[idxs]);
2161                 if (ilm_displaySetRenderOrder(pScreenIds[idxs], pLayerId, LayerNumber)
2162                     != ILM_SUCCESS)   {
2163                     ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2164                             "ilm_displaySetRenderOrder(%d) Error", LayerNumber);
2165                 }
2166                 else if (ilm_commitChanges() != ILM_SUCCESS) {
2167                     ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2168                             "ilm_commitChanges() Error");
2169                 }
2170                 ppLayerId = pLayerId;
2171                 for (idx2 = 0; idx2 < LayerNumber; idx2++) {
2172                     if (ilm_layerAddNotification(*ppLayerId, wlGeniviLayerNotification)
2173                         != ILM_SUCCESS)   {
2174                         ICO_ERR("CicoSCWindowController::initializeGeniviLMS "
2175                                 "ilm_layerAddNotification(%d) Error", *ppLayerId);
2176                     }
2177                     ppLayerId ++;
2178                 }
2179             }
2180             free(pLayerId);
2181         }
2182     }
2183     free(pScreenIds);
2184 }
2185
2186 //==========================================================================
2187 // private method
2188 //==========================================================================
2189
2190 //--------------------------------------------------------------------------
2191 /**
2192  *  @brief  find window object by surfaceid
2193  *
2194  *  @param [in] surfaceid   wayland surface id
2195  */
2196 //--------------------------------------------------------------------------
2197 CicoSCWindow*
2198 CicoSCWindowController::findWindow(int surfaceid)
2199 {
2200     map<unsigned int, CicoSCWindow*>::iterator itr;
2201     itr = m_windowList.find(surfaceid);
2202     if (m_windowList.end() == itr) {
2203         ICO_TRA("not found window object. surfaceid=%08x", surfaceid);
2204         return NULL;
2205     }
2206
2207     return itr->second;
2208 }
2209
2210 //--------------------------------------------------------------------------
2211 /**
2212  *  @brief  find window object by surfaceid
2213  *
2214  *  @param [in] surfaceid   wayland surface id
2215  */
2216 //--------------------------------------------------------------------------
2217 CicoSCLayer*
2218 CicoSCWindowController::findLayer(int displayid, int layerid)
2219 {
2220     vector<CicoSCDisplay*>::iterator itr;
2221     itr = m_displayList.begin();
2222     for (; itr != m_displayList.end(); ++itr) {
2223         if ((*itr)->displayid != displayid) {
2224             continue;
2225         }
2226         vector<CicoSCLayer*>::iterator itr2;
2227         itr2 = (*itr)->layerList.begin();
2228         for (; itr2 != (*itr)->layerList.end(); ++itr2) {
2229             if ((*itr2)->layerid == layerid) {
2230                 return *itr2;
2231             }
2232         }
2233     }
2234     return NULL;
2235 }
2236
2237 //--------------------------------------------------------------------------
2238 /**
2239  *  @brief  find display zone by id
2240  */
2241 //--------------------------------------------------------------------------
2242 const CicoSCDisplayZone *
2243 CicoSCWindowController::findDisplayZone(int zoneid)
2244 {
2245     vector<CicoSCDisplay*>::iterator itr;
2246     itr = m_displayList.begin();
2247     for (; itr != m_displayList.end(); ++itr) {
2248         std::map<unsigned int, CicoSCDisplayZone*>::iterator itr2;
2249         itr2 = (*itr)->zoneList.find(zoneid);
2250         if ((*itr)->zoneList.end() != itr2) {
2251             return itr2->second;
2252         }
2253     }
2254     return NULL;
2255 }
2256
2257 //--------------------------------------------------------------------------
2258 /**
2259  *  @brief  handle command
2260  *
2261  *  @param [in] cmd     control command
2262  */
2263 //--------------------------------------------------------------------------
2264 void
2265 CicoSCWindowController::handleCommand(const CicoSCCommand * cmd)
2266 {
2267 //    ICO_TRA("CicoSCWindowController::handleCommand Enter(%d)", cmd->cmdid);
2268
2269     CicoSCCmdWinCtrlOpt *opt = static_cast<CicoSCCmdWinCtrlOpt*>(cmd->opt);
2270
2271     switch (cmd->cmdid) {
2272     case MSG_CMD_SHOW:
2273         ICO_DBG("command: MSG_CMD_SHOW");
2274         if (opt->animationTime & ICO_SYC_WIN_SURF_NORESCTL) {
2275             /* show command but not resource control (for HomeScreen)   */
2276             (void)show(opt->surfaceid,
2277                        opt->animation.c_str(),
2278                        opt->animationTime);
2279         }
2280         else {
2281             /* show command (normal)    */
2282             (void)notifyResourceManager(opt->surfaceid,
2283                                         NULL,
2284                                         opt->layerid,
2285                                         opt->animation.c_str(),
2286                                         opt->animationTime);
2287         }
2288         break;
2289     case MSG_CMD_HIDE:
2290         ICO_DBG("command: MSG_CMD_HIDE");
2291         (void)hide(opt->surfaceid, opt->animation.c_str(), opt->animationTime);
2292         break;
2293     case MSG_CMD_MOVE:
2294     {
2295         ICO_DBG("command: MSG_CMD_MOVE");
2296         CicoSCWindow *window = findWindow(opt->surfaceid);
2297         if (NULL == window) {
2298             break;
2299         }
2300         if (true == opt->zone.empty()) {
2301             (void)setGeometry(opt->surfaceid, opt->nodeid, opt->layerid,
2302                               opt->x, opt->y, opt->width, opt->height,
2303                               opt->animation.c_str(), opt->animationTime,
2304                               opt->animation.c_str(), opt->animationTime);
2305         }
2306         else if (opt->zone == window->zone) {
2307             (void)setGeometry(opt->surfaceid, opt->zone.c_str(), opt->layerid,
2308                               opt->animation.c_str(), opt->animationTime,
2309                               opt->animation.c_str(), opt->animationTime);
2310         }
2311         else {
2312             (void)notifyResourceManager(opt->surfaceid,
2313                                         opt->zone.c_str(),
2314                                         opt->layerid,
2315                                         opt->animation.c_str(),
2316                                         opt->animationTime);
2317         }
2318         break;
2319     }
2320     case MSG_CMD_ANIMATION:
2321         ICO_DBG("command: MSG_CMD_ANIMATION");
2322         (void)setWindowAnimation(opt->surfaceid, opt->animationType,
2323                                  opt->animation.c_str(), opt->animationTime);
2324         break;
2325     case MSG_CMD_CHANGE_ACTIVE:
2326         ICO_DBG("command: MSG_CMD_CHANGE_ACTIVE");
2327         (void)active(opt->surfaceid, opt->active);
2328         break;
2329     case MSG_CMD_CHANGE_LAYER:
2330         ICO_DBG("command: MSG_CMD_CHANGE_LAYER");
2331         (void)setWindowLayer(opt->surfaceid, opt->layerid);
2332         break;
2333     case MSG_CMD_MAP_GET:
2334         ICO_DBG("command: MSG_CMD_MAP_GET");
2335         (void)setmapGet(opt->surfaceid, opt->animation.c_str());
2336         break;
2337     case MSG_CMD_MAP_THUMB:
2338         ICO_DBG("command: MSG_CMD_MAP_THUMB");
2339         (void)mapSurface(opt->surfaceid, opt->framerate, opt->animation.c_str());
2340         break;
2341     case MSG_CMD_UNMAP_THUMB:
2342         ICO_DBG("command: MSG_CMD_UNMAP_THUMB");
2343         (void)unmapSurface(opt->surfaceid);
2344         break;
2345     case MSG_CMD_SHOW_LAYER:
2346         ICO_DBG("command: MSG_CMD_SHOW_LAYER");
2347         (void)showLayer(opt->displayid, opt->layerid);
2348         break;
2349     case MSG_CMD_HIDE_LAYER:
2350         ICO_DBG("command: MSG_CMD_HIDE_LAYER");
2351         (void)hideLayer(opt->displayid, opt->layerid);
2352         break;
2353     default:
2354         ICO_WRN("command: Unknown(0x%08x)", cmd->cmdid);
2355         break;
2356     }
2357
2358 //    ICO_TRA("CicoSCWindowController::handleCommand Leave");
2359 }
2360
2361 int
2362 CicoSCWindowController::notifyResourceManager(int        surfaceid,
2363                                               const char *zone,
2364                                               int        layerid,
2365                                               const char *animation,
2366                                               int        animationTime)
2367 {
2368     ICO_TRA("CicoSCWindowController::notifyResourceManager Enter"
2369             "(surfaceid=%08x zone=%s layerid=%d "
2370             "animation=%s animationTime=%d)",
2371             surfaceid, zone, layerid, animation, animationTime);
2372
2373     // find window information in window list
2374     CicoSCWindow *window = findWindow(surfaceid);
2375     if (NULL == window) {
2376         ICO_WRN("not found window information");
2377         ICO_TRA("CicoSCWindowController::notifyResourceManager Leave(ENOENT)");
2378         return ICO_SYC_ENOENT;
2379     }
2380
2381     CicoSCCommand cmd;
2382     CicoSCCmdResCtrlOpt *opt = new CicoSCCmdResCtrlOpt();
2383
2384     cmd.cmdid = MSG_CMD_ACQUIRE_RES;
2385     cmd.appid = window->appid;
2386     cmd.pid   = window->pid;
2387     cmd.opt   = opt;
2388
2389     opt->dispres       = true;
2390     opt->winname       = window->name;
2391     opt->layerid       = layerid;
2392     opt->surfaceid     = window->surfaceid;
2393     opt->animation     = animation ? animation : "";
2394     opt->animationTime = animationTime;
2395     string fullname;
2396     if (NULL == zone) {
2397         const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
2398         if (NULL != zone) {
2399             opt->dispzone = zone->fullname;
2400         }
2401         else {
2402             ICO_WRN("not found zone information");
2403             ICO_TRA("CicoSCWindowController::notifyResourceManager Leave(ENOENT)");
2404             return ICO_SYC_ENOENT;
2405         }
2406     }
2407     else {
2408         opt->dispzone = zone;
2409     }
2410 #if 1   //TODO
2411     opt->soundres  = true;
2412     opt->soundname = window->appid;
2413     opt->soundid   = 0;
2414     CicoSystemConfig *sysconf = CicoSystemConfig::getInstance();
2415     const CicoSCDefaultConf *defconf = sysconf->getDefaultConf();
2416     if (NULL != defconf) {
2417         const CicoSCSoundZoneConf *zoneconf =
2418             sysconf->findSoundZoneConfbyId(defconf->soundzone);
2419         if (NULL != zoneconf) {
2420             opt->soundzone = zoneconf->fullname;
2421         }
2422     }
2423 #endif
2424
2425     m_resMgr->handleCommand((const CicoSCCommand&)cmd, true);
2426
2427     ICO_TRA("CicoSCWindowController::notifyResourceManager Leave(EOK)");
2428     return ICO_SYC_EOK;
2429 }
2430
2431 const CicoSCWindow*
2432 CicoSCWindowController::findWindowObj(int32_t pid, uint32_t surfaceid) const
2433 {
2434     const CicoSCWindow* r = NULL;
2435     map<unsigned int, CicoSCWindow*>::const_iterator itr = m_windowList.begin();
2436     for (; itr != m_windowList.end(); ++itr) {
2437         const CicoSCWindow* tmp = itr->second;
2438         if ((pid == tmp->pid) && (surfaceid == (uint32_t)tmp->surfaceid)) {
2439             r = tmp;
2440             break;  // break of for itr
2441         }
2442     }
2443     ICO_TRA("return %x", r);
2444     return r;
2445 }
2446
2447 const CicoSCResourceManager*
2448 CicoSCWindowController::getResourceManager(void) const
2449 {
2450     return m_resMgr;
2451 }
2452 // vim:set expandtab ts=4 sw=4: