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