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