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