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