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