Updated package changelog.
[profile/ivi/ico-uxf-homescreen.git] / ico-app-framework / ico_uxf_conf_app.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(read apprication's configuration file)
11  *
12  * @date    Feb-28-2013
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <unistd.h>
20 #include <string.h>
21 #include <sys/time.h>
22 #include <sys/file.h>
23 #include <errno.h>
24 #include <ail.h>
25
26 #include "ico_apf_log.h"
27 #include "ico_apf_apimacro.h"
28 #include "ico_uxf_conf_common.h"
29
30 #define APP_CONF_AIL_NULL_STR   "(null)"
31
32 static Ico_Uxf_App_Config *readAilApplist(void);
33 static void Ico_Uxf_conf_remakeAppHash(void);
34
35 static Ico_Uxf_App_Config   *_ico_app_config = NULL;
36 static Ico_Uxf_Sys_Config   *sys_config = NULL;
37 static GKeyFile             *sappfile = NULL;
38
39
40 /*--------------------------------------------------------------------------*/
41 /**
42  * @brief   ico_uxf_getAppConfig: get application configurations
43  *
44  * @param       none
45  * @return      application configuration table
46  * @retval      !=NULL          success(application configuration table address)
47  * @retval      ==NULL          error(can not read configuration files)
48  */
49 /*--------------------------------------------------------------------------*/
50 ICO_APF_API const Ico_Uxf_App_Config *
51 ico_uxf_getAppConfig(void)
52 {
53     if (_ico_app_config) {
54         return _ico_app_config;
55     }
56     _ico_app_config = g_new0(Ico_Uxf_App_Config,1);
57     return readAilApplist();
58 }
59
60 /*--------------------------------------------------------------------------*/
61 /**
62  * @brief   infoAilpkg: callback function for configuration from AppCore(static function)
63  *
64  * @param[in]   appinfo         AppCore(AIL) application information
65  * @param[in]   data            user data(application index)
66  * @return      result
67  * @retval      AIL_CB_RET_CONTINUE success(continue next application)
68  * @retval      AIL_CB_RET_CANCEL   error(stop all application search)
69  */
70 /*--------------------------------------------------------------------------*/
71 static ail_cb_ret_e
72 infoAilpkg(const ail_appinfo_h appinfo, void *data)
73 {
74     int     num = (int)data;
75     char    *package;
76     char    *icon;
77     char    *name;
78     char    *category;
79     char    *type;
80     char    *exec;
81     GError  *error;
82     char    *app_category;
83     char    add_category[256];
84     int     i;
85     bool    bval;
86     struct stat buff;
87     Ico_Uxf_conf_application *apptbl;
88
89     /* get package name for appid */
90     ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
91     if (strcmp(package, APP_CONF_AIL_NULL_STR) == 0) {
92         package = NULL;
93     }
94     /* get icon path */
95     ail_appinfo_get_str(appinfo, AIL_PROP_ICON_STR, &icon);
96     if (strcmp(icon, APP_CONF_AIL_NULL_STR) == 0) {
97         icon = NULL;
98     }
99     else if (icon != NULL) {
100         /* file check */
101         memset(&buff, 0, sizeof(buff));
102         if (stat(icon, &buff) == 0) {
103             if (S_ISDIR(buff.st_mode)) {
104                 /* is directory */
105                 icon = NULL;
106             }
107         }
108         else {
109             /* is not exist */
110             icon = NULL;
111         }
112     }
113     /* get name */
114     ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &name);
115     if (strcmp(name, APP_CONF_AIL_NULL_STR) == 0) {
116         name = NULL;
117     }
118
119     /* get default category of this application */
120     add_category[0] = 0;
121     error = NULL;
122     app_category = g_key_file_get_string(sappfile, "app-attributes", package, &error);
123     if (error != NULL)  {
124         g_clear_error(&error);
125         error = NULL;
126         app_category = g_key_file_get_string(sappfile, "app-attributes", name, &error);
127     }
128     if (error != NULL)  {
129         g_clear_error(&error);
130         apfw_trace("infoAilpkg: %s(%s) dose not has app-attributes", package, name);
131     }
132     else    {
133         apfw_trace("infoAilpkg: %s(%s) has app-category=%s", package, name, app_category);
134         strncpy(add_category, app_category, sizeof(add_category)-2);
135         add_category[sizeof(add_category)-2] = 0;
136         i = strlen(add_category);
137         if (i > 0)  {
138             if (add_category[i-1] != ';')   {
139                 strcpy(&add_category[i], ";");
140             }
141         }
142     }
143     g_clear_error(&error);
144
145     /* get category */
146     ail_appinfo_get_str(appinfo, AIL_PROP_CATEGORIES_STR, &category);
147     if (strcmp(category, APP_CONF_AIL_NULL_STR) != 0) {
148         apfw_trace("infoAilpkg: %s + %s", add_category, category);
149         i = strlen(add_category);
150         strncpy(&add_category[i], category, sizeof(add_category)-i-1);
151         add_category[sizeof(add_category)-i-1] = 0;
152     }
153     if (add_category[0])    {
154         category = add_category;
155     }
156     else    {
157         category = NULL;
158     }
159
160     /* get type */
161     ail_appinfo_get_str(appinfo, AIL_PROP_TYPE_STR, &type);
162     if (strcmp(type, APP_CONF_AIL_NULL_STR) == 0) {
163         type = NULL;
164     }
165     /* get exec */
166     ail_appinfo_get_str(appinfo, AIL_PROP_EXEC_STR, &exec);
167     if (strcmp(exec, APP_CONF_AIL_NULL_STR) == 0) {
168         exec = NULL;
169     }
170
171     if ((package != NULL) && (*package != 0))   {
172         apptbl = &_ico_app_config->application[_ico_app_config->applicationNum];
173         apptbl->appid = strdup(package);
174         if (icon)   {
175             apptbl->icon_key_name = strdup(icon);
176         }
177         else    {
178             apptbl->icon_key_name = strdup("\0");
179         }
180         if ((name != NULL) && (*name != 0)) {
181             apptbl->name = strdup(name);
182         }
183         else    {
184             apptbl->name = strdup(package);
185         }
186
187         /* set default values       */
188         apptbl->hostId = sys_config->misc.default_hostId;
189         apptbl->kindId = sys_config->misc.default_kindId;
190         apptbl->categoryId = sys_config->misc.default_categoryId;
191
192         /* get NoDisplay    */
193         if ((icon != NULL) && (*icon != 0)) {
194             bval = false;
195             ail_appinfo_get_bool(appinfo, AIL_PROP_NODISPLAY_BOOL, &bval);
196             apptbl->noicon = (int)bval;
197         }
198         else    {
199             apfw_trace("infoAilpkg: %s(%s) has no icon", package, name);
200             apptbl->noicon = 1;
201         }
202
203         /* analize categorys for extended attributes    */
204         if (category)   {
205             int     i, j, k, m, n;
206             int     found;
207             int     dispidx = sys_config->misc.default_displayId;;
208             int     soundidx = sys_config->misc.default_soundId;;
209             int     inputidx = sys_config->misc.default_inputdevId;
210             Ico_Uxf_conf_display    *display;
211             Ico_Uxf_conf_sound      *sound;
212             char    work[64];
213
214             apfw_trace("Ail.%d category=%s", _ico_app_config->applicationNum, category);
215
216             j = 0;
217             for (i = 0;; i++)   {
218                 if ((category[i] == 0) || (category[i] == ';')) {
219                     k = i - j;
220                     if (k >= ((int)sizeof(work)-1)) k = sizeof(work)-1;
221                     memcpy(work, &category[j], k);
222                     work[k] = 0;
223                     found = 0;
224
225                     /* find running host        */
226                     if (strncasecmp(work, "run=", 4) == 0)  {
227                         found = 4;
228                     }
229                     for (k = 0; k < sys_config->hostNum; k++)  {
230                         if (strcasecmp(&work[found], sys_config->host[k].name) == 0)   {
231                             apptbl->hostId = sys_config->host[k].id;
232                             found = 1;
233                             break;
234                         }
235                     }
236                     if (found > 1)  {
237                         apfw_error("infoAilpkg: [%s] unknown running host", work);
238                     }
239                     /* find kind                */
240                     if (found == 0) {
241                         if (strncasecmp(work, "kind=", 5) == 0) {
242                             found = 5;
243                         }
244                         for (k = 0; k < sys_config->kindNum; k++)  {
245                             if (strcasecmp(&work[found],
246                                            sys_config->kind[k].name) == 0)   {
247                                 apptbl->kindId = sys_config->kind[k].id;
248                                 found = 1;
249                                 break;
250                             }
251                         }
252                     }
253                     if (found > 1)  {
254                         apfw_error("infoAilpkg: [%s] unknown kind", work);
255                     }
256                     /* find category            */
257                     if (found == 0) {
258                         if (strncasecmp(work, "category=", 9) == 0) {
259                             found = 9;
260                         }
261                         for (k = 0; k < sys_config->categoryNum; k++)  {
262                             if (strcasecmp(&work[found],
263                                            sys_config->category[k].name) == 0)   {
264                                 apptbl->categoryId = sys_config->category[k].id;
265                                 found = 1;
266                                 break;
267                             }
268                         }
269                     }
270                     if (found > 1)  {
271                         apfw_error("infoAilpkg: [%s] unknown category", work);
272                     }
273                     /* find display             */
274                     if ((found == 0) &&
275                         (strncasecmp(work, "display", 7) == 0))   {
276                         if (work[7] == '=') {
277                             dispidx = 0;
278                             found = 8;
279                         }
280                         else if ((work[7] == '.') && (work[9] == '='))  {
281                             dispidx = work[8] - '0';
282                             found = 10;
283                             if ((dispidx < 0) || (dispidx >= ICO_UXF_APPDISPLAY_MAX))   {
284                                 apfw_error("infoAilpkg: [%s] unknown display number", work);
285                                 dispidx = 0;
286                                 break;
287                             }
288                         }
289                         else    {
290                             apfw_error("infoAilpkg: [%s] unknown display number", work);
291                             dispidx = 0;
292                             break;
293                         }
294                         if (apptbl->displayzoneNum <= dispidx)  {
295                             apptbl->display[dispidx].displayId
296                                     = sys_config->misc.default_displayId;
297                             apptbl->display[dispidx].layerId
298                                     = sys_config->misc.default_layerId;
299                             apptbl->display[dispidx].zoneId
300                                     = sys_config->misc.default_dispzoneId;
301                         }
302                         for (k = 0; k < sys_config->displayNum; k++)   {
303                             if (strcasecmp(&work[found],
304                                            sys_config->display[k].name) == 0)    {
305                                 apptbl->display[dispidx].displayId
306                                         = sys_config->display[k].id;
307                                 if (apptbl->displayzoneNum <= dispidx)  {
308                                     apptbl->displayzoneNum = dispidx + 1;
309                                 }
310                                 found = 1;
311                                 break;
312                             }
313                         }
314                     }
315                     if (found > 1)  {
316                         apfw_error("infoAilpkg: [%s] unknown display", work);
317                     }
318                     /* find display layer       */
319                     if ((found == 0) &&
320                         (strncasecmp(work, "layer", 5) == 0)) {
321                         if (work[5] == '=') {
322                             dispidx = 0;
323                             found = 6;
324                         }
325                         else if ((work[5] == '.') && (work[7] == '='))  {
326                             dispidx = work[6] - '0';
327                             found = 8;
328                             if ((dispidx < 0) || (dispidx >= ICO_UXF_APPDISPLAY_MAX))   {
329                                 apfw_error("infoAilpkg: [%s] unknown display number", work);
330                                 dispidx = 0;
331                                 break;
332                             }
333                         }
334                         else    {
335                             apfw_error("infoAilpkg: [%s] unknown display number", work);
336                             dispidx = 0;
337                             break;
338                         }
339                         if (apptbl->displayzoneNum <= dispidx)  {
340                             apptbl->display[dispidx].displayId
341                                     = sys_config->misc.default_displayId;
342                             apptbl->display[dispidx].layerId
343                                     = sys_config->misc.default_layerId;
344                             apptbl->display[dispidx].zoneId
345                                     = sys_config->misc.default_dispzoneId;
346                         }
347                         display = &sys_config->display[apptbl->display[dispidx].displayId];
348
349                         for (k = 0; k < display->layerNum; k++) {
350                             if (strcasecmp(&work[found], display->layer[k].name) == 0)  {
351                                 apptbl->display[dispidx].layerId = display->layer[k].id;
352                                 if (apptbl->displayzoneNum <= dispidx)  {
353                                     apptbl->displayzoneNum = dispidx + 1;
354                                 }
355                                 found = 1;
356                                 break;
357                             }
358                         }
359                     }
360                     if (found > 1)  {
361                         apfw_error("infoAilpkg: [%s] unknown layer", work);
362                     }
363                     /* find display zone        */
364                     if ((found == 0) &&
365                         (strncasecmp(work, "dispzone", 8) == 0))  {
366                         if (work[8] == '=') {
367                             dispidx = 0;
368                             found = 9;
369                         }
370                         else if ((work[8] == '.') && (work[10] == '=')) {
371                             dispidx = work[9] - '0';
372                             found = 11;
373                             if ((dispidx < 0) || (dispidx >= ICO_UXF_APPDISPLAY_MAX))   {
374                                 apfw_error("infoAilpkg: [%s] unknown display number", work);
375                                 dispidx = 0;
376                                 break;
377                             }
378                         }
379                         else    {
380                             apfw_error("infoAilpkg: [%s] unknown display number", work);
381                             dispidx = 0;
382                             break;
383                         }
384                         if (apptbl->displayzoneNum <= dispidx)  {
385                             apptbl->display[dispidx].displayId
386                                     = sys_config->misc.default_displayId;
387                             apptbl->display[dispidx].layerId
388                                     = sys_config->misc.default_layerId;
389                             apptbl->display[dispidx].zoneId
390                                     = sys_config->misc.default_dispzoneId;
391                         }
392                         display = &sys_config->display[apptbl->display[dispidx].displayId];
393
394                         for (k = 0; k < display->zoneNum; k++)  {
395                             if (strcasecmp(&work[found], display->zone[k].name) == 0)   {
396                                 apptbl->display[dispidx].zoneId = display->zone[k].id;
397                                 if (apptbl->displayzoneNum <= dispidx)  {
398                                     apptbl->displayzoneNum = dispidx + 1;
399                                 }
400                                 found = 1;
401                                 break;
402                             }
403                         }
404                     }
405                     if (found > 1)  {
406                         apfw_error("infoAilpkg: [%s] unknown display zone", work);
407                     }
408
409                     /* find sound zone      */
410                     if ((found == 0) &&
411                         (strncasecmp(work, "soundzone", 9) == 0)) {
412                         if (work[9] == '=') {
413                             soundidx = 0;
414                             found = 10;
415                         }
416                         else if ((work[9] == '.') && (work[11] == '=')) {
417                             soundidx = work[10] - '0';
418                             found = 12;
419                             if ((soundidx < 0) || (soundidx >= ICO_UXF_APPSOUND_MAX))   {
420                                 apfw_error("infoAilpkg: [%s] unknown sound number", work);
421                                 soundidx = 0;
422                                 break;
423                             }
424                         }
425                         else    {
426                             apfw_error("infoAilpkg: [%s] unknown sound number", work);
427                             soundidx = 0;
428                             break;
429                         }
430                         if (apptbl->soundzoneNum <= soundidx)   {
431                             apptbl->sound[soundidx].soundId
432                                     = sys_config->misc.default_soundId;
433                             apptbl->sound[soundidx].zoneId
434                                     = sys_config->misc.default_soundzoneId;
435                         }
436                         sound = &sys_config->sound[apptbl->sound[soundidx].soundId];
437
438                         for (k = 0; k < sound->zoneNum; k++)    {
439                             if (strcasecmp(&work[found], sound->zone[k].name) == 0) {
440                                 apptbl->sound[soundidx].zoneId = sound->zone[k].id;
441                                 if (apptbl->soundzoneNum <= soundidx)   {
442                                     apptbl->soundzoneNum = soundidx + 1;
443                                 }
444                                 found = 1;
445                                 break;
446                             }
447                         }
448                     }
449                     if (found > 1)  {
450                         apfw_error("infoAilpkg: [%s] unknown sound zone", work);
451                     }
452
453                     /* find sound           */
454                     if ((found == 0) &&
455                         (strncasecmp(work, "sound", 5) == 0)) {
456                         if (work[5] == '=') {
457                             soundidx = 0;
458                             found = 5;
459                         }
460                         else if ((work[5] == '.') && (work[7] == '='))  {
461                             soundidx = work[6] - '0';
462                             found = 8;
463                             if ((soundidx < 0) || (soundidx >= ICO_UXF_APPSOUND_MAX))   {
464                                 apfw_error("infoAilpkg: [%s] unknown sound number", work);
465                                 soundidx = 0;
466                                 break;
467                             }
468                         }
469                         else    {
470                             apfw_error("infoAilpkg: [%s] unknown sound number", work);
471                             soundidx = 0;
472                             break;
473                         }
474                         if (apptbl->soundzoneNum <= soundidx)   {
475                             apptbl->sound[soundidx].soundId
476                                     = sys_config->misc.default_soundId;
477                             apptbl->sound[soundidx].zoneId
478                                     = sys_config->misc.default_soundzoneId;
479                         }
480                         for (k = 0; k < sys_config->soundNum; k++) {
481                             if (strcasecmp(&work[found], sys_config->sound[k].name) == 0)  {
482                                 apptbl->sound[soundidx].soundId = sys_config->sound[k].id;
483                                 if (apptbl->soundzoneNum <= soundidx)   {
484                                     apptbl->soundzoneNum = soundidx + 1;
485                                 }
486                                 found = 1;
487                                 break;
488                             }
489                         }
490                     }
491                     if (found > 1)  {
492                         apfw_error("infoAilpkg: [%s] unknown sound", work);
493                     }
494
495                     /* find input device    */
496                     if ((found == 0) &&
497                         (strncasecmp(work, "input", 5) == 0)) {
498                         if (work[5] == '=') {
499                             inputidx = 0;
500                             found = 6;
501                         }
502                         else if ((work[5] == '.') && (work[7] == '='))  {
503                             inputidx = work[6] - '0';
504                             if ((inputidx < 0) || (inputidx >= ICO_UXF_APPINPUT_MAX))   {
505                                 apfw_error("infoAilpkg: [%s] unknown input number", work);
506                                 found = 1;
507                                 break;
508                             }
509                             found = 8;
510                         }
511                         else    {
512                             apfw_error("infoAilpkg: [%s] unknown input number", work);
513                             break;
514                         }
515                         if (apptbl->inputdevNum <= inputidx)    {
516                             apptbl->input[inputidx].inputdevId
517                                     = sys_config->misc.default_inputdevId;
518                         }
519                         for (k = 0; k < sys_config->inputdevNum; k++)  {
520                             m = strlen(sys_config->inputdev[k].name);
521                             if (strncasecmp(&work[found],
522                                             sys_config->inputdev[k].name, m) == 0)  {
523                                 if (work[found+m] != '.')   {
524                                     apfw_error("infoAilpkg: [%s] unknown input sw", work);
525                                     break;
526                                 }
527                                 apptbl->input[inputidx].inputdevId
528                                         = sys_config->inputdev[k].id;
529                                 m += (found + 1);
530                                 for (n = 0; n < sys_config->inputdev[k].inputswNum; n++)   {
531                                     if (strcasecmp(&work[m],
532                                                    sys_config->inputdev[k].inputsw[n].name)
533                                             == 9) {
534                                         apptbl->input[inputidx].inputswId = n;
535                                         break;
536                                     }
537                                 }
538                                 if (n < sys_config->inputdev[k].inputswNum)    {
539                                     if (apptbl->inputdevNum <= inputidx)   {
540                                         apptbl->inputdevNum = inputidx + 1;
541                                     }
542                                 }
543                                 else    {
544                                     apfw_error("infoAilpkg: [%s] unknown input sw", work);
545                                 }
546                                 found = 1;
547                                 break;
548                             }
549                         }
550                         if (k >= sys_config->inputdevNum)  {
551                             apfw_error("infoAilpkg: [%s] unknown input device", work);
552                             found = 1;
553                             break;
554                         }
555                     }
556                     if (found > 1)  {
557                         apfw_error("infoAilpkg: [%s] unknown input", work);
558                     }
559
560                     /* start mode               */
561                     if ((found == 0) && (work[0] != 0)) {
562                         if (strcasecmp(work, "auto") == 0)  {
563                             apptbl->autostart = 1;
564                         }
565                         else if (strcasecmp(work, "noauto") == 0)   {
566                             apptbl->autostart = 0;
567                         }
568                         else    {
569                             apfw_error("infoAilpkg: [%s] unknown key", work);
570                         }
571                     }
572                     if (category[i] == 0)   break;
573                     j = i + 1;
574                 }
575             }
576         }
577         apptbl->exec = strdup(exec);
578         apptbl->type = strdup(type);
579         if (apptbl->displayzoneNum == 0)    {
580             apptbl->displayzoneNum = 1;
581             apptbl->display[0].displayId = sys_config->misc.default_displayId;
582             apptbl->display[0].layerId = sys_config->misc.default_layerId;
583             apptbl->display[0].zoneId = sys_config->misc.default_dispzoneId;
584         }
585         if (apptbl->soundzoneNum == 0)  {
586             apptbl->soundzoneNum = 1;
587             apptbl->sound[0].soundId = sys_config->misc.default_soundId;
588             apptbl->sound[0].zoneId = sys_config->misc.default_soundzoneId;
589         }
590         apfw_trace("Ail.%d: appid=%s name=%s exec=%s type=%s",
591                    _ico_app_config->applicationNum, apptbl->appid, apptbl->name,
592                    apptbl->exec, apptbl->type);
593         apfw_trace("Ail.%d: categ=%d kind=%d disp=%d layer=%d zone=%d "
594                    "sound=%d zone=%d auto=%d noicon=%d",
595                    _ico_app_config->applicationNum, apptbl->categoryId, apptbl->kindId,
596                    apptbl->display[0].displayId, apptbl->display[0].layerId,
597                    apptbl->display[0].zoneId, apptbl->sound[0].soundId,
598                    apptbl->sound[0].zoneId, apptbl->autostart, apptbl->noicon);
599         _ico_app_config->applicationNum++;
600     }
601     else    {
602     }
603
604     if (_ico_app_config->applicationNum > num)
605         return AIL_CB_RET_CANCEL;
606
607     return AIL_CB_RET_CONTINUE;
608 }
609
610 /*--------------------------------------------------------------------------*/
611 /**
612  * @brief   readAilApplist: get all application configuration from AppCore(static function)
613  *
614  * @param       none
615  * @return      application configuration table
616  * @retval      !=NULL          success(application configuration table address)
617  * @retval      ==NULL          error(can not read configuration files)
618  */
619 /*--------------------------------------------------------------------------*/
620 static Ico_Uxf_App_Config *
621 readAilApplist(void)
622 {
623     int     ret, num, wnum;
624     ail_filter_h filter;
625     GError  *error = NULL;
626
627     /* get system configuration */
628     sys_config = (Ico_Uxf_Sys_Config *)ico_uxf_getSysConfig();
629     if (! sys_config)   {
630         apfw_error("readAilApplist: can not read system configuration");
631         return NULL;
632     }
633
634     /* read system configuration file for application default category  */
635     sappfile = g_key_file_new();
636
637     GString* filepath = g_string_new("xx");
638     g_string_printf(filepath, "%s/%s", sys_config->misc.confdir, ICO_UXF_CONFIG_APPATTR);
639
640     if (! g_key_file_load_from_file(sappfile, filepath->str,
641                                     G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
642                                     &error)) {
643         apfw_error("readAilApplist: %s %s", (char *)filepath->str, error->message);
644         g_key_file_free(sappfile);
645         sappfile = NULL;
646     }
647     g_string_free(filepath, TRUE);
648
649     /* count packages */
650     ret = ail_filter_count_appinfo(NULL, &num);
651     if (ret != AIL_ERROR_OK) {
652         if( sappfile)   {
653             g_key_file_free(sappfile);
654             sappfile = NULL;
655         }
656         return NULL;
657     }
658     apfw_trace("readAilApplist: number of off AIL package = %d", num);
659
660     ail_filter_new(&filter);
661     ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "menu");
662     ail_filter_count_appinfo(filter, &num);
663     apfw_trace("readAilApplist: number of menu AIL package = %d", num);
664     ail_filter_destroy(filter);
665
666     ail_filter_new(&filter);
667     ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
668     ail_filter_count_appinfo(filter, &wnum);
669     apfw_trace("readAilApplist: number of Application AIL package = %d", wnum);
670     ail_filter_destroy(filter);
671     num += wnum;
672
673     _ico_app_config->application = g_new0(Ico_Uxf_conf_application, num);
674
675     ail_filter_new(&filter);
676     ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "menu");
677     ail_filter_list_appinfo_foreach(filter, infoAilpkg, (void *)num);
678     ail_filter_destroy(filter);
679
680     ail_filter_new(&filter);
681     ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
682     ail_filter_list_appinfo_foreach(filter, infoAilpkg, (void *)num);
683     ail_filter_destroy(filter);
684
685     /* create Hash Table                    */
686     Ico_Uxf_conf_remakeAppHash();
687
688     if( sappfile)   {
689         g_key_file_free(sappfile);
690     }
691
692     return _ico_app_config;
693 }
694
695 /*--------------------------------------------------------------------------*/
696 /**
697  * @brief   ico_uxf_closeAppConfig: close application configuration table
698  *
699  * @param       none
700  * @return      none
701  */
702 /*--------------------------------------------------------------------------*/
703 ICO_APF_API void
704 ico_uxf_closeAppConfig(void)
705 {
706     if(_ico_app_config != NULL){
707         g_free(_ico_app_config->application);
708         g_free(_ico_app_config);
709         _ico_app_config = NULL;
710     }
711 }
712
713 /*--------------------------------------------------------------------------*/
714 /**
715  * @brief   Ico_Uxf_conf_remakeAppHash: make application hash table(static function)
716  *
717  * @param       none
718  * @return      none
719  */
720 /*--------------------------------------------------------------------------*/
721 static void
722 Ico_Uxf_conf_remakeAppHash(void)
723 {
724     int         i;
725     int         hash;
726     Ico_Uxf_conf_application    *app;
727
728     memset(_ico_app_config->hashnametable, 0, sizeof(_ico_app_config->hashnametable));
729
730     for (i = 0; i < _ico_app_config->applicationNum; i++)  {
731
732         _ico_app_config->application[i].nextidhash = NULL;
733         hash = ICO_UXF_MISC_HASHBYID(i);
734         app = _ico_app_config->hashidtable[hash];
735         if (! app) {
736             _ico_app_config->hashidtable[hash] = &_ico_app_config->application[i];
737         }
738         else    {
739             while (app->nextidhash)    {
740                 app = app->nextidhash;
741             }
742             app->nextidhash = &_ico_app_config->application[i];
743         }
744
745         _ico_app_config->application[i].nextnamehash = NULL;
746         hash = ICO_UXF_MISC_HASHBYNAME(_ico_app_config->application[i].appid);
747         app = _ico_app_config->hashnametable[hash];
748         if (! app) {
749             _ico_app_config->hashnametable[hash] = &_ico_app_config->application[i];
750         }
751         else    {
752             while (app->nextnamehash)  {
753                 app = app->nextnamehash;
754             }
755             app->nextnamehash = &_ico_app_config->application[i];
756         }
757     }
758 }
759
760 /*--------------------------------------------------------------------------*/
761 /**
762  * @brief   ico_uxf_getAppByAppid: get application configuration by application Id
763  *
764  * @param[in]   appid       application Id
765  * @return      application configuration table
766  * @retval      !=NULL          success(application configuration table address)
767  * @retval      ==NULL          error(application dose not exist)
768  */
769 /*--------------------------------------------------------------------------*/
770 ICO_APF_API const Ico_Uxf_conf_application *
771 ico_uxf_getAppByAppid(const char *appid)
772 {
773     Ico_Uxf_conf_application    *app;
774
775     if (!_ico_app_config)  {
776         (void)ico_uxf_getAppConfig();
777     }
778     app = _ico_app_config->hashnametable[ICO_UXF_MISC_HASHBYNAME(appid)];
779
780     while (app)    {
781         if (strcasecmp(app->appid, appid) == 0)   break;
782         app = app->nextnamehash;
783     }
784     if (! app)  {
785         apfw_warn("ico_uxf_getAppByAppid: appid(%s) dose not exist", appid);
786     }
787     return app;
788 }
789
790 /*--------------------------------------------------------------------------*/
791 /**
792  * @brief   ico_uxf_getAppByName: get application configuration by application name
793  *
794  * @param[in]   name            application name
795  * @return      application configuration table
796  * @retval      !=NULL          success(application configuration table address)
797  * @retval      ==NULL          error(application dose not exist)
798  */
799 /*--------------------------------------------------------------------------*/
800 ICO_APF_API const Ico_Uxf_conf_application *
801 ico_uxf_getAppByName(const char *name)
802 {
803     int     i;
804     Ico_Uxf_conf_application    *app = NULL;
805
806     if (!_ico_app_config)  {
807         (void)ico_uxf_getAppConfig();
808     }
809
810     for (i = 0; i < _ico_app_config->applicationNum; i++)   {
811         if (strcasecmp(_ico_app_config->application[i].name, name) == 0)    {
812             app = &_ico_app_config->application[i];
813             break;
814         }
815     }
816     if (! app)  {
817         apfw_warn("ico_uxf_getAppByName: name(%s) dose not exist", name);
818     }
819     return app;
820 }
821
822 /*--------------------------------------------------------------------------*/
823 /**
824  * @brief   ico_uxf_getAppDisplay: get application display
825  *
826  * @param[in]   app         application configuration table
827  * @param[in]   idx         display zone index
828  * @param[out]  x           zone X coodinate
829  * @param[out]  y           zone Y coodinate
830  * @param[out]  width       zone width
831  * @param[out]  height      zone height
832  * @return      result
833  * @retval      ICO_UXF_EOK     succes
834  * @retval      ICO_UXF_EINVAL  error(illegal idx)
835  * @retval      ICO_UXF_ENOSYS  error(can not read configuration files)
836  */
837 /*--------------------------------------------------------------------------*/
838 ICO_APF_API int
839 ico_uxf_getAppDisplay(const Ico_Uxf_conf_application *app, const int idx,
840                       int *x, int *y, int *width, int *height)
841 {
842     Ico_Uxf_conf_display_zone *zone;
843
844     if (! sys_config)  {
845         return ICO_UXF_ENOSYS;
846     }
847     if ((! app) || (idx < 0) || (idx >= app->displayzoneNum))  {
848         return ICO_UXF_EINVAL;
849     }
850
851     zone = &sys_config->display[app->display[idx].displayId].zone[app->display[idx].zoneId];
852
853     if (x)      *x = zone->x;
854     if (y)      *y = zone->y;
855     if (width)  *width = zone->width;
856     if (height) *height = zone->height;
857
858     return 0;
859 }
860