aa2a46af1eaf6ab9ffc3b087cb241e84c69e8069
[profile/ivi/ico-uxf-homescreen.git] / ico-app-framework / ico_uxf_init.c
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  * @brief   user experiance library(initialize/terminate/event)
11  *
12  * @date    Feb-28-2013
13  */
14
15 #include    <stdio.h>
16 #include    <stdlib.h>
17 #include    <unistd.h>
18 #include    <string.h>
19 #include    <errno.h>
20 #include    <pthread.h>
21 #include    <sys/ioctl.h>
22 #include    <sys/time.h>
23 #include    <fcntl.h>
24
25 #include    "wayland-client.h"
26 #include    "ico_window_mgr-client-protocol.h"
27 #include    "ico_uxf.h"
28 #include    "ico_uxf_conf.h"
29 #include    "ico_uxf_private.h"
30
31 /* static functions             */
32 /* wayland standard callback functions      */
33 static void ico_uxf_wayland_globalcb(void *data, struct wl_registry *registry,
34                                      uint32_t name, const char *interface,
35                                      uint32_t version);
36 static void ico_uxf_output_geometrycb(void *data, struct wl_output *wl_output,
37                                       int32_t x, int32_t y, int32_t physical_width,
38                                       int32_t physical_height, int32_t subpixel,
39                                       const char *make, const char *model,
40                                       int32_t transform);
41 static void ico_uxf_output_modecb(void *data, struct wl_output *wl_output,
42                                   uint32_t flags, int32_t width, int32_t height,
43                                   int32_t refresh);
44
45 /* ico_window_mgr(Multi Window Manager) callback functions  */
46 struct ico_window;
47 static void ico_uxf_window_createdcb(void *data, struct ico_window_mgr *ico_window_mgr,
48                                      uint32_t surfaceid, int32_t pid, const char *appid);
49 static void ico_uxf_window_destroyedcb(void *data, struct ico_window_mgr *ico_window_mgr,
50                                        uint32_t surfaceid);
51 static void ico_uxf_window_visiblecb(void *data, struct ico_window_mgr *ico_window_mgr,
52                                      uint32_t surfaceid, int32_t visible, int32_t raise,
53                                      int32_t hint);
54 static void ico_uxf_window_configurecb(void *data, struct ico_window_mgr *ico_window_mgr,
55                                        uint32_t surfaceid, const char *appid,
56                                        int32_t layer, int32_t x, int32_t y,
57                                        int32_t width, int32_t height, int32_t hint);
58 static void ico_uxf_window_activecb(void *data,
59                                     struct ico_window_mgr *ico_window_mgr,
60                                     uint32_t surfaceid,
61                                     uint32_t active);
62
63 /* ico_input_mgr(Multi Input Manager) callback functions    */
64 static void ico_uxf_input_capabilitiescb(void *data, struct ico_exinput *ico_exinput,
65                                          const char *device, int32_t type,
66                                          const char *swname, int32_t input,
67                                          const char *codename, int32_t code);
68 static void ico_uxf_input_codecb(void *data, struct ico_exinput *ico_exinput,
69                                  const char *device, int32_t input, const char *codename,
70                                  int32_t code);
71 static void ico_uxf_input_inputcb(void *data, struct ico_exinput *ico_exinput,
72                                   uint32_t time, const char *device, int32_t input,
73                                   int32_t code, int32_t state);
74
75 /* AppCore(AUL) callback function   */
76 static int ico_uxf_aul_aulcb(int pid, void *data);
77
78 /* Variables & Tables               */
79 Ico_Uxf_Api_Mng         gIco_Uxf_Api_Mng = { 0 };
80
81 static pthread_mutex_t  sMutex;
82
83 /* Wayland Registry Listener */
84 static const struct wl_registry_listener ico_uxf_registry_listener = {
85     ico_uxf_wayland_globalcb
86 };
87
88 /* Window Manger Interface */
89 static const struct ico_window_mgr_listener     windowlistener = {
90     ico_uxf_window_createdcb,
91     ico_uxf_window_destroyedcb,
92     ico_uxf_window_visiblecb,
93     ico_uxf_window_configurecb,
94     ico_uxf_window_activecb
95 };
96
97 /* Input Manger Interface */
98 static const struct ico_exinput_listener      exinputlistener = {
99     ico_uxf_input_capabilitiescb,
100     ico_uxf_input_codecb,
101     ico_uxf_input_inputcb
102 };
103
104 /* Wayland Output interface */
105 static const struct wl_output_listener outputlistener = {
106     ico_uxf_output_geometrycb,
107     ico_uxf_output_modecb
108 };
109
110
111 /*--------------------------------------------------------------------------*/
112 /**
113  * @brief   ico_uxf_init: initialize user interface library hor HomeScreen
114  *
115  * @param[in]   name            application id
116  * @return      result
117  * @retval      ICO_UXF_EOK     success
118  * @retval      ICO_UXF_EBUSY   error(cullentry terminating)
119  * @retval      ICO_UXF_ESRCH   error(configuration error)
120  * @retval      ICO_UXF_ENOSYS  error(system error)
121  */
122 /*--------------------------------------------------------------------------*/
123 ICO_APF_API int
124 ico_uxf_init(const char *name)
125 {
126     Ico_Uxf_Mng_Display *dsp;
127     Ico_Uxf_Mng_Layer   *lay;
128     Ico_Uxf_Mng_Process *prc;
129     pthread_mutexattr_t sMutexAttr;
130     Ico_Uxf_Sys_Config *sysconf;
131     Ico_Uxf_App_Config *appconf;
132     Ico_Uxf_conf_appdisplay *appdsp;
133     Ico_Uxf_Mng_Callback    *freecb;
134     Ico_Uxf_Mng_EventQue    *freeeq;
135     int         dn, tn;
136     int         ret;
137
138     ico_uxf_log_open(name);
139
140     if (gIco_Uxf_Api_Mng.Initialized)  {
141         if (gIco_Uxf_Api_Mng.Initialized < 0)  {
142             uifw_trace("ico_uxf_init: Enter");
143             uifw_warn("ico_uxf_init: Leave(EBUSY)");
144             return ICO_UXF_EBUSY;
145         }
146         uifw_trace("ico_uxf_init: Enter");
147         uifw_trace("ico_uxf_init: Leave(EOK)");
148         return ICO_UXF_EOK;
149     }
150     uifw_trace("ico_uxf_init: Enter");
151
152     gIco_Uxf_Api_Mng.Initialized = -1;
153     memset(gIco_Uxf_Api_Mng.MyProcess, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
154     strncpy(gIco_Uxf_Api_Mng.MyProcess, name, ICO_UXF_MAX_PROCESS_NAME);
155     gIco_Uxf_Api_Mng.EventMask = 0;
156     gIco_Uxf_Api_Mng.WaylandFd = -1;
157     gIco_Uxf_Api_Mng.Wayland_Display = NULL;
158     gIco_Uxf_Api_Mng.InitTimer = ICO_UXF_SUSP_INITTIME;
159     gIco_Uxf_Api_Mng.Win_Show_Anima = 1;
160     gIco_Uxf_Api_Mng.Win_Hide_Anima = 1;
161
162     /* read configurations */
163     sysconf = (Ico_Uxf_Sys_Config *)ico_uxf_getSysConfig();
164     appconf = (Ico_Uxf_App_Config *)ico_uxf_getAppConfig();
165     if ((sysconf == NULL) || (appconf == NULL)) {
166         uifw_error("ico_uxf_init: Leave(ESRCH), Configuration Read Error");
167         return ICO_UXF_ESRCH;
168     }
169
170     uifw_trace("ico_uxf_init: set display configurations");
171     /* set display configurations */
172     for (dn = 0; dn < sysconf->displayNum; dn++) {
173         dsp = ico_uxf_mng_display(sysconf->display[dn].id, 1);
174         dsp->attr.type = sysconf->display[dn].type;
175         dsp->attr.num_layers = sysconf->display[dn].layerNum;
176         dsp->attr.hostId = sysconf->display[dn].hostId;
177         dsp->attr.displayNo = sysconf->display[dn].displayno;
178         dsp->attr.w = sysconf->display[dn].width;
179         dsp->attr.h = sysconf->display[dn].height;
180         dsp->attr.pWidth = -1;
181         dsp->attr.pHeight = -1;
182         dsp->attr.orientation = ICO_UXF_ORIENTATION_HORIZONTAL;
183         dsp->attr.inch = sysconf->display[dn].inch;
184         strncpy(dsp->attr.name, sysconf->display[dn].name, ICO_UXF_MAX_WIN_NAME);
185         dsp->attr.name[ICO_UXF_MAX_WIN_NAME] = 0;
186
187         for (tn = 0; tn < sysconf->display[dn].layerNum; tn++) {
188             lay = ico_uxf_mng_layer(sysconf->display[dn].id,
189                                     sysconf->display[dn].layer[tn].id, 1);
190             lay->attr.display = sysconf->display[dn].id;
191             lay->attr.w = sysconf->display[dn].width;
192             lay->attr.h = sysconf->display[dn].height;
193             lay->attr.menuoverlap = sysconf->display[dn].layer[tn].menuoverlap;
194             lay->mng_display = dsp;
195         }
196     }
197
198     uifw_trace("ico_uxf_init: set application configurations(num=%d)",
199                appconf->applicationNum);
200     /* set application configurations */
201     for(dn = 0; dn < appconf->applicationNum; dn++)  {
202         prc = ico_uxf_mng_process(appconf->application[dn].appid, 1);
203         prc->attr.internalid = 0;
204         prc->appconf = (void *)&appconf->application[dn];
205         prc->attr.status = ICO_UXF_PROCSTATUS_STOP;
206         prc->attr.type = appconf->application[dn].categoryId;
207         prc->attr.hostId = appconf->application[dn].hostId;
208         prc->attr.myHost = (prc->attr.hostId == sysconf->misc.myhostId) ? 1 : 0;
209         prc->attr.noicon = appconf->application[dn].noicon;
210         prc->attr.autostart = appconf->application[dn].autostart;
211         prc->attr.invisiblecpu = appconf->application[dn].invisiblecpu;
212
213         appdsp = &appconf->application[dn].display[0];
214         prc->attr.mainwin.window = 0;
215         prc->attr.mainwin.windowtype = appconf->application[dn].categoryId;
216         prc->attr.mainwin.display = appdsp->displayId;
217         prc->attr.mainwin.layer = appdsp->layerId;
218         prc->attr.mainwin.x =
219                 sysconf->display[appdsp->displayId].zone[appdsp->zoneId].x;
220         prc->attr.mainwin.y =
221                 sysconf->display[appdsp->displayId].zone[appdsp->zoneId].y;
222         prc->attr.mainwin.w =
223                 sysconf->display[appdsp->displayId].zone[appdsp->zoneId].width;
224         prc->attr.mainwin.h =
225                 sysconf->display[appdsp->displayId].zone[appdsp->zoneId].height;
226         prc->attr.mainwin.name[ICO_UXF_MAX_WIN_NAME] = 0;
227         prc->attr.numwindows = appconf->application[dn].displayzoneNum;
228         /* get sub windows                          */
229         if (prc->attr.numwindows > 1)   {
230             prc->attr.subwin = malloc(sizeof(Ico_Uxf_ProcessWin) *
231                                       (prc->attr.numwindows - 1));
232             if (! prc->attr.subwin) {
233                 uifw_error("ico_uxf_init: No Memory");
234                 appconf->application[dn].displayzoneNum = 1;
235                 prc->attr.numwindows = 1;
236             }
237             else    {
238                 memset(prc->attr.subwin, 0, (prc->attr.numwindows - 1));
239                 for (tn = 0; tn < (prc->attr.numwindows - 1); tn++) {
240                     appdsp ++;
241                     prc->attr.subwin[tn].windowtype = prc->attr.mainwin.windowtype;
242                     prc->attr.subwin[tn].display = appdsp->displayId;
243                     prc->attr.subwin[tn].layer = appdsp->layerId;
244                     prc->attr.subwin[tn].x =
245                         sysconf->display[appdsp->displayId].zone[appdsp->zoneId].x;
246                     prc->attr.subwin[tn].y =
247                         sysconf->display[appdsp->displayId].zone[appdsp->zoneId].y;
248                     prc->attr.subwin[tn].w =
249                         sysconf->display[appdsp->displayId].zone[appdsp->zoneId].width;
250                     prc->attr.subwin[tn].h =
251                         sysconf->display[appdsp->displayId].zone[appdsp->zoneId].height;
252                 }
253             }
254         }
255     }
256
257     gIco_Uxf_Api_Mng.Mng_MyProcess
258         = ico_uxf_mng_process(gIco_Uxf_Api_Mng.MyProcess, 0);
259     if (!gIco_Uxf_Api_Mng.Mng_MyProcess) {
260         uifw_error("ico_uxf_init: Leave(ESRCH), Unknown Apprication(%s)",
261                    gIco_Uxf_Api_Mng.MyProcess);
262         return ICO_UXF_ESRCH;
263     }
264     gIco_Uxf_Api_Mng.Mng_MyProcess->attr.internalid = getpid();
265     gIco_Uxf_Api_Mng.Mng_MyProcess->attr.status = ICO_UXF_PROCSTATUS_RUN;
266
267     dsp = ico_uxf_mng_display(gIco_Uxf_Api_Mng.Mng_MyProcess->attr.mainwin.display, 0);
268
269     uifw_trace("ico_uxf_init: App.%d MainDisplay.%d %08x",
270                gIco_Uxf_Api_Mng.Mng_MyProcess->attr.process,
271                gIco_Uxf_Api_Mng.Mng_MyProcess->attr.mainwin.display, dsp);
272
273     for (ret = 0; ret < (5000/50); ret++)  {
274         gIco_Uxf_Api_Mng.Wayland_Display = wl_display_connect(NULL);
275         if (gIco_Uxf_Api_Mng.Wayland_Display)  break;
276         usleep(50*1000);
277     }
278
279     gIco_Uxf_Api_Mng.Wayland_Registry
280         = wl_display_get_registry(gIco_Uxf_Api_Mng.Wayland_Display);
281     wl_registry_add_listener(gIco_Uxf_Api_Mng.Wayland_Registry,
282                              &ico_uxf_registry_listener, (void *)0);
283
284     for (ret = 0; ret < (500/20); ret++) {
285         if ((gIco_Uxf_Api_Mng.Wayland_WindowMgr != NULL) &&
286             (gIco_Uxf_Api_Mng.Wayland_exInput != NULL) &&
287             (gIco_Uxf_Api_Mng.Wayland_InputMgr != NULL))    break;
288         uifw_trace("ico_uxf_init: call wl_display_dispatch(%08x)",
289                    (int)gIco_Uxf_Api_Mng.Wayland_Display);
290         wl_display_dispatch(gIco_Uxf_Api_Mng.Wayland_Display);
291         usleep(20*1000);
292     }
293     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
294     uifw_trace("ico_uxf_init: Wayland/Weston connect OK");
295
296     /* set client attribute if need     */
297     if (gIco_Uxf_Api_Mng.Wayland_WindowMgr) {
298         for(dn = 0; dn < appconf->applicationNum; dn++)  {
299             if (appconf->application[dn].noconfigure)   {
300                 uifw_trace("ico_uxf_init: %s no need configure event",
301                            appconf->application[dn].appid);
302                 ico_window_mgr_set_client_attr(gIco_Uxf_Api_Mng.Wayland_WindowMgr,
303                                                appconf->application[dn].appid,
304                                                ICO_WINDOW_MGR_CLIENT_ATTR_NOCONFIGURE, 1);
305                 wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
306             }
307         }
308     }
309
310     gIco_Uxf_Api_Mng.WaylandFd
311         = wl_display_get_fd(gIco_Uxf_Api_Mng.Wayland_Display);
312
313     /* initialize mutex */
314     (void) pthread_mutexattr_init(&sMutexAttr);
315     if (pthread_mutex_init(&sMutex, &sMutexAttr) != 0) {
316         uifw_error("ico_uxf_init: Leave(ENOSYS), Mutex Create Error %d", errno);
317         wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
318         gIco_Uxf_Api_Mng.Wayland_Display = NULL;
319         gIco_Uxf_Api_Mng.Initialized = 0;
320         return ICO_UXF_ENOSYS;
321     }
322
323     /* allocate free control blocks         */
324     freecb = ico_uxf_alloc_callback();
325     ico_uxf_free_callback(freecb);
326     freeeq = ico_uxf_alloc_eventque();
327     ico_uxf_free_eventque(freeeq);
328
329     /* flush wayland connection             */
330     ico_window_mgr_set_eventcb(gIco_Uxf_Api_Mng.Wayland_WindowMgr, 1);
331     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
332
333     /* application launch/dead callback from AppCore(aul)   */
334     aul_listen_app_launch_signal(ico_uxf_aul_aulcb, (void *)0);
335     aul_listen_app_dead_signal(ico_uxf_aul_aulcb, (void *)1);
336
337     gIco_Uxf_Api_Mng.Initialized = 1;
338
339     uifw_trace("ico_uxf_init: Leave(EOK)");
340     uifw_logflush();
341
342     return ICO_UXF_EOK;
343 }
344
345 /*--------------------------------------------------------------------------*/
346 /**
347  * @brief   ico_uxf_wl_display_fd: get wayland file discriptor
348  *
349  * @param       none
350  * @return      wayland connect socket file descriptor
351  * @retval      >=0         success(file descriptor)
352  * @retval      < 0         error(wayland not connect)
353  */
354 /*--------------------------------------------------------------------------*/
355 ICO_APF_API int
356 ico_uxf_wl_display_fd(void)
357 {
358     uifw_trace("ico_uxf_wl_display_fd: fd=%d", gIco_Uxf_Api_Mng.WaylandFd);
359
360     return gIco_Uxf_Api_Mng.WaylandFd;
361 }
362
363 /*--------------------------------------------------------------------------*/
364 /**
365  * @brief   ico_uxf_shutdown: terminate user interface library hor HomeScreen
366  *
367  * @param       none
368  * @return      result
369  * @retval      ICO_UXF_EOK     success
370  * @retval      ICO_UXF_EBUSY   error(cullentry terminating)
371  */
372 /*--------------------------------------------------------------------------*/
373 ICO_APF_API int
374 ico_uxf_shutdown(void)
375 {
376     uifw_trace("ico_uxf_shutdown: Enter");
377
378     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
379         if (gIco_Uxf_Api_Mng.Initialized < 0)  {
380             uifw_warn("ico_uxf_shutdown: Leave(EBUSY)");
381             return ICO_UXF_EBUSY;
382         }
383         uifw_trace("ico_uxf_shutdown: Leave(EOK)");
384         return ICO_UXF_EOK;
385     }
386     gIco_Uxf_Api_Mng.Initialized = -1;
387     gIco_Uxf_Api_Mng.LastEvent = 0;
388
389     (void) pthread_mutex_destroy(&sMutex);
390
391     if (gIco_Uxf_Api_Mng.Wayland_Seat) {
392         wl_seat_destroy(gIco_Uxf_Api_Mng.Wayland_Seat);
393         gIco_Uxf_Api_Mng.Wayland_Seat = NULL;
394     }
395     if (gIco_Uxf_Api_Mng.Wayland_exInput) {
396         ico_exinput_destroy(gIco_Uxf_Api_Mng.Wayland_exInput);
397         gIco_Uxf_Api_Mng.Wayland_exInput = NULL;
398     }
399     if (gIco_Uxf_Api_Mng.Wayland_InputMgr) {
400         ico_input_mgr_control_destroy(gIco_Uxf_Api_Mng.Wayland_InputMgr);
401         gIco_Uxf_Api_Mng.Wayland_InputMgr = NULL;
402     }
403     if (gIco_Uxf_Api_Mng.Wayland_Compositor)   {
404         wl_compositor_destroy(gIco_Uxf_Api_Mng.Wayland_Compositor);
405         gIco_Uxf_Api_Mng.Wayland_Compositor = NULL;
406     }
407     if (gIco_Uxf_Api_Mng.Wayland_Display)  {
408         wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
409         wl_display_disconnect(gIco_Uxf_Api_Mng.Wayland_Display);
410         gIco_Uxf_Api_Mng.Wayland_Display = NULL;
411     }
412
413     gIco_Uxf_Api_Mng.Initialized = 0;
414
415     uifw_trace("ico_uxf_shutdown: Leave(EOK)");
416     return ICO_UXF_EOK;
417 }
418
419 /*--------------------------------------------------------------------------*/
420 /**
421  * @brief   ico_uxf_main_loop_iterate: process user interface library events
422  *
423  * @param       none
424  * @return      none
425  */
426 /*--------------------------------------------------------------------------*/
427 ICO_APF_API void
428 ico_uxf_main_loop_iterate(void)
429 {
430     int                     arg;
431     Ico_Uxf_Mng_EventQue    *wkque;
432     Ico_Uxf_Mng_Callback    *callback;
433     Ico_Uxf_Event_Cb        func;
434
435     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
436
437     arg = 0;
438     if (ioctl(gIco_Uxf_Api_Mng.WaylandFd, FIONREAD, &arg) < 0)   {
439         uifw_warn("ico_uxf_main_loop_iterate: ioclt(FIONREAD,) Error %d", errno);
440         arg = 0;
441     }
442
443     if (arg > 0)   {
444         wl_display_dispatch(gIco_Uxf_Api_Mng.Wayland_Display);
445     }
446
447     ico_uxf_enter_critical();
448
449     /* notify event */
450     while (gIco_Uxf_Api_Mng.EventQue) {
451
452         wkque = gIco_Uxf_Api_Mng.EventQue;
453         gIco_Uxf_Api_Mng.EventQue = gIco_Uxf_Api_Mng.EventQue->next;
454
455         gIco_Uxf_Api_Mng.LastEvent = wkque->detail.event;
456         callback = gIco_Uxf_Api_Mng.Callback;
457         while (callback) {
458             if (callback->eventmask & gIco_Uxf_Api_Mng.LastEvent) {
459                 func = callback->func;
460                 arg = callback->arg;
461                 ico_uxf_leave_critical();
462
463                 uifw_trace("ico_uxf_main_loop: Call Event Callback(%08x,,%08x)",
464                            gIco_Uxf_Api_Mng.LastEvent, arg);
465                 (*func)(gIco_Uxf_Api_Mng.LastEvent, wkque->detail, arg);
466
467                 ico_uxf_enter_critical();
468             }
469             callback = callback->next;
470         }
471         ico_uxf_free_eventque(wkque);
472     }
473
474     ico_uxf_leave_critical();
475
476     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
477 }
478
479 /*--------------------------------------------------------------------------*/
480 /**
481  * @brief   ico_uxf_callback_set: set event calback function
482  *
483  * @param[in]   mask            event mask
484  * @param[in]   func            callback function
485  * @param[in]   arg             user argument
486  * @return      result
487  * @retval      ICO_UXF_EOK     success
488  * @retval      ICO_UXF_ESRCH   error(user interface library not initialized)
489  * @retval      ICO_UXF_EINVAL  error(illegal event mask)
490  * @retval      ICO_UXF_EBUSY   error(already set same event)
491  */
492 /*--------------------------------------------------------------------------*/
493 ICO_APF_API int
494 ico_uxf_callback_set(const unsigned int mask, Ico_Uxf_Event_Cb func, const int arg)
495 {
496     Ico_Uxf_Mng_Callback    *callback;
497     unsigned int            wkmask;
498
499     uifw_trace("ico_uxf_callback_set: Enter(%08x,%08x,%08x)", mask, (int)func, arg);
500
501     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
502         uifw_warn("ico_uxf_callback_set: Leave(ESRCH)");
503         return ICO_UXF_ESRCH;
504     }
505
506     if (mask)  {
507         wkmask = mask;
508     }
509     else    {
510         wkmask = ICO_UXF_EVENT_ALL;
511     }
512     if ((wkmask & ICO_UXF_EVENT_VALIDALL) == 0) {
513         uifw_warn("ico_uxf_callback_set: Leave(EINVAL)");
514         return ICO_UXF_EINVAL;
515     }
516
517     ico_uxf_enter_critical();
518
519     callback = gIco_Uxf_Api_Mng.Callback;
520     while (callback)   {
521         if ((callback->eventmask == wkmask) && (callback->func == func) &&
522             (callback->arg == arg))    {
523
524             ico_uxf_leave_critical();
525             uifw_warn("ico_uxf_callback_set: Leave(EBUSY)");
526             return ICO_UXF_EBUSY;
527         }
528     }
529
530     callback = ico_uxf_alloc_callback();
531
532     callback->eventmask = wkmask;
533     callback->func = func;
534     callback->arg = arg;
535
536     ico_uxf_regist_callback(callback);
537
538     gIco_Uxf_Api_Mng.EventMask |= wkmask;
539
540     ico_uxf_leave_critical();
541
542     uifw_trace("ico_uxf_callback_set: Leave(EOK)");
543     return ICO_UXF_EOK;
544 }
545
546 /*--------------------------------------------------------------------------*/
547 /**
548  * @brief   ico_uxf_callback_remove: remove event calback function
549  *
550  * @param[in]   mask            event mask
551  * @param[in]   func            callback function
552  * @param[in]   arg             user argument
553  * @return      result
554  * @retval      ICO_UXF_EOK     success
555  * @retval      ICO_UXF_ESRCH   error(user interface library not initialized)
556  */
557 /*--------------------------------------------------------------------------*/
558 ICO_APF_API int
559 ico_uxf_callback_remove(const unsigned int mask, Ico_Uxf_Event_Cb func, const int arg)
560 {
561     Ico_Uxf_Mng_Callback    *callback;
562     unsigned int            wkmask;
563
564     uifw_trace("ico_uxf_callback_remove: Enter(%08x,%08x,%08x)", mask, (int)func, arg);
565
566     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
567         uifw_warn("ico_uxf_callback_remove: Leave(ESRCH)");
568         return ICO_UXF_ESRCH;
569     }
570
571     if (mask)  {
572         wkmask = mask;
573     }
574     else    {
575         wkmask = ICO_UXF_EVENT_ALL;
576     }
577
578     ico_uxf_enter_critical();
579
580     gIco_Uxf_Api_Mng.EventMask = 0;
581
582     callback = gIco_Uxf_Api_Mng.Callback;
583
584     while (callback)   {
585         if ((callback->eventmask == wkmask) && (callback->func == func) &&
586             (callback->arg == arg))    {
587             ico_uxf_remove_callback(callback);
588         }
589         else    {
590             gIco_Uxf_Api_Mng.EventMask |= callback->eventmask;
591         }
592         callback = callback->next;
593     }
594
595     ico_uxf_leave_critical();
596
597     uifw_trace("ico_uxf_callback_remove: Leave(EOK)");
598     return ICO_UXF_EOK;
599 }
600
601 /*--------------------------------------------------------------------------*/
602 /**
603  * @brief   ico_uxf_free_procwin: free active window management table(internal function)
604  *
605  * @param[in]   prc             application management table address
606  * @return      none
607  */
608 /*--------------------------------------------------------------------------*/
609 void
610 ico_uxf_free_procwin(Ico_Uxf_Mng_Process *prc)
611 {
612     Ico_Uxf_Mng_Window  *p;
613     Ico_Uxf_Mng_Window  *pp;
614     Ico_Uxf_Mng_Window  *freep;
615     int                 hash;
616
617     uifw_trace("ico_uxf_free_procwin: Enter(%d)", prc->attr.process);
618
619     for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++)   {
620         p = gIco_Uxf_Api_Mng.Hash_WindowId[hash];
621         pp = (Ico_Uxf_Mng_Window *)0;
622         while (p)  {
623             if (p->attr.process == prc->attr.process)  {
624                 freep = p;
625                 p = p->nextidhash;
626                 if (! pp)  {
627                     gIco_Uxf_Api_Mng.Hash_WindowId[hash] = p;
628                 }
629                 else    {
630                     pp->nextidhash = p;
631                 }
632                 uifw_trace("ico_uxf_free_procwin: Free Window(%08x)", freep->attr.window);
633                 free(freep);
634             }
635             else    {
636                 pp = p;
637                 p = p->nextidhash;
638             }
639         }
640     }
641     uifw_trace("ico_uxf_free_procwin: Leave");
642 }
643
644 /*--------------------------------------------------------------------------*/
645 /**
646  * @brief   ico_uxf_wayland_globalcb: wayland global callback(static function)
647  *
648  * @param[in]   data            user data(unused)
649  * @param[in]   registry        wayland registry
650  * @param[in]   name            wayland display Id(unused)
651  * @param[in]   interface       wayland interface name
652  * @param[in]   version         wayland interface version number(unused)
653  * @return      none
654  */
655 /*--------------------------------------------------------------------------*/
656 static void
657 ico_uxf_wayland_globalcb(void *data, struct wl_registry *registry,
658                          uint32_t name, const char *interface, uint32_t version)
659 {
660     uifw_trace("ico_uxf_wayland_globalcb: Enter(Event=%s DispId=%08x)", interface, name);
661
662     if (strcmp(interface, "ico_window_mgr") == 0)    {
663         gIco_Uxf_Api_Mng.Wayland_WindowMgr = (struct ico_window_mgr *)
664                 wl_registry_bind(registry, name, &ico_window_mgr_interface, 1);
665         ico_window_mgr_add_listener(gIco_Uxf_Api_Mng.Wayland_WindowMgr,
666                                     &windowlistener, NULL);
667         ico_window_mgr_set_user(gIco_Uxf_Api_Mng.Wayland_WindowMgr,
668                                 getpid(), gIco_Uxf_Api_Mng.MyProcess);
669     }
670     else if (strcmp(interface, "ico_exinput") == 0) {
671         /* regist exinput */
672         gIco_Uxf_Api_Mng.Wayland_exInput = (struct ico_exinput *)
673                 wl_registry_bind(registry, name, &ico_exinput_interface, 1);
674         ico_exinput_add_listener(gIco_Uxf_Api_Mng.Wayland_exInput, &exinputlistener, NULL);
675     }
676     else if (strcmp(interface, "ico_input_mgr_control") == 0) {
677         /* regist Multi Input Manager interface */
678         gIco_Uxf_Api_Mng.Wayland_InputMgr = (struct ico_input_mgr_control *)
679                 wl_registry_bind(registry, name, &ico_input_mgr_control_interface, 1);
680     }
681     else if (strcmp(interface, "wl_output") == 0) {
682         /* regist wl_output listener to get display info */
683         gIco_Uxf_Api_Mng.Wayland_Output = (struct wl_output *)
684                 wl_registry_bind(registry, name, &wl_output_interface, 1);
685         wl_output_add_listener(gIco_Uxf_Api_Mng.Wayland_Output, &outputlistener, NULL);
686     }
687     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
688     uifw_trace("ico_uxf_wayland_globalcb: Leave");
689 }
690
691 /*--------------------------------------------------------------------------*/
692 /**
693  * @brief   ico_uxf_output_geometrycb: wayland display attribute callback(static function)
694  *
695  * @param[in]   data            user data(unused)
696  * @param[in]   wl_output       wayland wl_output interface
697  * @param[in]   x               display upper-left X coodinate
698  * @param[in]   y               display upper-left Y coodinate
699  * @param[in]   physical_width  display physical width
700  * @param[in]   physical_height display physical height
701  * @param[in]   subpixel        display sub pixcel
702  * @param[in]   make            display maker
703  * @param[in]   model           diaplay model
704  * @param[in]   transform       transform
705  * @return      none
706  */
707 /*--------------------------------------------------------------------------*/
708 static void
709 ico_uxf_output_geometrycb(void *data, struct wl_output *wl_output, int32_t x, int32_t y,
710                           int32_t physical_width, int32_t physical_height, int32_t subpixel,
711                           const char *make, const char *model, int32_t transform)
712 {
713     Ico_Uxf_Mng_Display *dsp;
714
715     uifw_trace("ico_uxf_output_geometrycb: Enter(x/y=%d/%d, pwidth/height=%d/%d, trans=%d)",
716                x, y, physical_width, physical_height, transform);
717
718     dsp = ico_uxf_mng_display(gIco_Uxf_Api_Mng.Mng_MyProcess->attr.mainwin.display, 0);
719
720     if (dsp) {
721         if ((transform == WL_OUTPUT_TRANSFORM_90)
722             || (transform == WL_OUTPUT_TRANSFORM_270)
723             || (transform == WL_OUTPUT_TRANSFORM_FLIPPED_90)
724             || (transform == WL_OUTPUT_TRANSFORM_FLIPPED_270))  {
725             dsp->attr.pWidth = physical_height;
726             dsp->attr.pHeight = physical_width;
727             dsp->attr.orientation = ICO_UXF_ORIENTATION_VERTICAL;
728         }
729         else {
730             dsp->attr.pWidth = physical_width;
731             dsp->attr.pHeight = physical_height;
732             dsp->attr.orientation = ICO_UXF_ORIENTATION_HORIZONTAL;
733         }
734     }
735     uifw_trace("ico_uxf_output_geometrycb: Leave");
736 }
737
738 /*--------------------------------------------------------------------------*/
739 /**
740  * @brief   ico_uxf_output_modecb: wayland display mode callback(static function)
741  *
742  * @param[in]   data            user data(unused)
743  * @param[in]   wl_output       wayland wl_output interface
744  * @param[in]   flags           flags
745  * @param[in]   width           display width
746  * @param[in]   height          display height
747  * @param[in]   refresh         display refresh rate
748  * @return      none
749  */
750 /*--------------------------------------------------------------------------*/
751 static void
752 ico_uxf_output_modecb(void *data, struct wl_output *wl_output, uint32_t flags,
753                       int32_t width, int32_t height, int32_t refresh)
754 {
755     Ico_Uxf_Mng_Display *dsp;
756
757     uifw_trace("ico_uxf_output_modecb: Enter(flg=%d, width=%d, height=%d, ref=%d)",
758                flags, width, height, refresh);
759
760     dsp = ico_uxf_mng_display(gIco_Uxf_Api_Mng.Mng_MyProcess->attr.mainwin.display, 0);
761
762     if (dsp && (flags & WL_OUTPUT_MODE_CURRENT)) {
763         if (dsp->attr.orientation == ICO_UXF_ORIENTATION_VERTICAL) {
764             dsp->attr.pWidth = height;
765             dsp->attr.pHeight = width;
766         }
767         else {
768             dsp->attr.pWidth = width;
769             dsp->attr.pHeight = height;
770         }
771     }
772     uifw_trace("ico_uxf_output_modecb: Leave");
773 }
774
775 /*--------------------------------------------------------------------------*/
776 /**
777  * @brief   ico_uxf_window_createdcb: wayland surface create callback(static function)
778  *
779  * @param[in]   data            user data(unused)
780  * @param[in]   ico_window_mgr  wayland ico_window_mgr plugin interface
781  * @param[in]   surfaceid       ico_window_mgr surface Id
782  * @param[in]   pid             wayland client process Id
783  * @param[in]   appid           wayland client application Id
784  * @return      none
785  */
786 /*--------------------------------------------------------------------------*/
787 static void
788 ico_uxf_window_createdcb(void *data, struct ico_window_mgr *ico_window_mgr,
789                          uint32_t surfaceid, int32_t pid, const char *appid)
790 {
791     Ico_Uxf_Mng_Process *prc;
792     Ico_Uxf_Mng_ProcWin *ppwin;
793     Ico_Uxf_Mng_ProcWin *ppw;
794
795     uifw_trace("ico_uxf_window_createdcb: Enter(surf=%08x pid=%d appid=%s myapp=%s)",
796                (int)surfaceid, pid, appid, gIco_Uxf_Api_Mng.MyProcess);
797
798     prc = ico_uxf_mng_process(appid, 0);
799     if (prc)    {
800         /* set window animation     */
801         if (prc->appconf != NULL)   {
802             if (((Ico_Uxf_conf_application *)prc->appconf)->animation)  {
803                 ico_window_mgr_set_animation(
804                     gIco_Uxf_Api_Mng.Wayland_WindowMgr, surfaceid,
805                     ((Ico_Uxf_conf_application *)prc->appconf)->animation,
806                     ((Ico_Uxf_conf_application *)prc->appconf)->animation_time);
807             }
808             else if (((Ico_Uxf_conf_application *)prc->appconf)->animation_time > 0)    {
809                 ico_window_mgr_set_animation(
810                     gIco_Uxf_Api_Mng.Wayland_WindowMgr, surfaceid, " ",
811                     ((Ico_Uxf_conf_application *)prc->appconf)->animation_time);
812             }
813         }
814         if (prc->attr.mainwin.window <= 0)  {
815             uifw_trace("ico_uxf_window_createdcb: Set Main Window, Config Data");
816             prc->attr.mainwin.window = surfaceid;
817             ico_uxf_window_configurecb(data, ico_window_mgr, surfaceid, appid,
818                                        prc->attr.mainwin.layer, prc->attr.mainwin.x,
819                                        prc->attr.mainwin.y, prc->attr.mainwin.w,
820                                        prc->attr.mainwin.h, 0);
821             if (gIco_Uxf_Api_Mng.Hook_Window)   {
822                 (*gIco_Uxf_Api_Mng.Hook_Window)(prc->attr.process, surfaceid,
823                                                 ICO_UXF_HOOK_WINDOW_CREATE_MAIN);
824             }
825         }
826         else    {
827             uifw_trace("ico_uxf_window_createdcb: Sub Window, Dummy Data");
828             ico_uxf_window_configurecb(data, ico_window_mgr, surfaceid, appid,
829                                        prc->attr.mainwin.layer, 16384, 16384, 1, 1, 0);
830             ppwin = (Ico_Uxf_Mng_ProcWin *)malloc(sizeof(Ico_Uxf_Mng_ProcWin));
831             if (ppwin) {
832                 memset(ppwin, 0, sizeof(Ico_Uxf_Mng_ProcWin));
833                 ppwin->attr.window = surfaceid;
834                 ppwin->attr.display = prc->attr.mainwin.display;
835                 if (!prc->procwin) {
836                     prc->procwin = ppwin;
837                 }
838                 else {
839                     ppw = prc->procwin;
840                     while (ppw->next) {
841                         ppw = ppw->next;
842                     }
843                     ppw->next = ppwin;
844                 }
845             }
846             if (gIco_Uxf_Api_Mng.Hook_Window)   {
847                 (*gIco_Uxf_Api_Mng.Hook_Window)(prc->attr.process, surfaceid,
848                                                 ICO_UXF_HOOK_WINDOW_CREATE_SUB);
849             }
850         }
851     }
852     else    {
853         uifw_warn("ico_uxf_window_createdcb: Application.%s dose not exist", appid);
854     }
855     uifw_trace("ico_uxf_window_createdcb: Leave");
856 }
857
858 /*--------------------------------------------------------------------------*/
859 /**
860  * @brief   ico_uxf_window_destroyedcb: wayland surface destroy callback(static function)
861  *
862  * @param[in]   data            user data(unused)
863  * @param[in]   ico_window_mgr  wayland ico_window_mgr plugin interface
864  * @param[in]   surfaceid       ico_window_mgr surface Id
865  * @return      none
866  */
867 /*--------------------------------------------------------------------------*/
868 static void
869 ico_uxf_window_destroyedcb(void *data, struct ico_window_mgr *ico_window_mgr,
870                            uint32_t surfaceid)
871 {
872     Ico_Uxf_Mng_Window  *p;
873     Ico_Uxf_Mng_Window  *pp;
874     Ico_Uxf_Mng_Window  *freep;
875     Ico_Uxf_Mng_Process *prc;
876     Ico_Uxf_Mng_EventQue *que;
877     int                 hash;
878     char                wkappid[ICO_UXF_MAX_PROCESS_NAME+1];
879     int                 wksubwindow;
880
881     uifw_trace("ico_uxf_window_destroyedcb: Enter(surf=%08x)", (int)surfaceid);
882
883     ico_uxf_enter_critical();
884
885     p = ico_uxf_mng_window(surfaceid, 0);
886
887     if (! p)    {
888         ico_uxf_leave_critical();
889         uifw_trace("ico_uxf_window_destroyedcb: Leave(Surface=%08x dose not exist)",
890                    (int)surfaceid);
891         return;
892     }
893     prc = p->mng_process;
894     if ((prc != NULL) && (prc->attr.mainwin.window == (int)surfaceid))  {
895         prc->attr.mainwin.window = 0;
896     }
897
898     strcpy(wkappid, p->attr.process);
899     wksubwindow = p->attr.subwindow;
900
901     if ((gIco_Uxf_Api_Mng.EventMask & ICO_UXF_EVENT_DESTORYWINDOW) &&
902         (p->attr.eventmask & ICO_UXF_EVENT_DESTORYWINDOW)) {
903
904         que = ico_uxf_alloc_eventque();
905         que->detail.event = ICO_UXF_EVENT_DESTORYWINDOW;
906         que->detail.window.display = p->attr.display;
907         que->detail.window.window = surfaceid;
908         que->detail.window.layer = p->attr.layer;
909         que->detail.window.x = p->attr.x;
910         que->detail.window.y = p->attr.y;
911         que->detail.window.w = p->attr.w;
912         que->detail.window.h = p->attr.h;
913         que->detail.window.visible = p->attr.visible;
914         que->detail.window.raise = p->attr.raise;
915         que->detail.window.active = p->attr.active;
916         ico_uxf_regist_eventque(que);
917     }
918
919     for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++)   {
920         p = gIco_Uxf_Api_Mng.Hash_WindowId[hash];
921         pp = (Ico_Uxf_Mng_Window *)0;
922         while (p)  {
923             if (p->attr.window == (int)surfaceid)  {
924                 freep = p;
925                 p = p->nextidhash;
926                 if (! pp)  {
927                     gIco_Uxf_Api_Mng.Hash_WindowId[hash] = p;
928                 }
929                 else    {
930                     pp->nextidhash = p;
931                 }
932                 uifw_trace("ico_uxf_window_destroyedcb: Free Window.%08x(%08x)",
933                            (int)freep, freep->attr.window);
934                 free(freep);
935                 hash = ICO_UXF_MISC_HASHSIZE;
936                 break;
937             }
938             pp = p;
939             p = p->nextidhash;
940         }
941     }
942     ico_uxf_leave_critical();
943
944     if (gIco_Uxf_Api_Mng.Hook_Window)   {
945         (*gIco_Uxf_Api_Mng.Hook_Window)(wkappid, surfaceid,
946                                         wksubwindow ? ICO_UXF_HOOK_WINDOW_DESTORY_SUB :
947                                                       ICO_UXF_HOOK_WINDOW_DESTORY_MAIN);
948     }
949     uifw_trace("ico_uxf_window_destroyedcb: Leave");
950 }
951
952 /*--------------------------------------------------------------------------*/
953 /**
954  * @brief   ico_uxf_window_visiblecb: wayland surface visible callback(static function)
955  *
956  * @param[in]   data            user data(unused)
957  * @param[in]   ico_window_mgr  wayland ico_window_mgr plugin interface
958  * @param[in]   surfaceid       ico_window_mgr surface Id
959  * @param[in]   visibility      surface visible(1=visible/0=unvisible/9=nochange)
960  * @param[in]   raise           surface raise(1=raise/0=lower/9=nochange)
961  * @param[in]   hint            client request(1=client request(not changed)/0=changed)
962  * @return      none
963  */
964 /*--------------------------------------------------------------------------*/
965 static void
966 ico_uxf_window_visiblecb(void *data, struct ico_window_mgr *ico_window_mgr,
967                          uint32_t surfaceid, int32_t visible, int32_t raise, int32_t hint)
968 {
969     Ico_Uxf_Mng_Window  *win;
970     Ico_Uxf_Mng_EventQue *que;
971     int                 ovisible;
972     int                 oraise;
973
974     ico_uxf_enter_critical();
975
976     win = ico_uxf_mng_window(surfaceid, 0);
977
978     if (!win)  {
979         ico_uxf_leave_critical();
980         uifw_trace("ico_uxf_window_visiblecb: Surface=%08x dose not exist",
981                    (int)surfaceid);
982         return;
983     }
984
985     ovisible = visible;
986     oraise = raise;
987     if (ovisible == 9) {
988         ovisible = win->attr.visible;
989     }
990     if (oraise == 9)   {
991         oraise = win->attr.raise;
992     }
993
994     if ((win->attr.visible != ovisible) ||
995         (win->attr.raise != oraise))   {
996
997         if (((hint == 0) && (gIco_Uxf_Api_Mng.EventMask & ICO_UXF_EVENT_VISIBLE) &&
998              (win->attr.eventmask & ICO_UXF_EVENT_VISIBLE)) ||
999             ((hint != 0) && (gIco_Uxf_Api_Mng.EventMask & ICO_UXF_EVENT_VISIBLE_REQ) &&
1000              (win->attr.eventmask & ICO_UXF_EVENT_VISIBLE_REQ)))   {
1001
1002             que = ico_uxf_alloc_eventque();
1003             que->detail.event =
1004                     (hint == 0) ? ICO_UXF_EVENT_VISIBLE : ICO_UXF_EVENT_VISIBLE_REQ;
1005             que->detail.window.display = win->attr.display;
1006             que->detail.window.window = win->attr.window;
1007             que->detail.window.layer = win->attr.layer;
1008             que->detail.window.x = win->attr.x;
1009             que->detail.window.y = win->attr.y;
1010             que->detail.window.w = win->attr.w;
1011             que->detail.window.h = win->attr.h;
1012             que->detail.window.visible = ovisible;
1013             que->detail.window.raise = oraise;
1014             que->detail.window.active = win->attr.active;
1015
1016             ico_uxf_regist_eventque(que);
1017         }
1018     }
1019     ico_uxf_leave_critical();
1020 }
1021
1022 /*--------------------------------------------------------------------------*/
1023 /**
1024  * @brief   ico_uxf_window_configurecb: wayland surface configure callback(static function)
1025  *
1026  * @param[in]   data            user data(unused)
1027  * @param[in]   ico_window_mgr  wayland ico_window_mgr plugin interface
1028  * @param[in]   surfaceid       ico_window_mgr surface Id
1029  * @param[in]   appid           client application Id
1030  * @param[in]   x               surface upper-left X coodinate
1031  * @param[in]   y               surface upper-left Y coodinate
1032  * @param[in]   width           surface width
1033  * @param[in]   height          surface height
1034  * @param[in]   hint            client request(1=client request(not changed)/0=changed)
1035  * @return      none
1036  */
1037 /*--------------------------------------------------------------------------*/
1038 static void
1039 ico_uxf_window_configurecb(void *data, struct ico_window_mgr *ico_window_mgr,
1040                            uint32_t surfaceid, const char *appid, int32_t layer,
1041                            int32_t x, int32_t y, int32_t width, int32_t height,
1042                            int32_t hint)
1043 {
1044     Ico_Uxf_Mng_Window  *win;
1045     Ico_Uxf_Mng_EventQue *que;
1046     int                 display;
1047     Ico_Uxf_Mng_Process *prc;
1048
1049 #if 0               /* too many logout, change to comment out   */
1050     uifw_trace("ico_uxf_window_configurecb: surf=%08x app=%s layer=%d "
1051                "x/y=%d/%d w/h=%d/%d hint=%d",
1052                (int)surfaceid, appid, layer, x, y, width, height, hint);
1053 #endif              /* too many logout, change to comment out   */
1054
1055     ico_uxf_enter_critical();
1056
1057     win = ico_uxf_mng_window(surfaceid, 0);
1058
1059     if (!win)  {
1060         win = ico_uxf_mng_window(surfaceid, 1);
1061         display = ICO_UXF_GETDISPLAYID(surfaceid);
1062         win->mng_display = ico_uxf_mng_display(display, 0);
1063         win->mng_layer = ico_uxf_mng_layer(display, layer, 0);
1064         win->attr.eventmask = ICO_UXF_EVENT_NEWWINDOW;
1065         win->attr.display = display;
1066         win->attr.layer = layer;
1067         memset(win->attr.process, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
1068         strncpy(win->attr.process, appid, ICO_UXF_MAX_PROCESS_NAME);
1069         win->attr.x = x;
1070         win->attr.y = y;
1071         win->attr.w = width;
1072         win->attr.h = height;
1073         hint = 0;
1074
1075         prc = ico_uxf_mng_process(appid, 0);
1076         win->mng_process = prc;
1077         if ((prc != NULL) && (prc->attr.mainwin.window != (int)surfaceid)) {
1078             /* sub-window */
1079             win->attr.subwindow = 1;
1080         }
1081
1082         if (gIco_Uxf_Api_Mng.EventMask & ICO_UXF_EVENT_NEWWINDOW)    {
1083
1084             que = ico_uxf_alloc_eventque();
1085
1086             que->detail.event = ICO_UXF_EVENT_NEWWINDOW;
1087             que->detail.window.display = display;
1088             que->detail.window.window = surfaceid;
1089             que->detail.window.layer = layer;
1090             que->detail.window.x = win->attr.x;
1091             que->detail.window.y = win->attr.y;
1092             que->detail.window.w = win->attr.w;
1093             que->detail.window.h = win->attr.h;
1094             que->detail.window.visible = win->attr.visible;
1095             que->detail.window.raise = win->attr.raise;
1096             que->detail.window.active = win->attr.active;
1097
1098             ico_uxf_regist_eventque(que);
1099         }
1100     }
1101     else    {
1102         if ((win->attr.layer != layer) ||
1103             (win->attr.x != x) || (win->attr.y != y) ||
1104             (win->attr.w != width) || (win->attr.h != height)) {
1105
1106             if (((hint == 0) && (gIco_Uxf_Api_Mng.EventMask & ICO_UXF_EVENT_RESIZE) &&
1107                  (win->attr.eventmask & ICO_UXF_EVENT_RESIZE)) ||
1108                 ((hint != 0) && (gIco_Uxf_Api_Mng.EventMask & ICO_UXF_EVENT_RESIZE_REQ) &&
1109                  (win->attr.eventmask & ICO_UXF_EVENT_RESIZE_REQ)))    {
1110
1111                 que = ico_uxf_alloc_eventque();
1112
1113                 que->detail.event =
1114                         (hint == 0) ? ICO_UXF_EVENT_RESIZE : ICO_UXF_EVENT_RESIZE_REQ;
1115                 que->detail.window.display = win->mng_display->attr.display;
1116                 que->detail.window.window = win->attr.window;
1117                 que->detail.window.layer = layer;
1118                 que->detail.window.x = x;
1119                 que->detail.window.y = y;
1120                 que->detail.window.w = width;
1121                 que->detail.window.h = height;
1122                 que->detail.window.visible = win->attr.visible;
1123                 que->detail.window.raise = win->attr.raise;
1124                 que->detail.window.active = win->attr.active;
1125
1126                 ico_uxf_regist_eventque(que);
1127             }
1128             if (hint == 0)  {
1129                 win->attr.x = x;
1130                 win->attr.y = y;
1131                 win->attr.w = width;
1132                 win->attr.h = height;
1133                 if (win->attr.layer != layer)  {
1134                     win->attr.layer = layer;
1135                     win->mng_layer = ico_uxf_mng_layer(win->mng_display->attr.display,
1136                                                        layer, 0);
1137                 }
1138             }
1139         }
1140     }
1141     ico_uxf_leave_critical();
1142 }
1143
1144 /*--------------------------------------------------------------------------*/
1145 /**
1146  * @brief   ico_uxf_window_activecb: wayland surface active callback(static function)
1147  *
1148  * @param[in]   data            user data(unused)
1149  * @param[in]   ico_window_mgr  wayland ico_window_mgr plugin interface
1150  * @param[in]   surfaceid       ico_window_mgr surface Id
1151  * @param[in]   active          surface active(1=active/0=not active)
1152  * @return      none
1153  */
1154 /*--------------------------------------------------------------------------*/
1155 static void
1156 ico_uxf_window_activecb(void *data, struct ico_window_mgr *ico_window_mgr,
1157                         uint32_t surfaceid, uint32_t active)
1158 {
1159     Ico_Uxf_Mng_Window  *win;
1160     Ico_Uxf_Mng_EventQue *que;
1161
1162     uifw_trace("ico_uxf_window_activecb: Enter(surf=%08x active=%d)", surfaceid, active);
1163
1164     ico_uxf_enter_critical();
1165
1166     win = ico_uxf_mng_window(surfaceid, 0);
1167
1168     if (win)  {
1169         if (gIco_Uxf_Api_Mng.EventMask & ICO_UXF_EVENT_ACTIVEWINDOW)    {
1170
1171             que = ico_uxf_alloc_eventque();
1172
1173             que->detail.event = ICO_UXF_EVENT_ACTIVEWINDOW;
1174             que->detail.window.display = ICO_UXF_GETDISPLAYID(surfaceid);
1175             que->detail.window.window = surfaceid;
1176             que->detail.window.active = active;
1177             win->attr.active = active;
1178
1179             ico_uxf_regist_eventque(que);
1180         }
1181     }
1182     ico_uxf_leave_critical();
1183     uifw_trace("ico_uxf_window_activecb: Leave");
1184 }
1185
1186 /*--------------------------------------------------------------------------*/
1187 /**
1188  * @brief   ico_uxf_input_capabilitiescb: wayland extended input
1189  *                                        input capabilities callback(static function)
1190  *
1191  * @param[in]   data            user data(unused)
1192  * @param[in]   ico_exinput     wayland ico_input_mgr plugin interface
1193  * @param[in]   device          input device name
1194  * @param[in]   type            input device type
1195  * @param[in]   swname          input switch name
1196  * @param[in]   input           input switch number
1197  * @param[in]   codename        input code name
1198  * @param[in]   code            input code value
1199  * @return      none
1200  */
1201 /*--------------------------------------------------------------------------*/
1202 static void
1203 ico_uxf_input_capabilitiescb(void *data, struct ico_exinput *ico_exinput,
1204                              const char *device, int32_t type, const char *swname,
1205                              int32_t input, const char *codename, int32_t code)
1206 {
1207     int     i, j;
1208     Ico_Uxf_Sys_Config  *sysconf = (Ico_Uxf_Sys_Config *)ico_uxf_getSysConfig();
1209     Ico_Uxf_InputDev    *inputdev;
1210     Ico_Uxf_InputDev    *bpdev;
1211     Ico_Uxf_InputSw     *inputsw;
1212     Ico_Uxf_InputSw     *bpsw;
1213
1214     uifw_trace("ico_uxf_input_capabilitiescb: "
1215                "Enter(device=%s type=%d sw=%s input=%d code=%s[%d])",
1216                device, type, swname, input, codename, code);
1217
1218     if (! sysconf)  return;
1219
1220     /* search and create input device table     */
1221     bpdev = NULL;
1222     inputdev = gIco_Uxf_Api_Mng.InputDev;
1223     while (inputdev)    {
1224         if (strcasecmp(inputdev->device, device) == 0)  break;
1225         bpdev = inputdev;
1226         inputdev = inputdev->next;
1227     }
1228     if (! inputdev) {
1229         inputdev = malloc(sizeof(Ico_Uxf_InputDev));
1230         if (! inputdev) {
1231             uifw_error("ico_uxf_input_capabilitiescb: Leave(No Memory)");
1232             return;
1233         }
1234         memset(inputdev, 0, sizeof(Ico_Uxf_InputDev));
1235
1236         if (bpdev)  {
1237             bpdev->next = inputdev;
1238         }
1239         else    {
1240             gIco_Uxf_Api_Mng.InputDev = inputdev;
1241         }
1242     }
1243     strncpy(inputdev->device, device, sizeof(inputdev->device)-1);
1244     inputdev->type = type;
1245
1246     bpsw = NULL;
1247     inputsw = inputdev->inputSw;
1248     while (inputsw) {
1249         if (strcasecmp(inputsw->swname, swname) == 0)   break;
1250         bpsw = inputsw;
1251         inputsw = inputsw->next;
1252     }
1253     if (! inputsw)  {
1254         inputsw = malloc(sizeof(Ico_Uxf_InputSw));
1255         if (! inputsw)  {
1256             uifw_error("ico_uxf_input_capabilitiescb: Leave(No Memory)");
1257             return;
1258         }
1259         if (bpsw)   {
1260             bpsw->next = inputsw;
1261         }
1262         else    {
1263             inputdev->inputSw = inputsw;
1264         }
1265         inputdev->numInputSw ++;
1266     }
1267     memset(inputsw, 0, sizeof(Ico_Uxf_InputSw));
1268     strncpy(inputsw->swname, swname, sizeof(inputsw->swname)-1);
1269     inputsw->input = input;
1270     inputsw->numCode = 1;
1271     inputsw->inputCode[0].code = code;
1272     strncpy(inputsw->inputCode[0].codename, codename,
1273             sizeof(inputsw->inputCode[0].codename)-1);
1274     uifw_trace("ico_uxf_input_capabilitiescb: create new inputsw");
1275
1276     /* send fixed application if fixed switch   */
1277     for (i = 0; i < sysconf->inputdevNum; i++)  {
1278         if (strcasecmp(sysconf->inputdev[i].name, inputdev->device) != 0)   continue;
1279
1280         for (j = 0; j < sysconf->inputdev[i].inputswNum; j++)   {
1281             if (! sysconf->inputdev[i].inputsw[j].appid)    continue;
1282             if (strcasecmp(sysconf->inputdev[i].inputsw[j].name,
1283                 inputsw->swname) != 0)  continue;
1284
1285             uifw_trace("ico_uxf_input_capabilitiescb: input %s.%s = %s",
1286                        inputdev->device, inputsw->swname,
1287                        sysconf->inputdev[i].inputsw[j].appid);
1288             ico_input_mgr_control_add_input_app(gIco_Uxf_Api_Mng.Wayland_InputMgr,
1289                                                 sysconf->inputdev[i].inputsw[j].appid,
1290                                                 inputdev->device, inputsw->input, 1);
1291             inputsw->fix = 1;
1292             break;
1293         }
1294     }
1295     uifw_trace("ico_uxf_input_capabilitiescb: Leave");
1296 }
1297
1298 /*--------------------------------------------------------------------------*/
1299 /**
1300  * @brief   ico_uxf_input_codecb: wayland extended input
1301  *                                input code callback(static function)
1302  *
1303  * @param[in]   data            user data(unused)
1304  * @param[in]   ico_exinput     wayland ico_input_mgr plugin interface
1305  * @param[in]   device          input device name
1306  * @param[in]   input           input switch number
1307  * @param[in]   codename        input code name
1308  * @param[in]   code            input code value
1309  * @return      none
1310  */
1311 /*--------------------------------------------------------------------------*/
1312 static void
1313 ico_uxf_input_codecb(void *data, struct ico_exinput *ico_exinput, const char *device,
1314                      int32_t input, const char *codename, int32_t code)
1315 {
1316     int     i;
1317     Ico_Uxf_InputDev    *inputdev;
1318     Ico_Uxf_InputSw     *inputsw;
1319
1320     uifw_trace("ico_uxf_input_codecb: device=%s input=%d code=%s[%d]",
1321                device, input, codename, code);
1322
1323     /* search input device table                */
1324     inputdev = gIco_Uxf_Api_Mng.InputDev;
1325     while (inputdev)    {
1326         if (strcasecmp(inputdev->device, device) == 0)  break;
1327         inputdev = inputdev->next;
1328     }
1329     if (! inputdev) {
1330         uifw_error("ico_uxf_input_codecb: device.%s dose not exist", device);
1331         return;
1332     }
1333
1334     /* search input switch                      */
1335     inputsw = inputdev->inputSw;
1336     while (inputsw) {
1337         if (inputsw->input == input)    break;
1338         inputsw = inputsw->next;
1339     }
1340     if (! inputsw)  {
1341         uifw_error("ico_uxf_input_codecb: device.%s input=%d dose not exist",
1342                    device, input);
1343         return;
1344     }
1345     for (i = 0; i < inputsw->numCode; i++)  {
1346         if (inputsw->inputCode[i].code == code) break;
1347     }
1348     if (i >= inputsw->numCode)  {
1349         if (i >= 8) {
1350             uifw_error("ico_uxf_input_codecb: device.%s input=%d number of codes overflow",
1351                        device, input);
1352             return;
1353         }
1354         inputsw->numCode ++;
1355         i = inputsw->numCode - 1;
1356     }
1357     memset(inputsw->inputCode[i].codename, 0, sizeof(inputsw->inputCode[i].codename));
1358     strncpy(inputsw->inputCode[i].codename, codename,
1359             sizeof(inputsw->inputCode[i].codename)-1);
1360     inputsw->inputCode[i].code = code;
1361 }
1362
1363 /*--------------------------------------------------------------------------*/
1364 /**
1365  * @brief   ico_uxf_input_inputcb: wayland extended input
1366  *                                 input switch callback(static function)
1367  *
1368  * @param[in]   data            user data(unused)
1369  * @param[in]   ico_exinput     wayland ico_input_mgr plugin interface
1370  * @param[in]   time            input time(miri-sec)
1371  * @param[in]   device          input device name
1372  * @param[in]   input           input switch number
1373  * @param[in]   code            input code value
1374  * @param[in]   state           input state(1=switch On/0=switch Off)
1375  * @return      none
1376  */
1377 /*--------------------------------------------------------------------------*/
1378 static void
1379 ico_uxf_input_inputcb(void *data, struct ico_exinput *ico_exinput, uint32_t time,
1380                       const char *device, int32_t input, int32_t code, int32_t state)
1381 {
1382     Ico_Uxf_Mng_EventQue *que;
1383     uifw_trace("ico_uxf_input_inputcb: device=%s input=%d code=%d state=%d",
1384                device, input, code, state);
1385
1386     if (gIco_Uxf_Api_Mng.EventMask & ICO_UXF_EVENT_EXINPUT)    {
1387
1388         ico_uxf_enter_critical();
1389         que = ico_uxf_alloc_eventque();
1390
1391         strncpy(que->detail.exinput.device, device,
1392                 sizeof(que->detail.exinput.device)-1);
1393         que->detail.exinput.input = input;
1394         que->detail.exinput.code = code;
1395         que->detail.exinput.state = state;
1396
1397         ico_uxf_regist_eventque(que);
1398         ico_uxf_leave_critical();
1399     }
1400 }
1401
1402 /*--------------------------------------------------------------------------*/
1403 /**
1404  * @brief   ico_uxf_aul_aulcb: AppCore(AUL) application launch/dead callback(static function)
1405  *
1406  * @param[in]   pid             target application process Id
1407  * @param[in]   data            user data(0=launch, 1=dead)
1408  * @return      result(always 0, means success)
1409  */
1410 /*--------------------------------------------------------------------------*/
1411 static int
1412 ico_uxf_aul_aulcb(int pid, void *data)
1413 {
1414     Ico_Uxf_Mng_Process     *proc;
1415     int                     hash;
1416     Ico_Uxf_Mng_EventQue    *que;
1417     int                     dead;
1418     char                    appid[ICO_UXF_MAX_PROCESS_NAME+1];
1419
1420     dead = (int)data;
1421     memset(appid, 0, sizeof(appid));
1422     if (dead == 0)  {
1423         (void) aul_app_get_appid_bypid(pid, appid, sizeof(appid));
1424         uifw_trace("ico_uxf_aul_aulcb: Enter(pid=%d, dead=No, appid=%s)", pid, appid);
1425     }
1426     else    {
1427         uifw_trace("ico_uxf_aul_aulcb: Enter(pid=%d, dead=Yes)", pid);
1428     }
1429     for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++) {
1430         proc = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
1431         while (proc)   {
1432             if (proc->attr.internalid == pid) break;
1433             if (strcmp(proc->attr.process, appid) == 0) break;
1434             proc = proc->nextidhash;
1435         }
1436         if (proc) break;
1437     }
1438     if (! proc) {
1439         /* not handle process,  */
1440         /* or the process is correctly terminated by ico_uxf_process_terminate */
1441         uifw_trace("ico_uxf_aul_aulcb: Leave(not find)");
1442         return 0;
1443     }
1444     uifw_trace("ico_uxf_aul_aulcb: find(appid=%s)", proc->attr.process);
1445
1446     ico_uxf_enter_critical();
1447     /* set event */
1448     que = ico_uxf_alloc_eventque();
1449     strncpy(que->detail.process.process, proc->attr.process, ICO_UXF_MAX_PROCESS_NAME);
1450     if (dead)   {
1451         que->detail.event = ICO_UXF_EVENT_TERMPROCESS;
1452         que->detail.process.status = ICO_UXF_PROCSTATUS_STOP;
1453
1454         /* delete process info */
1455         proc->attr.status = ICO_UXF_PROCSTATUS_STOP;
1456         proc->attr.internalid = -1;
1457         proc->attr.mainwin.window = 0;
1458         ico_uxf_free_procwin(proc);
1459     }
1460     else    {
1461         que->detail.event = ICO_UXF_EVENT_EXECPROCESS;
1462         que->detail.process.status = ICO_UXF_PROCSTATUS_RUN;
1463
1464         /* setup process info */
1465         if (proc->attr.status != ICO_UXF_PROCSTATUS_RUN)    {
1466             proc->attr.internalid = pid;
1467             if (proc->attr.status != ICO_UXF_PROCSTATUS_INIT)   {
1468                 /* child process, search parent process */
1469                 uifw_trace("ico_uxf_aul_aulcb: fork&exec %s", proc->attr.process);
1470                 proc->attr.child = 1;
1471                 /* save parent application if exist     */
1472                 if (gIco_Uxf_Api_Mng.Mng_LastProcess != proc)   {
1473                     proc->parent = gIco_Uxf_Api_Mng.Mng_LastProcess;
1474                 }
1475                 else    {
1476                     uifw_trace("ico_uxf_aul_aulcb: same process %s real %s", proc->attr.process,
1477                                proc->parent ? proc->parent->attr.process : "(None)");
1478                 }
1479             }
1480             else    {
1481                 proc->attr.child = 0;
1482             }
1483             proc->attr.status = ICO_UXF_PROCSTATUS_RUN;
1484         }
1485     }
1486
1487     /* notify event */
1488     ico_uxf_regist_eventque(que);
1489
1490     ico_uxf_leave_critical();
1491
1492     uifw_trace("ico_uxf_aul_aulcb: Leave");
1493     return 0;
1494 }
1495
1496 /*--------------------------------------------------------------------------*/
1497 /**
1498  * @brief   ico_uxf_set_lastapp: save last application
1499  *
1500  * @param[in]   appid   applicationId (if NULL, no last application)
1501  * @return      none
1502  */
1503 /*--------------------------------------------------------------------------*/
1504 ICO_APF_API void
1505 ico_uxf_set_lastapp(const char *appid)
1506 {
1507     if (appid)  {
1508         gIco_Uxf_Api_Mng.Mng_LastProcess = ico_uxf_mng_process(appid, 0);
1509     }
1510     else    {
1511         gIco_Uxf_Api_Mng.Mng_LastProcess = NULL;
1512     }
1513 }
1514
1515 /*--------------------------------------------------------------------------*/
1516 /**
1517  * @brief   ico_uxf_getchild_appid: get child applicationId
1518  *
1519  * @param[in]   appid   parent applicationId
1520  * @return      last child applicationId
1521  * @retval      !=NULL      success(applicationId)
1522  * @retval      ==NULL      no child application
1523  */
1524 /*--------------------------------------------------------------------------*/
1525 ICO_APF_API char *
1526 ico_uxf_getchild_appid(const char *appid)
1527 {
1528     Ico_Uxf_Mng_Process *pproc;
1529     Ico_Uxf_Mng_Process *proc;
1530     int     hash;
1531
1532     pproc = ico_uxf_mng_process(appid, 0);
1533     if (! pproc)    {
1534         /* unknown parent application, no child     */
1535         uifw_trace("ico_uxf_getchild_appid: Unknown parent(%s)", appid);
1536         return NULL;
1537     }
1538
1539     /* search parent        */
1540     for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++)    {
1541         proc = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
1542         while (proc)    {
1543             if (proc->parent == pproc)  {
1544                 uifw_trace("ico_uxf_getchild_appid: child(%s) parent(%s)",
1545                            proc->attr.process, appid);
1546                 return proc->attr.process;
1547             }
1548             proc = proc->nextidhash;
1549         }
1550     }
1551     uifw_trace("ico_uxf_getchild_appid: parent(%s) has no child", appid);
1552     return NULL;
1553 }
1554
1555 /*--------------------------------------------------------------------------*/
1556 /**
1557  * @brief   ico_uxf_set_lastapp: save last application
1558  *
1559  * @param[in]   appid   applicationId (if NULL, no last application)
1560  * @return      none
1561  */
1562 /*--------------------------------------------------------------------------*/
1563 ICO_APF_API void
1564 ico_uxf_timer_wake(const int msec)
1565 {
1566     Ico_Uxf_Mng_Process *proc;
1567     int     hash;
1568
1569     if (gIco_Uxf_Api_Mng.InitTimer > 0) {
1570         gIco_Uxf_Api_Mng.InitTimer -= msec;
1571         if (gIco_Uxf_Api_Mng.InitTimer > 0) {
1572             return;
1573         }
1574         gIco_Uxf_Api_Mng.InitTimer = 0;
1575     }
1576
1577     if (gIco_Uxf_Api_Mng.NeedTimer == 0)    {
1578         return;
1579     }
1580     gIco_Uxf_Api_Mng.NeedTimer = 0;
1581     for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++)    {
1582         proc = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
1583         while (proc)    {
1584             if (proc->susptimer > 0)    {
1585                 if (msec >= proc->susptimer)    {
1586                     proc->susptimer = 0;
1587                     if (proc->attr.suspend) {
1588                         if (proc->susp == 0)    {
1589                             proc->susp = 1;
1590                             uifw_trace("ico_uxf_timer_wake: CPU suspend pid=%d",
1591                                        proc->attr.internalid);
1592                             kill(proc->attr.internalid, SIGSTOP);
1593                         }
1594                     }
1595                     else if (proc->susp == 0)    {
1596                         uifw_trace("ico_uxf_timer_wake: CPU resume pid=%d(show=%d)",
1597                                    proc->attr.internalid, proc->showmode);
1598                         ico_window_mgr_set_visible(gIco_Uxf_Api_Mng.Wayland_WindowMgr,
1599                                                    proc->attr.mainwin.window,
1600                                                    proc->showmode ==
1601                                                        ICO_WINDOW_MGR_VISIBLE_SHOW_ANIMATION ?
1602                                                      ICO_WINDOW_MGR_VISIBLE_SHOW_ANIMATION :
1603                                                      ICO_WINDOW_MGR_VISIBLE_SHOW,
1604                                                    ICO_WINDOW_MGR_RAISE_NOCHANGE);
1605                         wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
1606                     }
1607                 }
1608                 else    {
1609                     proc->susptimer -= msec;
1610                     gIco_Uxf_Api_Mng.NeedTimer ++;
1611                 }
1612             }
1613             proc = proc->nextidhash;
1614         }
1615     }
1616 }
1617
1618 /*--------------------------------------------------------------------------*/
1619 /**
1620  * @brief   ico_uxf_enter_critical: enter critical section(internal function)
1621  *
1622  * @param       none
1623  * @return      none
1624  */
1625 /*--------------------------------------------------------------------------*/
1626 void
1627 ico_uxf_enter_critical(void)
1628 {
1629     if (pthread_mutex_lock(&sMutex)) {
1630         uifw_error("ico_uxf_enter_critical: Error<%d>", errno);
1631     }
1632 }
1633
1634 /*--------------------------------------------------------------------------*/
1635 /**
1636  * @brief   ico_uxf_leave_critical: leave critical section(internal function)
1637  *
1638  * @param       none
1639  * @return      none
1640  */
1641 /*--------------------------------------------------------------------------*/
1642 void
1643 ico_uxf_leave_critical(void)
1644 {
1645     if (pthread_mutex_unlock(&sMutex))   {
1646         uifw_error("ico_uxf_leave_critical: Error<%d>", errno);
1647     }
1648 }
1649
1650 /*--------------------------------------------------------------------------*/
1651 /**
1652  * @brief   ico_uxf_alloc_callback: allocate callback management table(internal function)
1653  *
1654  * @param       none
1655  * @return      allocated callback management table address
1656  */
1657 /*--------------------------------------------------------------------------*/
1658 Ico_Uxf_Mng_Callback *
1659 ico_uxf_alloc_callback(void)
1660 {
1661     Ico_Uxf_Mng_Callback    *p;
1662     int                     idx;
1663
1664     p = gIco_Uxf_Api_Mng.CallbackFree;
1665     if (! p)   {
1666         p = (Ico_Uxf_Mng_Callback *)malloc(sizeof(Ico_Uxf_Mng_Callback) *
1667                                            ICO_UXF_MNG_BLOCK_ALLOCS);
1668         if (! p)   {
1669             uifw_error("ico_uxf_alloc_callback: NO Memory (malloc Error)");
1670             exit(1);
1671         }
1672         gIco_Uxf_Api_Mng.CallbackFree = p;
1673
1674         for (idx = 0; idx < ICO_UXF_MNG_BLOCK_ALLOCS; idx++, p++)  {
1675             if (idx != (ICO_UXF_MNG_BLOCK_ALLOCS-1))   {
1676                 p->next = (p+1);
1677             }
1678             else    {
1679                 p->next = (struct _Ico_Uxf_Mng_Callback *)0;
1680             }
1681         }
1682         p = gIco_Uxf_Api_Mng.CallbackFree;
1683     }
1684     gIco_Uxf_Api_Mng.CallbackFree = p->next;
1685     return p;
1686 }
1687
1688 /*--------------------------------------------------------------------------*/
1689 /**
1690  * @brief   ico_uxf_free_callback: release callback management table(internal function)
1691  *
1692  * @param[in]   p           callback management table address
1693  * @return      none
1694  */
1695 /*--------------------------------------------------------------------------*/
1696 void
1697 ico_uxf_free_callback(Ico_Uxf_Mng_Callback *p)
1698 {
1699     p->next = gIco_Uxf_Api_Mng.CallbackFree;
1700     gIco_Uxf_Api_Mng.CallbackFree = p;
1701 }
1702
1703 /*--------------------------------------------------------------------------*/
1704 /**
1705  * @brief   ico_uxf_regist_callback: register a callback management table(internal function)
1706  *
1707  * @param[in]   p           callback management table address
1708  * @return      none
1709  */
1710 /*--------------------------------------------------------------------------*/
1711 void
1712 ico_uxf_regist_callback(Ico_Uxf_Mng_Callback *p)
1713 {
1714     p->next = (struct _Ico_Uxf_Mng_Callback *)0;
1715
1716     if (gIco_Uxf_Api_Mng.Callback) {
1717         gIco_Uxf_Api_Mng.CallbackLast->next = p;
1718         gIco_Uxf_Api_Mng.CallbackLast = p;
1719     }
1720     else    {
1721         gIco_Uxf_Api_Mng.Callback = p;
1722         gIco_Uxf_Api_Mng.CallbackLast = gIco_Uxf_Api_Mng.Callback;
1723     }
1724 }
1725
1726 /*--------------------------------------------------------------------------*/
1727 /**
1728  * @brief   ico_uxf_remove_callback: remove a callback management table(internal function)
1729  *
1730  * @param[in]   p           callback management table address
1731  * @return      none
1732  */
1733 /*--------------------------------------------------------------------------*/
1734 void
1735 ico_uxf_remove_callback(Ico_Uxf_Mng_Callback *p)
1736 {
1737     Ico_Uxf_Mng_Callback    *pp;
1738     Ico_Uxf_Mng_Callback    *before;
1739
1740     pp = gIco_Uxf_Api_Mng.Callback;
1741     before = (Ico_Uxf_Mng_Callback *)0;
1742
1743     while (pp) {
1744         if (pp == p)   break;
1745         before = pp;
1746         pp = pp->next;
1747     }
1748     if (pp)    {
1749         if (before)    {
1750             before->next = p->next;
1751             if (! p->next) {
1752                 gIco_Uxf_Api_Mng.CallbackLast = before;
1753             }
1754         }
1755         else    {
1756             gIco_Uxf_Api_Mng.Callback = p->next;
1757         }
1758     }
1759 }
1760
1761 /*--------------------------------------------------------------------------*/
1762 /**
1763  * @brief   ico_uxf_alloc_eventque: allocate event queue block(internal function)
1764  *
1765  * @param       none
1766  * @return      allocated event queue control block address
1767  */
1768 /*--------------------------------------------------------------------------*/
1769 Ico_Uxf_Mng_EventQue
1770 *ico_uxf_alloc_eventque(void)
1771 {
1772     Ico_Uxf_Mng_EventQue    *p;
1773     int                 idx;
1774
1775     p = gIco_Uxf_Api_Mng.EventQueFree;
1776     if (! p)   {
1777         p = (Ico_Uxf_Mng_EventQue *)
1778                 malloc(sizeof(Ico_Uxf_Mng_EventQue) * ICO_UXF_MNG_BLOCK_ALLOCS);
1779         if (! p)   {
1780             uifw_error("ico_uxf_alloc_eventque: NO Memory (malloc Error)");
1781             exit(1);
1782         }
1783         gIco_Uxf_Api_Mng.EventQueFree = p;
1784
1785         for (idx = 0; idx < ICO_UXF_MNG_BLOCK_ALLOCS; idx++, p++)  {
1786             if (idx != (ICO_UXF_MNG_BLOCK_ALLOCS-1))   {
1787                 p->next = (p+1);
1788             }
1789             else    {
1790                 p->next = (struct _Ico_Uxf_Mng_EventQue *)0;
1791             }
1792         }
1793         p = gIco_Uxf_Api_Mng.EventQueFree;
1794     }
1795     gIco_Uxf_Api_Mng.EventQueFree = p->next;
1796
1797     return p;
1798 }
1799
1800 /*--------------------------------------------------------------------------*/
1801 /**
1802  * @brief   ico_uxf_free_eventque: release event queue block(internal function)
1803  *
1804  * @param[in]   p       event queue control block address
1805  * @return      none
1806  */
1807 /*--------------------------------------------------------------------------*/
1808 void
1809 ico_uxf_free_eventque(Ico_Uxf_Mng_EventQue *p)
1810 {
1811     p->next = gIco_Uxf_Api_Mng.EventQueFree;
1812     gIco_Uxf_Api_Mng.EventQueFree = p;
1813 }
1814
1815 /*--------------------------------------------------------------------------*/
1816 /**
1817  * @brief   ico_uxf_regist_eventque: register a event queue(internal function)
1818  *
1819  * @param[in]   p       event queue control block address
1820  * @return      none
1821  */
1822 /*--------------------------------------------------------------------------*/
1823 void
1824 ico_uxf_regist_eventque(Ico_Uxf_Mng_EventQue *p)
1825 {
1826     p->next = (struct _Ico_Uxf_Mng_EventQue *)0;
1827
1828     if (gIco_Uxf_Api_Mng.EventQue) {
1829         gIco_Uxf_Api_Mng.EventQueLast->next = p;
1830         gIco_Uxf_Api_Mng.EventQueLast = p;
1831     }
1832     else    {
1833         gIco_Uxf_Api_Mng.EventQue = p;
1834         gIco_Uxf_Api_Mng.EventQueLast = gIco_Uxf_Api_Mng.EventQue;
1835     }
1836 }
1837
1838 /*--------------------------------------------------------------------------*/
1839 /**
1840  * @brief   ico_uxf_mng_display: get display management table(internal function)
1841  *
1842  * @param[in]   display     display Id
1843  * @param[in]   create      create flag(1=create tabell if not exist/0=not create)
1844  * @return      display management table address
1845  * @retval      !=NULL      display management table address
1846  * @retval      ==NULL      display dose not exist(parameter 'create' only 0)
1847  */
1848 /*--------------------------------------------------------------------------*/
1849 Ico_Uxf_Mng_Display *
1850 ico_uxf_mng_display(const int display, const int create)
1851 {
1852     Ico_Uxf_Mng_Display *p;
1853     Ico_Uxf_Mng_Display *plast;
1854
1855     p = gIco_Uxf_Api_Mng.Mng_Display;
1856     plast = (Ico_Uxf_Mng_Display *)0;
1857     while (p)  {
1858         if (p->attr.display == display)    break;
1859         plast = p;
1860         p = p->next;
1861     }
1862
1863     if ((! p) && (create != 0))   {
1864
1865         p = (Ico_Uxf_Mng_Display *) malloc(sizeof(Ico_Uxf_Mng_Display));
1866         if (! p)   {
1867             uifw_error("ico_uxf_mng_display: NO Memory (malloc Error)");
1868             exit(1);
1869         }
1870         memset((char *)p, 0, sizeof(Ico_Uxf_Mng_Display));
1871         p->attr.display = display;
1872         if (plast) {
1873             plast->next = p;
1874         }
1875         else    {
1876             gIco_Uxf_Api_Mng.Mng_Display = p;
1877         }
1878     }
1879     return p;
1880 }
1881
1882 /*--------------------------------------------------------------------------*/
1883 /**
1884  * @brief   ico_uxf_mng_layer: get layer management table(internal function)
1885  *
1886  * @param[in]   display     display Id
1887  * @param[in]   layer       layer Id
1888  * @param[in]   create      create flag(1=create tabell if not exist/0=not create)
1889  * @return      layer management table address
1890  * @retval      !=NULL      layer management table address
1891  * @retval      ==NULL      layer dose not exist(parameter 'create' only 0)
1892  */
1893 /*--------------------------------------------------------------------------*/
1894 Ico_Uxf_Mng_Layer *
1895 ico_uxf_mng_layer(const int display, const int layer, const int create)
1896 {
1897     Ico_Uxf_Mng_Layer   *p;
1898     Ico_Uxf_Mng_Layer   *plast;
1899
1900     p = gIco_Uxf_Api_Mng.Mng_Layer;
1901     plast = (Ico_Uxf_Mng_Layer *)0;
1902     while (p)  {
1903         if ((p->attr.display == display) &&
1904             (p->attr.layer == layer))  break;
1905         plast = p;
1906         p = p->next;
1907     }
1908
1909     if ((! p) && (create != 0))   {
1910
1911         p = (Ico_Uxf_Mng_Layer *) malloc(sizeof(Ico_Uxf_Mng_Layer));
1912         if (! p)   {
1913             uifw_error("ico_uxf_mng_layer: NO Memory (malloc Error)");
1914             exit(1);
1915         }
1916         memset((char *)p, 0, sizeof(Ico_Uxf_Mng_Layer));
1917         p->attr.layer = layer;
1918         if (plast) {
1919             plast->next = p;
1920         }
1921         else    {
1922             gIco_Uxf_Api_Mng.Mng_Layer = p;
1923         }
1924     }
1925     return p;
1926 }
1927
1928 /*--------------------------------------------------------------------------*/
1929 /**
1930  * @brief   ico_uxf_mng_window: get window management table(internal function)
1931  *
1932  * @param[in]   window      window Id(same as ico_window_mgr surface Id)
1933  * @param[in]   create      create flag(1=create tabell if not exist/0=not create)
1934  * @return      window management table address
1935  * @retval      !=NULL      window management table address
1936  * @retval      ==NULL      window dose not exist(parameter 'create' only 0)
1937  */
1938 /*--------------------------------------------------------------------------*/
1939 Ico_Uxf_Mng_Window *
1940 ico_uxf_mng_window(const int window, const int create)
1941 {
1942     Ico_Uxf_Mng_Window  *p;
1943     Ico_Uxf_Mng_Window  *plast = (Ico_Uxf_Mng_Window *)0;
1944     int                 hash;
1945
1946     hash = ICO_UXF_MISC_HASHBYID(window);
1947     p = gIco_Uxf_Api_Mng.Hash_WindowId[hash];
1948     while (p)  {
1949         if (p->attr.window == window)  break;
1950         plast = p;
1951         p = p->nextidhash;
1952     }
1953
1954     if ((! p) && (create != 0))    {
1955
1956         p = (Ico_Uxf_Mng_Window *) malloc(sizeof(Ico_Uxf_Mng_Window));
1957         if (! p)   {
1958             uifw_error("ico_uxf_mng_window: NO Memory (malloc Error)");
1959             exit(1);
1960         }
1961         memset((char *)p, 0, sizeof(Ico_Uxf_Mng_Window));
1962         p->attr.window = window;
1963         if (plast) {
1964             plast->nextidhash = p;
1965         }
1966         else    {
1967             gIco_Uxf_Api_Mng.Hash_WindowId[hash] = p;
1968         }
1969         uifw_trace("ico_uxf_mng_window: Create New Table=%08x", (int)p);
1970     }
1971     return p;
1972 }
1973
1974 /*--------------------------------------------------------------------------*/
1975 /**
1976  * @brief   ico_uxf_mng_process: get process management table(internal function)
1977  *
1978  * @param[in]   process     application Id
1979  * @param[in]   create      create flag(1=create tabell if not exist/0=not create)
1980  * @return      process management table address
1981  * @retval      !=NULL      process management table address
1982  * @retval      ==NULL      process dose not exist(parameter 'create' only 0)
1983  */
1984 /*--------------------------------------------------------------------------*/
1985 Ico_Uxf_Mng_Process *
1986 ico_uxf_mng_process(const char *process, const int create)
1987 {
1988     Ico_Uxf_Mng_Process *p;
1989     Ico_Uxf_Mng_Process *plast = (Ico_Uxf_Mng_Process *)0;
1990     int                 hash;
1991
1992     hash = ICO_UXF_MISC_HASHBYNAME(process);
1993     p = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
1994     while (p)  {
1995         if(strncmp(p->attr.process, process, ICO_UXF_MAX_PROCESS_NAME) == 0) break;
1996         plast = p;
1997         p = p->nextidhash;
1998     }
1999
2000     if ((! p) && (create != 0))   {
2001
2002         p = (Ico_Uxf_Mng_Process *) malloc(sizeof(Ico_Uxf_Mng_Process));
2003         if (! p)   {
2004             uifw_error("ico_uxf_mng_process: NO Memory (malloc Error)");
2005             exit(1);
2006         }
2007         memset((char *)p, 0, sizeof(Ico_Uxf_Mng_Process));
2008         strncpy(p->attr.process, process, ICO_UXF_MAX_PROCESS_NAME);
2009         if (plast) {
2010             plast->nextidhash = p;
2011         }
2012         else    {
2013             gIco_Uxf_Api_Mng.Hash_ProcessId[hash] = p;
2014         }
2015     }
2016     return p;
2017 }
2018
2019 /*--------------------------------------------------------------------------*/
2020 /**
2021  * @brief   ico_uxf_update_procwin: update a process management table
2022  *
2023  * @param[in]   appid       application id
2024  * @param[in]   type        type(install/uninstall)
2025  * @param[in]   func        window create/destroy hook function
2026  * @return      none
2027  */
2028 /*--------------------------------------------------------------------------*/
2029 ICO_APF_API void
2030 ico_uxf_update_procwin(const char *appid, int type)
2031 {
2032     Ico_Uxf_Mng_Process     *prc = NULL;
2033     Ico_Uxf_Sys_Config      *sysconf;
2034     Ico_Uxf_App_Config      *appconf;
2035     Ico_Uxf_conf_appdisplay *appdsp;
2036     int                     dn, tn;
2037     Ico_Uxf_conf_application *app = NULL;
2038
2039     uifw_trace("ico_uxf_update_procwin: Enter(appid=%s, type=%d)", appid, type);
2040
2041     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
2042         uifw_trace("ico_uxf_callback_remove: Leave(not initialized)");
2043         return;
2044     }
2045     prc = ico_uxf_mng_process(appid, 0);
2046
2047     if (type == ICO_UXF_CONF_EVENT_INSTALL) {
2048         if (!prc) {
2049             sysconf = (Ico_Uxf_Sys_Config *)ico_uxf_getSysConfig();
2050             appconf = (Ico_Uxf_App_Config *)ico_uxf_getAppConfig();
2051             if ((sysconf == NULL) || (appconf == NULL)) {
2052                 uifw_trace("ico_uxf_update_procwin: Leave(cannot find tables)");
2053                 return;
2054             }
2055             for (dn = 0;  dn < appconf->applicationNum; dn++) {
2056                 app = &appconf->application[dn];
2057                 if (strncmp(app->appid, appid, ICO_UXF_MAX_PROCESS_NAME) == 0) {
2058                     uifw_trace("ico_uxf_update_procwin: Install(%s)", appid);
2059                     /* add process management table */
2060                     prc = ico_uxf_mng_process(appid, 1);
2061                     prc->attr.internalid = 0;
2062                     prc->attr.status = ICO_UXF_PROCSTATUS_STOP;
2063                     prc->attr.type = app->categoryId;
2064                     prc->attr.hostId = app->hostId;
2065                     prc->attr.myHost = (prc->attr.hostId == sysconf->misc.myhostId) ? 1 : 0;
2066
2067                     appdsp = &app->display[0];
2068                     prc->attr.mainwin.window = 0;
2069                     prc->attr.mainwin.windowtype = app->categoryId;
2070                     prc->attr.mainwin.display = appdsp->displayId;
2071                     prc->attr.mainwin.layer = appdsp->layerId;
2072                     prc->attr.mainwin.x =
2073                             sysconf->display[appdsp->displayId].zone[appdsp->zoneId].x;
2074                     prc->attr.mainwin.y =
2075                             sysconf->display[appdsp->displayId].zone[appdsp->zoneId].y;
2076                     prc->attr.mainwin.w =
2077                             sysconf->display[appdsp->displayId].zone[appdsp->zoneId].width;
2078                     prc->attr.mainwin.h =
2079                             sysconf->display[appdsp->displayId].zone[appdsp->zoneId].height;
2080                     prc->attr.mainwin.name[ICO_UXF_MAX_WIN_NAME] = 0;
2081                     prc->attr.numwindows = app->displayzoneNum;
2082                     /* get sub windows                          */
2083                     if (prc->attr.numwindows > 1)   {
2084                         prc->attr.subwin = malloc(sizeof(Ico_Uxf_ProcessWin) *
2085                                                   (prc->attr.numwindows - 1));
2086                         if (! prc->attr.subwin) {
2087                             uifw_trace("ico_uxf_update_procwin: Install(No memory)");
2088                             app->displayzoneNum = 1;
2089                             prc->attr.numwindows = 1;
2090                         }
2091                         else    {
2092                             memset(prc->attr.subwin, 0, (prc->attr.numwindows - 1));
2093                             for (tn = 0; tn < (prc->attr.numwindows - 1); tn++) {
2094                                 appdsp ++;
2095                                 prc->attr.subwin[tn].windowtype = prc->attr.mainwin.windowtype;
2096                                 prc->attr.subwin[tn].display = appdsp->displayId;
2097                                 prc->attr.subwin[tn].layer = appdsp->layerId;
2098                                 prc->attr.subwin[tn].x =
2099                                     sysconf->display[appdsp->displayId].zone[appdsp->zoneId].x;
2100                                 prc->attr.subwin[tn].y =
2101                                     sysconf->display[appdsp->displayId].zone[appdsp->zoneId].y;
2102                                 prc->attr.subwin[tn].w =
2103                                     sysconf->display[appdsp->displayId].zone[appdsp->zoneId].width;
2104                                 prc->attr.subwin[tn].h =
2105                                     sysconf->display[appdsp->displayId].zone[appdsp->zoneId].height;
2106                             }
2107                         }
2108                     }
2109                 }
2110             }
2111         }
2112     }
2113     else if (type == ICO_UXF_CONF_EVENT_UNINSTALL) {
2114         if (prc) {
2115             /* not delete process management table */
2116         }
2117     }
2118
2119     uifw_trace("ico_uxf_update_procwin: Leave");
2120
2121     return;
2122 }
2123
2124 /*--------------------------------------------------------------------------*/
2125 /**
2126  * @brief   ico_uxf_window_screen_size_get: get display physical size
2127  *
2128  * @param[out]  width       variable to receive the width of the display
2129  * @param[out]  height      variable to receive the height of the display
2130  * @return      none
2131  */
2132 /*--------------------------------------------------------------------------*/
2133 ICO_APF_API void
2134 ico_uxf_window_screen_size_get(int *width, int *height)
2135 {
2136     Ico_Uxf_Mng_Display *dsp;
2137     dsp = ico_uxf_mng_display(gIco_Uxf_Api_Mng.Mng_MyProcess->attr.mainwin.display, 0);
2138
2139     uifw_trace("ico_uxf_window_screen_size_get: Enter(dsp=%d(%d))",
2140                dsp, gIco_Uxf_Api_Mng.Mng_MyProcess->attr.mainwin.display);
2141
2142     if ((dsp != NULL) && (width != NULL) && (height != NULL)) {
2143         uifw_trace("ico_uxf_window_screen_size_get: %dx%d",
2144                    dsp->attr.pWidth, dsp->attr.pHeight);
2145         *width = dsp->attr.pWidth;
2146         *height = dsp->attr.pHeight;
2147     }
2148 }
2149
2150 /*--------------------------------------------------------------------------*/
2151 /**
2152  * @brief   ico_uxf_window_hook: set window create/destroy hook function
2153  *
2154  * @param[in]   func        window create/destroy hook function
2155  * @return      none
2156  */
2157 /*--------------------------------------------------------------------------*/
2158 ICO_APF_API void
2159 ico_uxf_window_hook(Ico_Uxf_Hook func)
2160 {
2161     uifw_trace("ico_uxf_window_hook: Window Control Hook=%08x", (int)func);
2162
2163     gIco_Uxf_Api_Mng.Hook_Window = func;
2164 }
2165