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