55c80324211ed10f31740ffa0a9841af8779a844
[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  
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 "CicoSCSystemConfig.h"
36 #include "CicoSCConf.h"
37 #include "CicoSCDisplay.h"
38 #include "CicoSCLayer.h"
39 #include "CicoSCDisplayZone.h"
40 #include "ico_syc_error.h"
41 #include "CicoSCCommandParser.h"
42 #include "ico_syc_msg_cmd_def.h"
43 #include "CicoSCServer.h"
44 #include "CicoSCMessage.h"
45 #include "CicoSCLifeCycleController.h"
46 #include "CicoSCResourceManager.h"
47
48 //--------------------------------------------------------------------------
49 /**
50  *  @brief  default constructor
51  */
52 //--------------------------------------------------------------------------
53 CicoSCWindowController::CicoSCWindowController()
54     : m_resMgr(NULL)
55 {
56     CicoSCWayland* wayland = CicoSCWayland::getInstance();
57     wayland->getInstance()->addWaylandIF(ICO_WL_WIN_MGR_IF, this);
58     wayland->getInstance()->addWaylandIF(ICO_WL_OUTPUT_IF, this);
59     wayland->getInstance()->addWaylandIF(ICO_WL_SHM_IF, this);
60     initDB();
61 }
62
63 //--------------------------------------------------------------------------
64 /**
65  *  @brief  destructor
66  */
67 //--------------------------------------------------------------------------
68 CicoSCWindowController::~CicoSCWindowController()
69 {
70 }
71
72 //--------------------------------------------------------------------------
73 /**
74  *  @brief  initialize display and window database
75  */
76 //--------------------------------------------------------------------------
77 int
78 CicoSCWindowController::initDB(void)
79 {
80     ICO_DBG("CicoSCWindowController::initDB: Enter");
81
82     const vector<CicoSCDisplayConf*>& displayList =
83             CicoSCSystemConfig::getInstance()->getDisplayConfList();
84     vector<CicoSCDisplayConf*>::const_iterator itr;
85     itr = displayList.begin();
86     for (; itr != displayList.end(); ++itr) {
87         const CicoSCDisplayConf *dconf = const_cast<CicoSCDisplayConf*>(*itr);
88         CicoSCDisplay *display = new CicoSCDisplay();
89
90         display->displayid = dconf->id;
91         display->type      = dconf->type;
92         display->nodeid    = dconf->node;
93         display->displayno = dconf->no;
94         display->width     = dconf->width;
95         display->height    = dconf->height;
96         display->inch      = dconf->inch;
97         display->name      = dconf->name;
98
99         vector<CicoSCLayerConf*>::const_iterator itr2;
100         itr2 = dconf->layerConfList.begin();
101         for (; itr2 != dconf->layerConfList.end(); ++itr2) {
102             const CicoSCLayerConf *lconf = const_cast<CicoSCLayerConf*>(*itr2);
103
104             CicoSCLayer *layer = new CicoSCLayer();
105             layer->layerid     = lconf->id;
106             layer->type        = lconf->type;
107             layer->width       = display->width;
108             layer->height      = display->height;
109             layer->displayid   = display->displayid;
110             layer->menuoverlap = lconf->menuoverlap;
111             display->layerList.push_back(layer);
112         }
113
114         vector<CicoSCDisplayZoneConf*>::const_iterator itr3;
115         itr3 = dconf->zoneConfList.begin();
116         for (; itr3 != dconf->zoneConfList.end(); ++itr3) {
117 //            const CicoSCDisplayZoneConf *dzconf = const_cast<CicoSCLayerConf*>(*itr2);
118
119             CicoSCDisplayZone *zone = new CicoSCDisplayZone();
120             zone->zoneid = (*itr3)->id;
121             zone->x      = (*itr3)->x;
122             zone->y      = (*itr3)->y;
123             zone->width  = (*itr3)->w;
124             zone->height = (*itr3)->h;
125             display->zoneList.push_back(zone);
126         }
127         display->dump();
128         m_displayList.push_back(display);
129
130         display->dump();
131         m_displayList.push_back(display);
132     }
133
134     ICO_DBG("CicoSCWindowController::initDB: Leave");
135     return ICO_SYC_EOK;
136 }
137
138 //--------------------------------------------------------------------------
139 /**
140  *  @brief   set resource manager instance
141  *
142  *  @param [in] resMgr  resource manager instance
143  */
144 //--------------------------------------------------------------------------
145 void
146 CicoSCWindowController::setResourceManager(CicoSCResourceManager *resMgr)
147 {
148     m_resMgr = resMgr;
149 }
150
151 //--------------------------------------------------------------------------
152 /**
153  *  @brief   show a target window
154  *
155  *  @param [in] surfaceid       wayland surface id
156  *  @param [in] animation       animation name
157  *  @param [in] animationTime   animation time
158  *
159  *  @return ICO_SYC_EOK on success, other on error
160  *  @retval ICO_SYC_EOK         success
161  *  @retval ICO_SYC_ESRCH       error(not initialized)
162  *  @retval ICO_SYC_ENOENT      error(not exist)
163  */
164 //--------------------------------------------------------------------------
165 int
166 CicoSCWindowController::show(int        surfaceid,
167                              const char *animation,
168                              int        animationTime)
169 {
170     ICO_DBG("CicoSCWindowController::show Enter"
171             "(surfaceid=%08X animation=%s animationTime=%d)",
172             surfaceid, animation, animationTime);
173
174     // find window infomation in window list
175     CicoSCWindow *window = findWindow(surfaceid);
176     if (NULL == window) {
177         ICO_WRN("CicoSCWindowController::show Leave(ENOENT)");
178         return ICO_SYC_ENOENT;
179     }
180
181     // update visible attr
182     window->visible = true;
183
184     // set animation request to Multi Window Manager
185     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
186     int raiseFlag = ICO_WINDOW_MGR_RAISE_RAISE;
187     if ((NULL != animation) && (animation[0] != '\0')) {
188         ICO_DBG("ico_window_mgr_set_animation"
189                 "(surface=0x%08X type=%d anima=%s time=%d)",
190                 window->surfaceid,
191                 ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW,
192                 animation, animationTime);
193         ico_window_mgr_set_animation(m_winmgr,
194                                      window->surfaceid,
195                                      ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW,
196                                      animation,
197                                      animationTime);
198         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
199         raiseFlag = ICO_WINDOW_MGR_V_NOCHANGE;
200     }
201
202     // show request to Multi Window Manager
203     ICO_DBG("ico_window_mgr_set_visible called."
204             "(surfaceid=0x%08X visible=%d raise=%d anima=%d",
205             window->surfaceid, ICO_WINDOW_MGR_VISIBLE_SHOW,
206             raiseFlag, animaFlag);
207     ico_window_mgr_set_visible(m_winmgr,
208                                window->surfaceid,
209                                ICO_WINDOW_MGR_VISIBLE_SHOW,
210                                raiseFlag,
211                                animaFlag);
212
213     // flush display 
214     CicoSCWayland::getInstance()->flushDisplay();
215
216     ICO_DBG("CicoSCWindowController::show Leave(EOK)");
217     return ICO_SYC_EOK;
218 }
219
220 //--------------------------------------------------------------------------
221 /**
222  *  @brief   hide a target window
223  *
224  *  @param [in] surfaceid       wayland surface id
225  *  @param [in] animation       animation name
226  *  @param [in] animationTime   animation time
227  *
228  *  @return ICO_SYC_EOK on success, other on error
229  *  @retval ICO_SYC_EOK         success
230  *  @retval ICO_SYC_ESRCH       error(not initialized)
231  *  @retval ICO_SYC_ENOENT      error(not exist)
232  */
233 //--------------------------------------------------------------------------
234 int
235 CicoSCWindowController::hide(int        surfaceid,
236                              const char *animation,
237                              int        animationTime)
238 {
239     ICO_DBG("CicoSCWindowController::hide Enter"
240             "(surfaceid=%08X animation=%s animationTime=%d)",
241             surfaceid, animation, animationTime);
242
243     // find window infomation in window list
244     CicoSCWindow *window = findWindow(surfaceid);
245     if (NULL == window) {
246         ICO_WRN("CicoSCWindowController::hide Leave(ENOENT)");
247         return ICO_SYC_ENOENT;
248     }
249
250     // update window attr
251     window->visible = false;
252
253     // set animation request to Multi Window Manager
254     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
255     if ((NULL != animation) && (animation[0] != '\0')) {
256         ico_window_mgr_set_animation(m_winmgr,
257                                      window->surfaceid,
258                                      ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE,
259                                      animation,
260                                      animationTime);
261         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
262     }
263
264     // show request to Multi Window Manager
265     ico_window_mgr_set_visible(m_winmgr,
266                                window->surfaceid,
267                                ICO_WINDOW_MGR_VISIBLE_HIDE,
268                                ICO_WINDOW_MGR_V_NOCHANGE,
269                                animaFlag);
270
271     // flush display 
272     CicoSCWayland::getInstance()->flushDisplay();
273
274     ICO_DBG("CicoSCWindowController::hide Leave(EOK)");
275     return ICO_SYC_EOK;
276 }
277
278 //--------------------------------------------------------------------------
279 /**
280  *  @brief   resize window(surface) size
281  *
282  *  @param [in] surfaceid       wayland surface id
283  *  @param [in] w               window width
284  *  @param [in] h               window height
285  *  @param [in] animation       animation name
286  *  @param [in] animationTime   animation time
287  *
288  *  @return ICO_SYC_EOK on success, other on error
289  *  @retval ICO_SYC_EOK         success
290  *  @retval ICO_SYC_ESRCH       error(not initialized)
291  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
292  */
293 //--------------------------------------------------------------------------
294 int
295 CicoSCWindowController::resize(int        surfaceid,
296                                int        w,
297                                int        h,
298                                const char *animation,
299                                int        animationTime)
300 {
301     ICO_DBG("CicoSCWindowController::resize Enter"
302             "(surfaceid=%08X h=%d w=%d animation=%s animationTime=%d)",
303             surfaceid, w, h, animation, animationTime);
304
305     // find window infomation in window list
306     CicoSCWindow *window = findWindow(surfaceid);
307     if (NULL == window) {
308         ICO_WRN("CicoSCWindowController::resize Leave(ENOENT)");
309         return ICO_SYC_ENOENT;
310     }
311
312     // set animation request to Multi Window Manager
313     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
314     if ((NULL != animation) && (animation[0] != '\0')) {
315         ico_window_mgr_set_animation(m_winmgr,
316                                      window->surfaceid,
317                                      ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE,
318                                      animation,
319                                      animationTime);
320         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
321     }
322
323     // set visible request to Multi Window Manager
324     ico_window_mgr_set_positionsize(m_winmgr,
325                                     window->surfaceid,
326                                     0, //ICO_WINDOW_MGR_V_NOCHANGE,
327                                     ICO_WINDOW_MGR_V_NOCHANGE,
328                                     ICO_WINDOW_MGR_V_NOCHANGE,
329                                     w,
330                                     h,
331                                     animaFlag);
332
333     // flush display 
334     CicoSCWayland::getInstance()->flushDisplay();
335
336     ICO_DBG("CicoSCWindowController::resize Leave(EOK)");
337     return ICO_SYC_EOK;
338 }
339
340 //--------------------------------------------------------------------------
341 /**
342  *  @brief  move window(surface) size 
343  *
344  *  @param [in] surfaceid       wayland surface id
345  *  @param [in] nodeid          node id
346  *  @param [in] x               window width
347  *  @param [in] y               window height
348  *  @param [in] animation       animation name
349  *  @param [in] animationTime   animation time
350  *
351  *  @return ICO_SYC_EOK on success, other on error
352  *  @retval ICO_SYC_EOK         success
353  *  @retval ICO_SYC_ESRCH       error(not initialized)
354  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
355  */
356 //--------------------------------------------------------------------------
357 int
358 CicoSCWindowController::move(int        surfaceid,
359                              int        nodeid,
360                              int        x,
361                              int        y,
362                              const char *animation,
363                              int        animationTime)
364 {
365     ICO_DBG("CicoSCWindowController::move Enter"
366             "(surfaceid=%08X nodeid=%d x=%d y=%d "
367             "animation=%s animationTime=%d)",
368             surfaceid, nodeid, x, y, animation, animationTime);
369
370     // find window infomation in window list
371     CicoSCWindow *window = findWindow(surfaceid);
372     if (NULL == window) {
373         ICO_WRN("CicoSCWindowController::move Leave(ENOENT)");
374         return ICO_SYC_ENOENT;
375     }
376
377     // set animation request to Multi Window Manager
378     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
379     if ((NULL != animation) && (animation[0] != '\0')) {
380         ico_window_mgr_set_animation(m_winmgr,
381                                      window->surfaceid,
382                                      ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE,
383                                      animation,
384                                      animationTime);
385         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
386     }
387
388     int moveNodeId = ICO_WINDOW_MGR_V_NOCHANGE;
389     if (nodeid >= 0) {
390         moveNodeId = nodeid;
391     }
392
393     // set visible request to Multi Window Manager
394     ico_window_mgr_set_positionsize(m_winmgr,
395                                     window->surfaceid,
396                                     moveNodeId,
397                                     x,
398                                     y,
399                                     ICO_WINDOW_MGR_V_NOCHANGE,
400                                     ICO_WINDOW_MGR_V_NOCHANGE,
401                                     animaFlag);
402
403     // flush display 
404     CicoSCWayland::getInstance()->flushDisplay();
405
406     ICO_DBG("CicoSCWindowController::move Leave(EOK)");
407     return ICO_SYC_EOK;
408 }
409
410 //--------------------------------------------------------------------------
411 /**
412  *  @brief  raise window(surface)
413  *
414  *  @param [in] surfaceid       wayland surface id
415  *  @param [in] animation       animation name
416  *  @param [in] animationTime   animation time
417  *
418  *  @return ICO_SYC_EOK on success, other on error
419  *  @retval ICO_SYC_EOK         success
420  *  @retval ICO_SYC_ESRCH       error(not initialized)
421  *  @retval ICO_SYC_ENOENT      error(layer dose not exist)
422  */
423 //--------------------------------------------------------------------------
424 int
425 CicoSCWindowController::raise(int        surfaceid,
426                               const char *animation,
427                               int        animationTime)
428 {
429     ICO_DBG("CicoSCWindowController::raise Enter"
430             "(surfaceid=%08X animation=%s animationTime=%d)",
431             surfaceid, animation, animationTime);
432
433     // find window infomation in window list
434     CicoSCWindow *window = findWindow(surfaceid);
435     if (NULL == window) {
436         ICO_WRN("CicoSCWindowController::raise Leave(ENOENT)");
437         return ICO_SYC_ENOENT;
438     }
439
440     // update visible attr
441     window->raise = true;
442
443     // set animation request to Multi Window Manager
444     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
445     if ((NULL != animation) && (animation[0] != '\0')) {
446         ico_window_mgr_set_animation(m_winmgr,
447                                      window->surfaceid,
448                                      ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW,
449                                      animation,
450                                      animationTime);
451         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
452     }
453
454     // set visible request to Multi Window Manager
455     ico_window_mgr_set_visible(m_winmgr,
456                                window->surfaceid,
457                                ICO_WINDOW_MGR_V_NOCHANGE,
458                                ICO_WINDOW_MGR_RAISE_RAISE,
459                                animaFlag);
460
461     // flush display 
462     CicoSCWayland::getInstance()->flushDisplay();
463
464     ICO_DBG("CicoSCWindowController::raise Leave(EOK)");
465     return ICO_SYC_EOK;
466 }
467
468 //--------------------------------------------------------------------------
469 /**
470  *  @brief  set window(surface) geometry
471  *
472  *  @param [in] surfaceid           wayland surface id
473  *  @param [in] nodeid              node id
474  *  @param [in] x                   window x position
475  *  @param [in] y                   window y position
476  *  @param [in] w                   window width
477  *  @param [in] h                   window height
478  *  @param [in] resizeAnimation     resize animation name
479  *  @param [in] resizeAnimationTime resize animation time
480  *  @param [in] moveAnimation       move animation name
481  *  @param [in] moveanimationTime   move animation time
482  *
483  *  @return ICO_SYC_EOK on success, other on error
484  *  @retval ICO_SYC_EOK         success
485  *  @retval ICO_SYC_ESRCH       error(not initialized)
486  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
487  */
488 //--------------------------------------------------------------------------
489 int
490 CicoSCWindowController::setGeometry(int        surfaceid,
491                                     int        nodeid,
492                                     int        x,
493                                     int        y,
494                                     int        w,
495                                     int        h,
496                                     const char *resizeAnimation,
497                                     int        resizeAnimationTime,
498                                     const char *moveAnimation,
499                                     int        moveAnimationTime)
500 {
501     ICO_DBG("CicoSCWindowController::setGeometry Enter"
502             "(surfaceid=0x%08X nodeid=%d x=%d y=%d w=%d h=%d "
503             "resizeAnimation=%s resizeAnimationTime=%d "
504             "moveAnimation=%s moveAnimationTime=%d)",
505             surfaceid, nodeid, x, y, w, h,
506             resizeAnimation, resizeAnimationTime,
507             moveAnimation, moveAnimationTime);
508
509     // find window infomation in window list
510     CicoSCWindow *window = findWindow(surfaceid);
511     if (NULL == window) {
512         ICO_WRN("CicoSCWindowController::setGeometry Leave(ENOENT)");
513         return ICO_SYC_ENOENT;
514     }
515
516     // set animation request to Multi Window Manager
517     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
518     if (NULL != resizeAnimation) {
519         ico_window_mgr_set_animation(m_winmgr,
520                                      window->surfaceid,
521                                      ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE,
522                                      resizeAnimation,
523                                      resizeAnimationTime);
524         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
525     }
526
527     if (NULL != moveAnimation) {
528         ico_window_mgr_set_animation(m_winmgr,
529                                      window->surfaceid,
530                                      ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE,
531                                      moveAnimation,
532                                      moveAnimationTime);
533         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
534     }
535
536     int moveNodeId = ICO_WINDOW_MGR_V_NOCHANGE;
537     if (nodeid >= 0) {
538         moveNodeId = nodeid;
539     }
540     else {
541         moveNodeId = window->nodeid;
542     }
543
544     // set visible request to Multi Window Manager
545     ICO_DBG("ico_window_mgr_set_positionsize"
546             "(surfaceid=0x%08X nodeid=%d x=%d y=%d w=%d h=%d anima=%d)",
547             window->surfaceid, moveNodeId, x, y, w, h, animaFlag);
548     ico_window_mgr_set_positionsize(m_winmgr,
549                                     window->surfaceid,
550                                     moveNodeId,
551                                     x,
552                                     y,
553                                     w,
554                                     h,
555                                     animaFlag);
556
557     // flush display 
558     CicoSCWayland::getInstance()->flushDisplay();
559
560     ICO_DBG("CicoSCWindowController::setGeometry Leave(EOK)");
561     return ICO_SYC_EOK;
562 }
563
564
565 //--------------------------------------------------------------------------
566 /**
567  *  @brief  lower window(surface)
568  *
569  *  @param [in] surfaceid       wayland surface id
570  *  @param [in] animation       animation name
571  *  @param [in] animationTime   animation time
572  *
573  *  @return ICO_SYC_EOK on success, other on error
574  *  @retval ICO_SYC_EOK         success
575  *  @retval ICO_SYC_ESRCH       error(not initialized)
576  *  @retval ICO_SYC_ENOENT      error(layer dose not exist)
577  */
578 //--------------------------------------------------------------------------
579 int
580 CicoSCWindowController::lower(int        surfaceid,
581                               const char *animation,
582                               int        animationTime)
583 {
584     ICO_DBG("CicoSCWindowController::lower Enter"
585             "(surfaceid=%08X animation=%s animationTime=%d)",
586             surfaceid, animation, animationTime);
587
588     // find window infomation in window list
589     CicoSCWindow *window = findWindow(surfaceid);
590     if (NULL == window) {
591         ICO_WRN("CicoSCWindowController::lower Leave(ENOENT)");
592         return ICO_SYC_ENOENT;
593     }
594
595     // update visible attr
596     window->raise = false;
597
598     // set animation request to Multi Window Manager
599     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
600     if ((NULL != animation) && (animation[0] != '\0')) {
601         ico_window_mgr_set_animation(m_winmgr,
602                                      window->surfaceid,
603                                      ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE,
604                                      animation,
605                                      animationTime);
606         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
607     }
608
609     // set visible request to Multi Window Manager
610     ico_window_mgr_set_visible(m_winmgr,
611                                window->surfaceid,
612                                ICO_WINDOW_MGR_V_NOCHANGE,
613                                ICO_WINDOW_MGR_RAISE_LOWER,
614                                animaFlag);
615
616     // flush display 
617     CicoSCWayland::getInstance()->flushDisplay();
618
619     ICO_DBG("CicoSCWindowController::lower Leave(EOK)");
620     return ICO_SYC_EOK;
621 }
622
623 //--------------------------------------------------------------------------
624 /**
625  *  @brief  set window layer
626  *
627  *  @param [in] surfaceid       wayland surface id
628  *  @param [in] layer           layer id
629  *
630  *  @return ICO_SYC_EOK on success, other on error
631  *  @retval ICO_SYC_EOK         success
632  *  @retval ICO_SYC_ESRCH       error(not initialized)
633  *  @retval ICO_SYC_ENOENT      error(window or layer dose not exist)
634  */
635 //--------------------------------------------------------------------------
636 int
637 CicoSCWindowController::setWindowLayer(int surfaceid, int layerid)
638 {
639     ICO_DBG("CicoSCWindowController::setWindowLayer Enter"
640             "(surfaceid=%08X layerid=%d)", surfaceid, layerid);
641
642     // find window infomation in window list
643     CicoSCWindow *window = findWindow(surfaceid);
644     if (NULL == window) {
645         ICO_WRN("CicoSCWindowController::setWindowLayer Leave(ENOENT)");
646         return ICO_SYC_ENOENT;
647     }
648
649     // find layer infomation in layer list
650     CicoSCLayer* layer = findLayer(window->displayid, layerid);
651     if (NULL == layer) {
652         ICO_WRN("CicoSCWindowController::setWindowLayer Leave(ENOENT)");
653         return ICO_SYC_ENOENT;
654     }
655
656     // update window attr
657     window->layerid = layerid;
658
659     // set window layer request to Multi Window Manager
660     ICO_DBG("ico_window_mgr_set_window_layer called."
661             "surfaceid=0x%08X layerid=%d",
662             window->surfaceid, window->layerid);
663     ico_window_mgr_set_window_layer(m_winmgr,
664                                     window->surfaceid,
665                                     window->layerid);
666
667     // flush display 
668     CicoSCWayland::getInstance()->flushDisplay();
669
670     ICO_DBG("CicoSCWindowController::setWindowLayer Leave(EOK)");
671     return ICO_SYC_EOK;
672 }
673
674 //--------------------------------------------------------------------------
675 /**
676  *  @brief   show layer 
677  *
678  *  @param [in] displayid   display id
679  *  @param [in] layerid     layer id
680  *
681  *  @return ICO_SYC_EOK on success, other on error
682  *  @retval ICO_SYC_EOK     success
683  *  @retval ICO_SYC_ESRCH   error(not initialized)
684  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
685  */
686 //--------------------------------------------------------------------------
687 int
688 CicoSCWindowController::showLayer(int displayid, int layerid)
689 {
690     ICO_DBG("CicoSCWindowController::showLayer Enter"
691             "displayid=%d layerid=%d)", displayid, layerid);
692
693     // find layer infomation in layer list
694     CicoSCLayer* layer = findLayer(displayid, layerid);
695     if (NULL == layer) {
696         ICO_WRN("CicoSCWindowController::showLayer Leave(ENOENT)");
697         return ICO_SYC_ENOENT;
698     }
699
700     setLayerVisible(layerid, ICO_WINDOW_MGR_VISIBLE_SHOW);
701
702     // flush display 
703     CicoSCWayland::getInstance()->flushDisplay();
704
705     ICO_DBG("CicoSCWindowController::showLayer Leave(EOK)");
706     return ICO_SYC_EOK;
707 }
708
709 //--------------------------------------------------------------------------
710 /**
711  *  @brief   show layer 
712  *
713  *  @param [in] displayid   display id
714  *  @param [in] layerid     layer id
715  *
716  *  @return ICO_SYC_EOK on success, other on error
717  *  @retval ICO_SYC_EOK     success
718  *  @retval ICO_SYC_ESRCH   error(not initialized)
719  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
720  */
721 //--------------------------------------------------------------------------
722 int
723 CicoSCWindowController::hideLayer(int displayid, int layerid)
724 {
725     ICO_DBG("CicoSCWindowController::hideLayer Enter"
726             "displayid=%d layerid=%d)",
727             displayid, layerid);
728
729     // find layer infomation in layer list
730     CicoSCLayer* layer = findLayer(displayid, layerid);
731     if (NULL == layer) {
732         ICO_WRN("CicoSCWindowController::hideLayer Leave(ENOENT)");
733         return ICO_SYC_ENOENT;
734     }
735
736     setLayerVisible(layerid, ICO_WINDOW_MGR_VISIBLE_HIDE);
737
738     // flush display 
739     CicoSCWayland::getInstance()->flushDisplay();
740
741     ICO_DBG("CicoSCWindowController::hideVisible Leave(EOK)");
742     return ICO_SYC_EOK;
743 }
744
745 //--------------------------------------------------------------------------
746 /**
747  *  @brief   control layer visibility
748  *
749  *  @param [in] layerid     layer id
750  *  @param [in] visible     layer show
751  *                          ICO_WINDOW_MGR_VISIBLE_SHOW
752  *                          ICO_WINDOW_MGR_VISIBLE_HIDE
753  */
754 //--------------------------------------------------------------------------
755 void
756 CicoSCWindowController::setLayerVisible(int layerid, int visible)
757 {
758     // set layer visible request to Multi Window Manager
759     ICO_DBG("ico_window_mgr_set_layer_visible(%d,%d) called.",
760             layerid, visible);
761     ico_window_mgr_set_layer_visible(m_winmgr, layerid, visible);
762 }
763
764 //--------------------------------------------------------------------------
765 /**
766  *  @brief   active window(surface)
767  *
768  *  @param [in] surfaceid   wayland surface id
769  *  @param [in] target      target(pointer and/or keyboard)
770  *
771  *  @return ICO_SYC_EOK on success, other on error
772  *  @retval ICO_SYC_EOK     success
773  *  @retval ICO_SYC_ESRCH   error(not initialized)
774  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
775  */
776 //--------------------------------------------------------------------------
777 int
778 CicoSCWindowController::active(int surfaceid, int target)
779 {
780 #if 0
781     Ico_Uxf_Mng_Window  *winmng;
782     Ico_Uxf_Mng_Process *proc;
783     Ico_Uxf_Mng_Process *aproc;
784     int                 hash;
785 #endif
786
787     ICO_DBG("CicoSCWindowController::active Enter"
788             "(surfaceid=%08X, target=%08X)", surfaceid, target);
789
790     // find window infomation in window list
791     CicoSCWindow *window = findWindow(surfaceid);
792     if (NULL == window) {
793         ICO_WRN("CicoSCWindowController::active Leave(ENOENT)");
794         return ICO_SYC_ENOENT;
795     }
796
797     if (target < 0) {
798         target = ICO_WINDOW_MGR_ACTIVE_POINTER  |
799                  ICO_WINDOW_MGR_ACTIVE_KEYBOARD |
800                  ICO_WINDOW_MGR_ACTIVE_SELECTED;
801     }
802
803     ICO_DBG("ico_window_mgr_set_active(0x%08X, %d) called.",
804             surfaceid, target);
805     // set active request to Multi Window Manager
806     ico_window_mgr_set_active(m_winmgr, window->surfaceid, target);
807
808     // flush display 
809     CicoSCWayland::getInstance()->flushDisplay();
810
811     // update active window
812     map<unsigned int, CicoSCWindow*>::iterator itr;
813     itr = m_windowList.begin();
814     for (; itr != m_windowList.end(); ++itr) {
815         CicoSCWindow* window = itr->second;
816         if (window->surfaceid == surfaceid) {
817             window->active = target;
818         }
819         else {
820             if (target == 0) {
821                 window->active = 0;
822             }
823             else {
824                 window->active &= ~target;
825             }
826         }
827     }
828
829     // TODO update active application
830 #if 0
831     /* reset all active application without this application    */
832     aproc = NULL;
833     for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++)    {
834         proc = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
835         while (proc)    {
836             if (proc->attr.mainwin.window == window)    {
837                 aproc = proc;
838             }
839             else    {
840                 if (target == 0)    {
841                     proc->attr.active = 0;
842                 }
843                 else    {
844                     proc->attr.active &= ~target;
845                 }
846             }
847             proc = proc->nextidhash;
848         }
849     }
850     aproc->attr.active = target;
851 #endif
852
853     ICO_DBG("CicoSCWindowController::active Leave(EOK)");
854     return ICO_SYC_EOK;
855 }
856
857 //--------------------------------------------------------------------------
858 /**
859  *  @brief   map surface
860  *
861  *  @param [in] surfaceid   wayland surface id
862  *
863  *  @return ICO_SYC_EOK on success, other on error
864  *  @retval ICO_SYC_EOK     success
865  *  @retval ICO_SYC_ESRCH   error(not initialized)
866  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
867  */
868 //--------------------------------------------------------------------------
869 int
870 CicoSCWindowController::mapSurface(int surfaceid, int framerate)
871 {
872     ICO_WRN("CicoSCWindowController::mapSurface Enter");
873
874     // find window infomation in window list
875     CicoSCWindow *window = findWindow(surfaceid);
876     if (NULL == window) {
877         ICO_WRN("CicoSCWindowController::mapSurface Leave(ENOENT)");
878         return ICO_SYC_ENOENT;
879     }
880
881     if (framerate <= 0) {
882         framerate = 15;
883     }
884
885     ICO_DBG("ico_window_mgr_map_surface(%d, %d) called.",
886             surfaceid, framerate);
887     ico_window_mgr_map_surface(m_winmgr, surfaceid, framerate);
888     ICO_DBG("CicoSCWindowController::mapSurface Leave(EOK)");
889     return ICO_SYC_EOK;
890 }
891
892 //--------------------------------------------------------------------------
893 /**
894  *  @brief   unmap surface
895  *
896  *  @param [in] surfaceid   wayland surface id
897  *
898  *  @return ICO_SYC_EOK on success, other on error
899  *  @retval ICO_SYC_EOK     success
900  *  @retval ICO_SYC_ESRCH   error(not initialized)
901  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
902  */
903 //--------------------------------------------------------------------------
904 int
905 CicoSCWindowController::unmapSurface(int surfaceid)
906 {
907     ICO_DBG("CicoSCWindowController::unmapSurface Enter");
908
909     // find window infomation in window list
910     CicoSCWindow *window = findWindow(surfaceid);
911     if (NULL == window) {
912         ICO_WRN("CicoSCWindowController::unmapSurface Leave(ENOENT)");
913         return ICO_SYC_ENOENT;
914     }
915
916     ICO_DBG("ico_window_mgr_unmap_surface(%d) called.", surfaceid);
917     ico_window_mgr_unmap_surface(m_winmgr, surfaceid);
918
919     ICO_DBG("CicoSCWindowController::unmapSurface Leave(EOK)");
920     return ICO_SYC_EOK;
921 }
922
923 //--------------------------------------------------------------------------
924 /** 
925  *  @brief   wayland surface create callback
926  *  
927  *  @param [in] data            user data(unused)
928  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
929  *  @param [in] surfaceid       ico_window_mgr surface Id
930  *  @param [in] winname         surface window name(title)
931  *  @param [in] pid             wayland client process Id
932  *  @param [in] appid           wayland client application Id
933  */
934 //--------------------------------------------------------------------------
935 void
936 CicoSCWindowController::createdCB(void                  *data,
937                                   struct ico_window_mgr *ico_window_mgr,
938                                   uint32_t              surfaceid,
939                                   const char            *winname,
940                                   int32_t               pid,
941                                   const char            *appid)
942 {
943     ICO_DBG("CicoSCWindowController::createdCB Enter"
944             "(surfaceid=%08X winname=%s pid=%d appid=%s)",
945             surfaceid, winname, pid, appid);
946
947     CicoSCWindow* window = new CicoSCWindow();
948
949     window->surfaceid = surfaceid;
950     window->name      = winname;
951     window->appid     = appid;
952     window->pid       = pid;
953     window->displayid = ICO_SURFACEID_2_NODEID(surfaceid);
954
955     CicoSCLifeCycleController* appctrl;
956     appctrl = CicoSCLifeCycleController::getInstance();
957     const CicoSCAilItems *ailItem = appctrl->findAIL(appid);
958     if (NULL == ailItem) {
959         const CicoSCAulItems* aulitem = appctrl->findAUL(pid);
960         if (NULL != aulitem) {
961             window->appid = aulitem->m_appid;
962             ICO_DBG("appid=%s", window->appid.c_str());
963             ailItem = appctrl->findAIL(window->appid.c_str());
964         }
965         else {
966             ICO_DBG("aulitem not found.");
967         }
968     }
969
970     string fullZoneName;
971     if (NULL != ailItem) {
972         window->layerid = ailItem->m_layer;
973         window->zoneid  = ailItem->m_displayZone;
974         window->nodeid  = ailItem->m_nodeID;
975         if ((window->displayid >= 0) && (window->zoneid >= 0)) {
976             // TODO at errer try catch
977             CicoSCDisplay* display = m_displayList.at(window->displayid);
978             CicoSCDisplayZone *zone = display->zoneList.at(window->zoneid);
979             window->x       = zone->x;
980             window->y       = zone->y;
981             window->width   = zone->width;
982             window->height  = zone->height;
983
984             //TODO
985             //fullZoneName = display->name + "." + zone->name;
986             fullZoneName = "Center.Full";
987         }
988     }
989     else{
990         ICO_WRN("ail item not found.");
991         ICO_WRN("CicoSCWindowController::createdCB Leave(ENOENT)");
992         return;
993     }
994
995     appctrl->enterAUL(appid, pid, window);
996
997     // dump log window infomartion
998     window->dump();
999
1000     m_windowList[surfaceid] = window;
1001
1002     // send message
1003     CicoSCMessage *message = new CicoSCMessage();
1004     message->addRootObject("command", MSG_CMD_CREATE);
1005     message->addRootObject("appid", window->appid);
1006     message->addArgObject("surface", window->surfaceid);
1007     message->addArgObject("winname", window->name);
1008     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1009
1010     if (NULL != m_resMgr) {
1011         CicoSCCommand cmd;
1012         CicoSCCmdResCtrlOpt *opt = new CicoSCCmdResCtrlOpt();
1013
1014         cmd.cmdid = MSG_CMD_ACQUIRE_RES;
1015         cmd.appid = window->appid;
1016         cmd.pid   = window->pid;
1017         cmd.opt = opt;
1018         
1019         opt->displayres  = true;
1020         opt->displayZone = fullZoneName;
1021         opt->windowName  = window->name;
1022         opt->surfaceid   = window->surfaceid;
1023
1024         m_resMgr->handleCommand((const CicoSCCommand&)cmd, true);
1025     }
1026     else {
1027         //show(window->surfaceid, NULL, 0);
1028     }
1029
1030     ICO_DBG("CicoSCWindowController::createdCB Leave");
1031 }
1032
1033 //--------------------------------------------------------------------------
1034 /**
1035  *  @brief  wayland change surface name callback
1036  *
1037  *  @param [in] data            user data(unused)
1038  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1039  *  @param [in] surfaceid       ico_window_mgr surface Id
1040  *  @param [in] winname         surface window name(title)
1041  */
1042 //--------------------------------------------------------------------------
1043 void
1044 CicoSCWindowController::nameCB(void                  *data,
1045                                struct ico_window_mgr *ico_window_mgr,
1046                                uint32_t              surfaceid,
1047                                const char            *winname)
1048 {
1049     ICO_DBG("CicoSCWindowController::nameCB Enter"
1050             "(surfaceid=%08X winname=%s)", surfaceid, winname);
1051
1052     CicoSCWindow *window = findWindow(surfaceid);
1053     if (NULL == window) {
1054         ICO_DBG("CicoSCWindowController::nameCB Leave");
1055         return;
1056     }
1057
1058     ICO_DBG("nameCB: Update window name %s=>%s",
1059             window->name.c_str(), winname);
1060     window->name = winname;
1061
1062     ICO_DBG("CicoSCWindowController::nameCB Leave");
1063 }
1064
1065 //--------------------------------------------------------------------------
1066 /**
1067  *  @brief  wayland surface destroy callback
1068  *
1069  *  @param [in] data            user data(unused)
1070  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1071  *  @param [in] surfaceid       ico_window_mgr surface Id
1072  */
1073 //--------------------------------------------------------------------------
1074 void
1075 CicoSCWindowController::destroyedCB(void                  *data,
1076                                     struct ico_window_mgr *ico_window_mgr,
1077                                     uint32_t              surfaceid)
1078 {
1079     ICO_DBG("CicoSCWindowController::destroyedCB Enter");
1080
1081     CicoSCWindow *window = findWindow(surfaceid);
1082     if (NULL == window) {
1083         ICO_DBG("CicoSCWindowController::destroyedCB Leave");
1084         return;
1085     }
1086
1087     // send message
1088     CicoSCMessage *message = new CicoSCMessage();
1089     message->addRootObject("command", MSG_CMD_DESTROY);
1090     message->addRootObject("appid", window->appid);
1091     message->addArgObject("surface", window->surfaceid);
1092     message->addArgObject("winname", window->name);
1093     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1094
1095     // TODO delete window in application
1096
1097     // delete window in list
1098     m_windowList.erase(window->surfaceid);
1099     delete(window);
1100  
1101     ICO_DBG("CicoSCWindowController::destroyedCB Leave");
1102 }
1103
1104 //--------------------------------------------------------------------------
1105 /**
1106  *  @brief  wayland surface visible callback
1107  *
1108  *  @param [in] data            user data(unused)
1109  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1110  *  @param [in] surfaceid       ico_window_mgr surface Id
1111  *  @param [in] visible         surface visible
1112  *                              (1=visible/0=unvisible/other=nochange)
1113  *  @param [in] raise           surface raise
1114  *                              (1=raise/0=lower/other=nochange)
1115  *  @param [in] hint            client request
1116  *                              (1=client request(not changed)/0=changed)
1117  */
1118 //--------------------------------------------------------------------------
1119 void
1120 CicoSCWindowController::visibleCB(void                  *data,
1121                                   struct ico_window_mgr *ico_window_mgr,
1122                                   uint32_t              surfaceid,
1123                                   int32_t               visible,
1124                                   int32_t               raise,
1125                                   int32_t               hint)
1126 {
1127     ICO_DBG("CicoSCWindowController::visibleCB Enter"
1128             "(surfaceid=%08X visible=%d raise=%d hint=%d)",
1129             surfaceid, visible, raise, hint);
1130
1131     CicoSCWindow *window = findWindow(surfaceid);
1132     if (NULL == window) {
1133         ICO_DBG("CicoSCWindowController::visibleCB Leave");
1134         return;
1135     }
1136
1137     int newVisible = visible;
1138     int newRaise   = raise;
1139
1140     if (visible == ICO_WINDOW_MGR_V_NOCHANGE) {
1141         newVisible = window->visible;
1142     }
1143
1144     if (raise == ICO_WINDOW_MGR_V_NOCHANGE) {
1145         newVisible = window->raise;
1146     }
1147
1148     if ((window->visible == newVisible) && (window->raise == newRaise) ){
1149         ICO_DBG("CicoSCWindowController::visibleCB Leave");
1150         return;
1151     }
1152
1153     // notify homescreen
1154     CicoSCMessage *message = new CicoSCMessage();
1155     message->addRootObject("command", MSG_CMD_CHANGE_ATTR);
1156     message->addRootObject("appid", window->appid);
1157     message->addArgObject("surface", window->surfaceid);
1158     message->addArgObject("winname", window->name);
1159     message->addArgObject("node", window->nodeid);
1160     message->addArgObject("layer", window->layerid);
1161     message->addArgObject("pos_x", window->x);
1162     message->addArgObject("pos_y", window->y);
1163     message->addArgObject("width", window->width);
1164     message->addArgObject("height", window->height);
1165     message->addArgObject("raise", window->raise ? 1 : 0);
1166     message->addArgObject("visible", window->visible ? 1 : 0);
1167     message->addArgObject("active", window->active ? 1 : 0);
1168     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1169
1170     ICO_DBG("CicoSCWindowController::visibleCB Leave");
1171 }
1172
1173 //--------------------------------------------------------------------------
1174 /**
1175  *  @brief  wayland surface configure callback
1176  *
1177  *  @param [in] data            user data(unused)
1178  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1179  *  @param [in] surfaceid       ico_window_mgr surface Id
1180  *  @param [in] node            surface node Id
1181  *  @param [in] x               surface upper-left X coodinate
1182  *  @param [in] y               surface upper-left Y coodinate
1183  *  @param [in] width           surface width
1184  *  @param [in] height          surface height
1185  *  @param [in] hint            client request
1186  *                              (1=client request(not changed)/0=changed)
1187  */
1188 //--------------------------------------------------------------------------
1189 void
1190 CicoSCWindowController::configureCB(void                  *data,
1191                                     struct ico_window_mgr *ico_window_mgr,
1192                                     uint32_t              surfaceid,
1193                                     uint32_t              node,
1194                                     uint32_t              layer,
1195                                     int32_t               x,
1196                                     int32_t               y,
1197                                     int32_t               width,
1198                                     int32_t               height,
1199                                     int32_t               hint)
1200 {
1201     ICO_DBG("CicoSCWindowController::configureCB Enter"
1202             "surfaceid=%08X node=%d layer=%d x=%d y=%d "
1203             "width=%d height=%d hint=%d",
1204             surfaceid, node, layer, x, y, width, height, hint);
1205
1206     CicoSCWindow *window = findWindow(surfaceid);
1207     if (NULL == window) {
1208         ICO_DBG("CicoSCWindowController::visibleCB Leave"
1209                 "(update window visible failed)");
1210         return;
1211     }
1212
1213     if (ICO_WINDOW_MGR_HINT_CHANGE == hint) {
1214         window->x      = x;
1215         window->y      = y;
1216         window->width  = width;
1217         window->height = height;
1218 #if 0
1219         if (window->layerid != layer) {
1220             window->layerid = layer;
1221             layer = findLayer(window->displayid, layer);
1222         }
1223 #endif
1224     }
1225
1226     // send message
1227     CicoSCMessage *message = new CicoSCMessage();
1228     message->addRootObject("command", MSG_CMD_CHANGE_ATTR);
1229     message->addRootObject("appid", window->appid);
1230     message->addArgObject("surface", window->surfaceid);
1231     message->addArgObject("winname", window->name);
1232     message->addArgObject("node", window->nodeid);
1233     message->addArgObject("layer", window->layerid);
1234     message->addArgObject("pos_x", window->x);
1235     message->addArgObject("pos_y", window->y);
1236     message->addArgObject("width", window->width);
1237     message->addArgObject("height", window->height);
1238     message->addArgObject("raise", window->raise ? 1 : 0);
1239     message->addArgObject("visible", window->visible ? 1 : 0);
1240     message->addArgObject("active", window->active ? 1 : 0);
1241     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1242
1243     ICO_DBG("CicoSCWindowController::configureCB Leave");
1244 }
1245
1246 //--------------------------------------------------------------------------
1247 /**
1248  *  @brief  wayland surface active callback
1249  *
1250  *  @param [in] data            user data(unused)
1251  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1252  *  @param [in] surfaceid       ico_window_mgr surface Id
1253  *  @param [in] active          surface active
1254  *                              (1=active/0=not active)
1255  */
1256 //--------------------------------------------------------------------------
1257 void
1258 CicoSCWindowController::activeCB(void                  *data,
1259                                  struct ico_window_mgr *ico_window_mgr,
1260                                  uint32_t              surfaceid,
1261                                  int32_t               active)
1262 {
1263     ICO_DBG("CicoSCWindowController::activeCB Enter"
1264             "(surfaceid=%08X active=%d)", surfaceid, active);
1265
1266     CicoSCWindow *window = findWindow(surfaceid);
1267     if (NULL == window) {
1268         ICO_DBG("CicoSCWindowController::activeCB Leave");
1269         return;
1270     }
1271
1272     // send message
1273     CicoSCMessage *message = new CicoSCMessage();
1274     message->addRootObject("command", MSG_CMD_CHANGE_ACTIVE);
1275     message->addRootObject("appid", window->appid);
1276     message->addArgObject("surface", window->surfaceid);
1277     message->addArgObject("winname", window->name);
1278     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1279
1280     ICO_DBG("CicoSCWindowController::activeCB Leave");
1281 }
1282
1283 //--------------------------------------------------------------------------
1284 /**
1285  *  @brief  wayland layer visible callback
1286  *
1287  *  @param [in] data            user data(unused)
1288  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1289  *  @param [in] layer           layer Id
1290  *  @param [in] visible         layer visible
1291  *                              (1=visible/0=unvisible/other=nochange)
1292  */
1293 //--------------------------------------------------------------------------
1294 void
1295 CicoSCWindowController::layerVisibleCB(void                  *data,
1296                                        struct ico_window_mgr *ico_window_mgr,
1297                                        uint32_t              layer,
1298                                        int32_t               visible)
1299 {
1300     ICO_DBG("CicoSCWindowController::layerVisibleCB Enter"
1301             "layer=%d visible=%d)", layer, visible);
1302
1303     // send message
1304     CicoSCMessage *message = new CicoSCMessage();
1305     message->addRootObject("command", MSG_CMD_CHANGE_LAYER_ATTR);
1306     message->addRootObject("appid", "");
1307     message->addArgObject("layer", layer);
1308     message->addArgObject("visible", visible);
1309     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1310
1311     ICO_DBG("CicoSCWindowController::layerVisibleCB Leave");
1312 }
1313
1314 //--------------------------------------------------------------------------
1315 /**
1316  *  @brief  query applicationsurface callback
1317  *
1318  *  @param [in] data            user data(unused)
1319  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1320  *  @param [in] appid           application Id
1321  *  @param [in] suface          surface Id array
1322  */
1323 //--------------------------------------------------------------------------
1324 void
1325 CicoSCWindowController::appSurfacesCB(void                  *data,
1326                                       struct ico_window_mgr *ico_window_mgr,
1327                                       const char            *appid,
1328                                       struct wl_array       *surfaces)
1329 {
1330     ICO_DBG("CicoSCWindowController::appSurfacesCB Enter(appid=%s)", appid);
1331
1332     //struct wl_array {
1333     //  size_t size;
1334     //  size_t alloc;
1335     //  void *data;
1336     //};
1337     uint32_t **p;
1338     for (p = (uint32_t**)(surfaces)->data;
1339          (const char*) p < ((const char*) (surfaces)->data + (surfaces)->size);
1340          (p)++) {
1341         ICO_DBG("appSurfacesCB: surface=%d", (int)*p);
1342     }
1343
1344     ICO_DBG("CicoSCWindowController::appSurfacesCB Leave");
1345 }
1346
1347 //--------------------------------------------------------------------------
1348 /**
1349  *  @brief   surface map event callback
1350  *
1351  *  @param [in] data            user data(unused)
1352  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1353  *  @param [in] event           event
1354  *  @param [in] surfaceid       surface Id
1355  *  @param [in] width           surface width
1356  *  @param [in] height          surface height
1357  *  @param [in] stride          surface buffer(frame buffer) stride
1358  *  @param [in] format          surface buffer format
1359  */
1360 //--------------------------------------------------------------------------
1361 void
1362 CicoSCWindowController::mapSurfaceCB(void                  *data,
1363                                      struct ico_window_mgr *ico_window_mgr,
1364                                      int32_t               event,
1365                                      uint32_t              surfaceid,
1366                                      int32_t               width,
1367                                      int32_t               height,
1368                                      int32_t               stride,
1369                                      int32_t               format)
1370 {
1371     ICO_DBG("CicoSCWindowController::mapSurfaceCB Enter"
1372             "(event=%d surface=%d width=%d height=%d stride=%d format=%d)",
1373             event, surfaceid, width, height, stride, format);
1374
1375     CicoSCWindow *window = findWindow(surfaceid);
1376     if (NULL == window) {
1377         return;
1378     }
1379
1380     // send message
1381     CicoSCMessage *message = new CicoSCMessage();
1382     message->addRootObject("command", MSG_CMD_MAP_THUMB);
1383     message->addRootObject("appid", window->appid);
1384     message->addArgObject("surface", window->surfaceid);
1385     message->addArgObject("width", width);
1386     message->addArgObject("height", height);
1387     message->addArgObject("stride", stride);
1388     message->addArgObject("format", format);
1389     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1390
1391     ICO_DBG("CicoSCWindowController::mapSurfaceCB Leave");
1392 }
1393
1394 //--------------------------------------------------------------------------
1395 /**
1396  *  @brief   wayland display attribute callback
1397  *
1398  *  @param [in] data            user data(unused)
1399  *  @param [in] wl_output       wayland wl_output interface
1400  *  @param [in] x               display upper-left X coodinate
1401  *  @param [in] y               display upper-left Y coodinate
1402  *  @param [in] physical_width  display physical width
1403  *  @param [in] physical_height display physical height
1404  *  @param [in] subpixel        display sub pixcel
1405  *  @param [in] make            display maker
1406  *  @param [in] model           diaplay model
1407  *  @param [in] transform       transform
1408  */
1409 //--------------------------------------------------------------------------
1410 void
1411 CicoSCWindowController::outputGeometryCB(void             *data,
1412                                          struct wl_output *wl_output,
1413                                          int32_t          x,
1414                                          int32_t          y,
1415                                          int32_t          physical_width,
1416                                          int32_t          physical_height,
1417                                          int32_t          subpixel,
1418                                          const char       *make,
1419                                          const char       *model,
1420                                          int32_t          transform)
1421 {
1422     ICO_DBG("CicoSCWlWinMgrIF::outputGeometryCB Enter"
1423             "(x=%d y=%d physical_width=%d physical_height=%d "
1424             "subpixel=%d make=%s model=%s transform=%d)",
1425             x, y, physical_width, physical_height,
1426             subpixel, make, model, transform);
1427
1428     if (0 == m_displayList.size()) {
1429         ICO_DBG("CicoSCWlWinMgrIF::outputGeometryCB Leave(display is zero");
1430         return;
1431     }
1432
1433     CicoSCDisplay* display = m_displayList.at(0);
1434     switch (transform) {
1435     case WL_OUTPUT_TRANSFORM_90:
1436     case WL_OUTPUT_TRANSFORM_270:
1437     case WL_OUTPUT_TRANSFORM_FLIPPED_90:
1438     case WL_OUTPUT_TRANSFORM_FLIPPED_270:
1439         display->pWidth      = physical_height;
1440         display->pHeight     = physical_width;
1441         display->orientation = CicoSCDisplay::ORIENTATION_VERTICAL;
1442         break;
1443     case WL_OUTPUT_TRANSFORM_NORMAL:
1444     case WL_OUTPUT_TRANSFORM_180:
1445     case WL_OUTPUT_TRANSFORM_FLIPPED:
1446     case WL_OUTPUT_TRANSFORM_FLIPPED_180:
1447     default:
1448         display->pWidth      = physical_width;
1449         display->pHeight     = physical_height;
1450         display->orientation = CicoSCDisplay::ORIENTATION_HORIZONTAL;
1451         break;
1452     }
1453     display->dump();
1454
1455     ICO_DBG("CicoSCWlWinMgrIF::outputGeometryCB Leave");
1456 }
1457
1458 //--------------------------------------------------------------------------
1459 /**
1460  *  @brief  wayland display mode callback
1461  *
1462  *  @param [in] data        user data(unused)
1463  *  @param [in] wl_output   wayland wl_output interface
1464  *  @param [in] flags       flags
1465  *  @param [in] width       display width
1466  *  @param [in] height      display height
1467  *  @param [in] refresh     display refresh rate
1468  */
1469 //--------------------------------------------------------------------------
1470 void
1471 CicoSCWindowController::outputModeCB(void             *data,
1472                                      struct wl_output *wl_output,
1473                                      uint32_t         flags,
1474                                      int32_t          width,
1475                                      int32_t          height,
1476                                      int32_t          refresh)
1477 {
1478     ICO_DBG("CicoSCWlWinMgrIF::outputModeCB Enter"
1479             "(flags=%d width=%d height=%d refresh=%d)",
1480             flags, width, height, refresh);
1481
1482     if (0 == m_displayList.size()) {
1483         ICO_DBG("CicoSCWlWinMgrIF::outputModeCB Leave(display is zero");
1484         return;
1485     }
1486
1487     CicoSCDisplay* display = m_displayList.at(0);
1488     if (flags & WL_OUTPUT_MODE_CURRENT) {
1489         if (display->orientation == CicoSCDisplay::ORIENTATION_VERTICAL) {
1490             display->pWidth  = height;
1491             display->pHeight = width;
1492         }
1493         else {
1494             display->pWidth  = width;
1495             display->pHeight = height;
1496         }
1497         display->dump();
1498     }
1499
1500     ICO_DBG("CicoSCWlWinMgrIF::outputModeCB Leave");
1501 }
1502
1503 //==========================================================================
1504 // private method
1505 //==========================================================================
1506
1507 //--------------------------------------------------------------------------
1508 /**
1509  *  @brief  find window object by surfaceid
1510  *
1511  *  @param [in] surfaceid   wayland surface id
1512  */
1513 //--------------------------------------------------------------------------
1514 CicoSCWindow*
1515 CicoSCWindowController::findWindow(int surfaceid)
1516 {
1517     map<unsigned int, CicoSCWindow*>::iterator itr;
1518     itr = m_windowList.find(surfaceid);
1519     if (m_windowList.end() == itr) {
1520         ICO_WRN("not found window object. surfaceid=%d", surfaceid);
1521         return NULL;
1522     }
1523
1524     return itr->second;
1525 }
1526
1527 //--------------------------------------------------------------------------
1528 /**
1529  *  @brief  find window object by surfaceid
1530  *
1531  *  @param [in] surfaceid   wayland surface id
1532  */
1533 //--------------------------------------------------------------------------
1534 CicoSCLayer*
1535 CicoSCWindowController::findLayer(int displayid, int layerid)
1536 {
1537     CicoSCDisplay* display = NULL;
1538     CicoSCLayer* layer = NULL;
1539     try {
1540         display = m_displayList.at(displayid);
1541         layer = display->layerList.at(layerid);
1542     }
1543     catch (const std::exception& e) {
1544         ICO_ERR("catch exception %s", e.what());
1545         return NULL;
1546     }
1547     catch (...) {
1548         ICO_ERR("catch exception unknown");
1549         return NULL;
1550     }
1551     return layer;
1552 }
1553
1554 //--------------------------------------------------------------------------
1555 /**
1556  *  @brief  handle command
1557  *
1558  *  @param [in] commnad     control commnad
1559  */
1560 //--------------------------------------------------------------------------
1561 void
1562 CicoSCWindowController::handleCommand(const CicoSCCommand * cmd)
1563 {
1564     ICO_DBG("CicoSCWindowController::handleCommand Enter(%d)", cmd->cmdid);
1565
1566     CicoSCCmdWinCtrlOpt *opt = static_cast<CicoSCCmdWinCtrlOpt*>(cmd->opt);
1567
1568     int ret = 0;
1569     switch (cmd->cmdid) {
1570     case MSG_CMD_SHOW:
1571         ICO_DBG("command: MSG_CMD_SHOW");
1572         ret = show(opt->surfaceid, opt->animation.c_str(), opt->animationTime);
1573         break;
1574     case MSG_CMD_HIDE:
1575         ICO_DBG("command: MSG_CMD_HIDE");
1576         ret = hide(opt->surfaceid, opt->animation.c_str(), opt->animationTime);
1577         break;
1578     case MSG_CMD_MOVE:
1579         ICO_DBG("command: MSG_CMD_MOVE");
1580         ret = setGeometry(opt->surfaceid, opt->nodeid, opt->x, opt->y, 
1581                           opt->width, opt->height, 
1582                           opt->animation.c_str(), opt->animationTime,
1583                           opt->animation.c_str(), opt->animationTime);
1584         break;
1585     case MSG_CMD_CHANGE_ACTIVE:
1586         ICO_DBG("command: MSG_CMD_CHANGE_ACTIVE");
1587         ret = active(opt->surfaceid, opt->active);
1588         break;
1589     case MSG_CMD_CHANGE_LAYER:
1590         ICO_DBG("command: MSG_CMD_CHANGE_LAYER");
1591         ret = setWindowLayer(opt->surfaceid, opt->layerid);
1592         break;
1593     case MSG_CMD_PREPARE_THUMB:
1594         ICO_DBG("command: MSG_CMD_PREPARE_THUMB");
1595         ret = mapSurface(opt->surfaceid, opt->framerate);
1596         break;
1597     case MSG_CMD_UNMAP_THUMB:
1598         ICO_DBG("command: MSG_CMD_UNMAP_THUMB");
1599         ret = unmapSurface(opt->surfaceid);
1600         break;
1601     case MSG_CMD_SHOW_LAYER:
1602         ICO_DBG("command: MSG_CMD_SHOW_LAYER");
1603         ret = showLayer(opt->displayid, opt->layerid);
1604         break;
1605     case MSG_CMD_HIDE_LAYER:
1606         ICO_DBG("command: MSG_CMD_HIDE_LAYER");
1607         ret = hideLayer(opt->displayid, opt->layerid);
1608         break;
1609     default:
1610         ICO_WRN("Unknown Commnad(0x%08X)", cmd->cmdid);
1611         break;
1612     }
1613     ICO_DBG("commnd result(%d)", ret);
1614
1615     ICO_DBG("CicoSCWindowController::handleCommand Leave");
1616 }
1617 // vim:set expandtab ts=4 sw=4: