Fixed some RPMlint errors - group name, duplicate files, etc.
[profile/ivi/ico-uxf-homescreen.git] / ico-app-framework / ico_uxf_conf_sys.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 configuration file in all system)
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
25 #include "ico_apf_log.h"
26 #include "ico_apf_apimacro.h"
27 #include "ico_uxf_conf_common.h"
28
29 static Ico_Uxf_Sys_Config   *reloadSysConfig(void);
30
31 static Ico_Uxf_Sys_Config   *_ico_sys_config = NULL;
32
33
34 /*--------------------------------------------------------------------------*/
35 /**
36  * @brief   ico_uxf_getSysConfig: get system configurations
37  *
38  * @param       none
39  * @return      system configuration table
40  * @retval      != NULL         success(system configuration table address)
41  * @retval      == NULL         error(can not read configuration file)
42  */
43 /*--------------------------------------------------------------------------*/
44 ICO_APF_API const Ico_Uxf_Sys_Config *
45 ico_uxf_getSysConfig(void)
46 {
47     if (_ico_sys_config) {
48         return _ico_sys_config;
49     }
50     _ico_sys_config = g_new0(Ico_Uxf_Sys_Config,1);
51     return reloadSysConfig();
52 }
53
54 /*--------------------------------------------------------------------------*/
55 /**
56  * @brief   ico_uxf_ifGetSysConfig: get system configurations
57  *
58  * @param       none
59  * @return      system configuration table
60  * @retval      != NULL         success(system configuration table address)
61  * @retval      == NULL         error(the configuration file is not yet read)
62  */
63 /*--------------------------------------------------------------------------*/
64 ICO_APF_API const Ico_Uxf_Sys_Config *
65 ico_uxf_ifGetSysConfig(void)
66 {
67     return _ico_sys_config;
68 }
69
70 /*--------------------------------------------------------------------------*/
71 /**
72  * @brief   pars_dispposition: calculate an expression about display size(static function)
73  *
74  * @param[in]   exp             expression
75  * @param[in]   display         display configuration table
76  * @return      calculation result
77  */
78 /*--------------------------------------------------------------------------*/
79 static int
80 pars_dispposition(const char *exp, Ico_Uxf_conf_display *display)
81 {
82     int     val = 0;
83     int     wval;
84     int     i, j, sign;
85     char    word[32];
86
87     j = 0;
88     sign = 0;
89     for (i = 0; ; i++)  {
90         if (exp[i] == ' ')  continue;
91         if ((exp[i] == 0) || (exp[i] == '+') || (exp[i] == '-') ||
92             (exp[i] == '*') || (exp[i] == '-') || (exp[i] == '/'))  {
93             if (j > 0)  {
94                 word[j] = 0;
95                 if ((strcasecmp(word, "dispw") == 0) ||
96                     (strcasecmp(word, "width") == 0))   {
97                     wval = display->width;
98                 }
99                 else if ((strcasecmp(word, "disph") == 0) ||
100                          (strcasecmp(word, "heigh") == 0))  {
101                     wval = display->height;
102                 }
103                 else    {
104                     wval = strtol(word, (char **)0, 0);
105                 }
106                 j = 0;
107                 if (sign >= 10) {
108                     wval = 0 - wval;
109                 }
110                 switch (sign % 10)  {
111                 case 0:                     /* assign       */
112                     val = wval;
113                     break;
114                 case 1:                     /* '+'          */
115                     val += wval;
116                     break;
117                 case 2:                     /* '-'          */
118                     val -= wval;
119                     break;
120                 case 3:                     /* '*'          */
121                     val *= wval;
122                     break;
123                 case 4:                     /* '/'          */
124                     val /= wval;
125                     break;
126                 default:
127                     break;
128                 }
129                 sign = 0;
130                 if (exp[i] == '+')      sign = 1;
131                 else if (exp[i] == '-') sign = 2;
132                 else if (exp[i] == '*') sign = 3;
133                 else if (exp[i] == '/') sign = 4;
134                 else                    sign = 0;
135             }
136             else    {
137                 if ((sign > 0) && (exp[i] == '-'))  {
138                     sign += 10;
139                 }
140                 else    {
141                     if (exp[i] == '+')      sign = 1;
142                     else if (exp[i] == '-') sign = 2;
143                     else if (exp[i] == '*') sign = 3;
144                     else if (exp[i] == '/') sign = 4;
145                     else                    sign = 0;
146                 }
147             }
148             if (exp[i] == 0)    break;
149         }
150         else    {
151             if (j < ((int)sizeof(word)-1))  {
152                 word[j++] = exp[i];
153             }
154         }
155     }
156     return val;
157 }
158
159 /*--------------------------------------------------------------------------*/
160 /**
161  * @brief   reloadSysConfig: load system configuration file(static function)
162  *
163  * @param       none
164  * @return      system configuration table
165  * @retval      != NULL         success(system configuration table address)
166  * @retval      == NULL         error(can not read configuration file)
167  */
168 /*--------------------------------------------------------------------------*/
169 static Ico_Uxf_Sys_Config *
170 reloadSysConfig(void)
171 {
172     GKeyFile *keyfile;
173     GKeyFileFlags flags;
174     GError *error = NULL;
175     gsize length;
176     int i, j, k;
177     int zoneidx;
178     GList*  idlist;
179     char*   dirp;
180     char*   strp;
181
182     apfw_trace("reloadSysConfig: Enter");
183
184     /* decide top directory in all configurations       */
185     dirp = getenv(ICO_UXF_TOP_ENV);
186     if (! dirp)    {
187         dirp = ICO_UXF_TOP_TOPDIR;
188     }
189     strncpy(_ico_sys_config->misc.topdir, dirp, ICO_UXF_CONF_DIR_MAX);
190
191     /* decide top directory in configuration file's     */
192     dirp = getenv(ICO_UXF_CONFIG_ENV);
193     if (dirp)  {
194         strncpy(_ico_sys_config->misc.confdir, dirp, ICO_UXF_CONF_DIR_MAX);
195     }
196     else    {
197         snprintf(_ico_sys_config->misc.confdir, ICO_UXF_CONF_DIR_MAX,
198                  "%s/%s", _ico_sys_config->misc.topdir, ICO_UXF_CONFIG_DIR);
199         dirp = _ico_sys_config->misc.confdir;
200     }
201
202     /* A system-wide definition         */
203     keyfile = g_key_file_new();
204     flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
205
206     GString* filepath = g_string_new("xx");
207     g_string_printf(filepath, "%s/%s", dirp, ICO_UXF_CONFIG_SYSTEM);
208
209     if (!g_key_file_load_from_file(keyfile, filepath->str, flags, &error)) {
210         fprintf(stderr, "%s: %s\n", (char *)filepath->str, error->message);
211         g_string_free(filepath, TRUE);
212         return NULL;
213     }
214     g_string_free(filepath, TRUE);
215
216     /* log                      */
217     _ico_sys_config->misc.loglevel
218              = g_key_file_get_integer(keyfile, "log", "loglevel", &error);
219     ico_uxf_conf_checkGerror(&error);
220     _ico_sys_config->misc.logflush =
221         ico_uxf_getSysBoolByName(g_key_file_get_string(keyfile, "log", "logflush", &error));
222     ico_uxf_conf_checkGerror(&error);
223
224     /* log setting              */
225     if (getenv("ICO_IVI_NO_LOG"))    {
226         ico_uxf_log_setlevel(0);
227     }
228     else    {
229         ico_uxf_log_setlevel(_ico_sys_config->misc.loglevel |
230                              ((_ico_sys_config->misc.logflush) ?
231                                 ICO_APF_LOG_FLUSH : ICO_APF_LOG_NOFLUSH));
232     }
233
234     /* [category] application category name and attributes          */
235     idlist = ico_uxf_conf_countNumericalKey(keyfile, "category");
236     length = g_list_length(idlist);
237     _ico_sys_config->categoryNum = length;
238     _ico_sys_config->category = g_malloc0(sizeof(Ico_Uxf_conf_category) * length);
239
240     for (i = 0; i < (int)length; i++) {
241         const char* key = (const char*) g_list_nth_data(idlist, i);
242         const char* g = "category";
243         _ico_sys_config->category[i].id = ico_uxf_conf_getUint(key);
244         ico_uxf_conf_checkGerror(&error);
245         _ico_sys_config->category[i].name = g_key_file_get_string(keyfile, g, key, &error);
246         ico_uxf_conf_checkGerror(&error);
247
248         strp = (char *)g_key_file_get_string(keyfile, g,
249                                              ico_uxf_conf_appendStr(key, ".view"), &error);
250         ico_uxf_conf_checkGerror(&error);
251         if (strncasecmp(strp, "alway", 5) == 0) {
252             _ico_sys_config->category[i].view = ICO_UXF_POLICY_ALWAYS;
253         }
254         else if (strncasecmp(strp, "run", 3) == 0)  {
255             _ico_sys_config->category[i].view = ICO_UXF_POLICY_RUNNING;
256         }
257         else if (strncasecmp(strp, "park", 4) == 0) {
258             _ico_sys_config->category[i].view = ICO_UXF_POLICY_PARKED;
259         }
260         else if (strncasecmp(strp, "shift_park", 10) == 0)  {
261             _ico_sys_config->category[i].view = ICO_UXF_POLICY_SHIFT_PARKING;
262         }
263         else if ((strncasecmp(strp, "shift_back", 10) == 0) ||
264                  (strncasecmp(strp, "shift_rev", 9) == 0))  {
265             _ico_sys_config->category[i].view = ICO_UXF_POLICY_SHIFT_REVERSES;
266         }
267         else if (strcasecmp(strp, "blinker_left") == 0)   {
268             _ico_sys_config->category[i].view = ICO_UXF_POLICY_BLINKER_LEFT;
269         }
270         else if (strcasecmp(strp, "blinker_right") == 0)  {
271             _ico_sys_config->category[i].view = ICO_UXF_POLICY_BLINKER_RIGHT;
272         }
273         else    {
274             fprintf(stderr, "[%s.view: %s] Unknown view mode\n", key, strp);
275             g_list_free_full(idlist,g_free);
276             g_key_file_free(keyfile);
277             return NULL;
278         }
279
280         strp = (char *)g_key_file_get_string(keyfile, g,
281                                              ico_uxf_conf_appendStr(key, ".sound"), &error);
282         ico_uxf_conf_checkGerror(&error);
283         if (strncasecmp(strp, "alway", 5) == 0) {
284             _ico_sys_config->category[i].sound = ICO_UXF_POLICY_ALWAYS;
285         }
286         else if (strncasecmp(strp, "run", 3) == 0)  {
287             _ico_sys_config->category[i].sound = ICO_UXF_POLICY_RUNNING;
288         }
289         else if (strncasecmp(strp, "park", 4) == 0) {
290             _ico_sys_config->category[i].sound = ICO_UXF_POLICY_PARKED;
291         }
292         else if (strncasecmp(strp, "shift_park", 10) == 0)  {
293             _ico_sys_config->category[i].sound = ICO_UXF_POLICY_SHIFT_PARKING;
294         }
295         else if ((strncasecmp(strp, "shift_back", 10) == 0) ||
296                  (strncasecmp(strp, "shift_rev", 9) == 0))  {
297             _ico_sys_config->category[i].sound = ICO_UXF_POLICY_SHIFT_REVERSES;
298         }
299         else if (strcasecmp(strp, "blinker_left") == 0)   {
300             _ico_sys_config->category[i].sound = ICO_UXF_POLICY_BLINKER_LEFT;
301         }
302         else if (strcasecmp(strp, "blinker_right") == 0)  {
303             _ico_sys_config->category[i].sound = ICO_UXF_POLICY_BLINKER_RIGHT;
304         }
305         else    {
306             fprintf(stderr, "[%s.view: %s] Unknown sound mode\n", key, strp);
307             g_list_free_full(idlist,g_free);
308             g_key_file_free(keyfile);
309             return NULL;
310         }
311
312         strp = (char *)g_key_file_get_string(keyfile, g,
313                                              ico_uxf_conf_appendStr(key, ".input"), &error);
314         ico_uxf_conf_checkGerror(&error);
315         if (strncasecmp(strp, "alway", 5) == 0) {
316             _ico_sys_config->category[i].input = ICO_UXF_POLICY_ALWAYS;
317         }
318         else if (strncasecmp(strp, "run", 3) == 0)  {
319             _ico_sys_config->category[i].input = ICO_UXF_POLICY_RUNNING;
320         }
321         else if (strncasecmp(strp, "park", 4) == 0) {
322             _ico_sys_config->category[i].input = ICO_UXF_POLICY_PARKED;
323         }
324         else if (strncasecmp(strp, "shift_park", 10) == 0)  {
325             _ico_sys_config->category[i].input = ICO_UXF_POLICY_SHIFT_PARKING;
326         }
327         else if ((strncasecmp(strp, "shift_back", 10) == 0) ||
328                  (strncasecmp(strp, "shift_rev", 9) == 0))  {
329             _ico_sys_config->category[i].input = ICO_UXF_POLICY_SHIFT_REVERSES;
330         }
331         else if (strcasecmp(strp, "blinker_left") == 0)   {
332             _ico_sys_config->category[i].input = ICO_UXF_POLICY_BLINKER_LEFT;
333         }
334         else if (strcasecmp(strp, "blinker_right") == 0)  {
335             _ico_sys_config->category[i].input = ICO_UXF_POLICY_BLINKER_RIGHT;
336         }
337         else    {
338             fprintf(stderr, "[%s.view: %s] Unknown input mode\n", key, strp);
339             g_list_free_full(idlist,g_free);
340             g_key_file_free(keyfile);
341             return NULL;
342         }
343         _ico_sys_config->category[i].priority =
344                                 g_key_file_get_integer(keyfile, g,
345                                 ico_uxf_conf_appendStr(key,".priority"), &error);
346         ico_uxf_conf_checkGerror(&error);
347
348         apfw_trace("Categry.%d id = %d name = %s view = %d sound = %d input = %d prio = %d",
349                    i, _ico_sys_config->category[i].id, _ico_sys_config->category[i].name,
350                    _ico_sys_config->category[i].view, _ico_sys_config->category[i].sound,
351                    _ico_sys_config->category[i].input,
352                    _ico_sys_config->category[i].priority);
353     }
354     g_list_free_full(idlist,g_free);
355
356     /* [kind] application kind name and attributes          */
357     idlist = ico_uxf_conf_countNumericalKey(keyfile, "kind");
358     length = g_list_length(idlist);
359     _ico_sys_config->kindNum = length;
360     _ico_sys_config->kind = g_malloc0(sizeof(Ico_Uxf_conf_kind) * length);
361
362     for (i = 0; i < (int)length; i++) {
363         const char* key = (const char*) g_list_nth_data(idlist, i);
364         const char* g = "kind";
365         _ico_sys_config->kind[i].id = ico_uxf_conf_getUint(key);
366         ico_uxf_conf_checkGerror(&error);
367         _ico_sys_config->kind[i].name = g_key_file_get_string(keyfile, g, key, &error);
368         ico_uxf_conf_checkGerror(&error);
369         strp = (char *)g_key_file_get_string(
370                             keyfile, g, ico_uxf_conf_appendStr(key, ".privilege"), &error);
371         ico_uxf_conf_checkGerror(&error);
372         if (strcasecmp(strp, "almighty") == 0)   {
373             _ico_sys_config->kind[i].priv = ICO_UXF_PRIVILEGE_ALMIGHTY;
374         }
375         else if (strcasecmp(strp, "system") == 0)   {
376             _ico_sys_config->kind[i].priv = ICO_UXF_PRIVILEGE_SYSTEM;
377         }
378         else if (strcasecmp(strp, "system.audio") == 0)   {
379             _ico_sys_config->kind[i].priv = ICO_UXF_PRIVILEGE_SYSTEM_AUDIO;
380         }
381         else if (strcasecmp(strp, "system.visible") == 0)   {
382             _ico_sys_config->kind[i].priv = ICO_UXF_PRIVILEGE_SYSTEM_VISIBLE;
383         }
384         else if (strcasecmp(strp, "maker") == 0)    {
385             _ico_sys_config->kind[i].priv = ICO_UXF_PRIVILEGE_MAKER;
386         }
387         else if (strcasecmp(strp, "certificate") == 0)  {
388             _ico_sys_config->kind[i].priv = ICO_UXF_PRIVILEGE_CERTIFICATE;
389         }
390         else if (strcasecmp(strp, "none") == 0) {
391             _ico_sys_config->kind[i].priv = ICO_UXF_PRIVILEGE_NONE;
392         }
393         else    {
394             fprintf(stderr, "[%s.view: %s] Unknown privilege mode\n", key, strp);
395             g_list_free_full(idlist,g_free);
396             g_key_file_free(keyfile);
397             return NULL;
398         }
399         apfw_trace("Kind.%d id = %d name = %s privilege = %d",
400                    i, _ico_sys_config->kind[i].id, _ico_sys_config->kind[i].name,
401                    _ico_sys_config->kind[i].priv);
402     }
403     g_list_free_full(idlist,g_free);
404
405     /* [port] port numbers              */
406     _ico_sys_config->misc.appscontrollerport
407         = g_key_file_get_integer(keyfile, "port", "appscontrollerport", &error);
408     ico_uxf_conf_checkGerror(&error);
409     _ico_sys_config->misc.soundpluginport
410         = g_key_file_get_integer(keyfile, "port", "soundpluginport", &error);
411     ico_uxf_conf_checkGerror(&error);
412     if (_ico_sys_config->misc.appscontrollerport <= 0)
413         _ico_sys_config->misc.appscontrollerport = 18081;
414     if (_ico_sys_config->misc.soundpluginport <= 0)
415         _ico_sys_config->misc.soundpluginport = 18082;
416
417     /* hosts                        */
418     idlist = ico_uxf_conf_countNumericalKey(keyfile, "host");
419     length = g_list_length(idlist);
420     _ico_sys_config->hostNum = length;
421     _ico_sys_config->host = g_malloc0(sizeof(Ico_Uxf_conf_host) * length);
422
423     for (i = 0; i < (int)length; i++)   {
424         char* key = (char*) g_list_nth_data(idlist, i);
425         const char* g = "host";
426         _ico_sys_config->host[i].id  = ico_uxf_conf_getUint(key);
427         _ico_sys_config->host[i].name = g_key_file_get_string(keyfile, g, key, &error);
428         ico_uxf_conf_checkGerror(&error);
429
430         _ico_sys_config->host[i].address
431             = g_key_file_get_string(keyfile, g, ico_uxf_conf_appendStr(key, ".ip"), &error);
432         ico_uxf_conf_checkGerror(&error);
433         if (g_hostname_is_ip_address(_ico_sys_config->host[i].address)!= TRUE){
434             apfw_error("host[%d] = %s is not ip address style",
435                         _ico_sys_config->host[i].id, _ico_sys_config->host[i].address);
436             exit(1);
437         }
438
439         _ico_sys_config->host[i].type =
440             ico_uxf_getSysHostTypeByName(
441                     g_key_file_get_string(keyfile, g,
442                                           ico_uxf_conf_appendStr(key, ".type"), &error));
443         ico_uxf_conf_checkGerror(&error);
444
445         _ico_sys_config->host[i].homescreen =
446             g_key_file_get_string(keyfile, g,
447                                   ico_uxf_conf_appendStr(key, ".homescreen"), &error);
448         ico_uxf_conf_checkGerror(&error);
449         apfw_trace("Host.%d: Id = %d Name = %s Type = %d Ip = %s HomeScreen = %s",
450             i, _ico_sys_config->host[i].id, (char *)_ico_sys_config->host[i].name,
451             _ico_sys_config->host[i].type, (char *)_ico_sys_config->host[i].address,
452             _ico_sys_config->host[i].homescreen);
453     }
454     g_list_free_full(idlist,g_free);
455
456     /* decide myhost        */
457     const char *penv = getenv(ICO_UXF_ENV_APPINF);
458     int hostid = -1;
459     int dmy1, dmy2, dmy3;
460     char cdmy4[64];
461     if (penv)  {
462         if (sscanf(penv, "%d %d %d %s %d", &dmy1, &dmy2, &dmy3, cdmy4, &hostid) < 5) {
463             hostid = -1;
464         }
465         apfw_trace("reloadSysConfig: Env(%s) = %s, hostId = %d",
466                     ICO_UXF_ENV_APPINF, penv, hostid);
467     }
468
469     if (hostid < 0)    {
470         if ((gethostname(cdmy4, sizeof(cdmy4)-1) >= 0) &&
471             (strncmp(cdmy4, "localhost", 9) != 0))   {
472             apfw_trace("hostname = %s", cdmy4);
473             for (j = 0; cdmy4[j]; j++) {
474                 if ((cdmy4[j] == ' ') || (cdmy4[j] == '(') ||
475                     (cdmy4[j] == '@') || (cdmy4[j] == ':'))    {
476                     cdmy4[j] = 0;
477                     break;
478                 }
479             }
480             for (j = 0; j < _ico_sys_config->hostNum; j++) {
481                 if (strcasecmp(_ico_sys_config->host[j].name, cdmy4) == 0)   {
482                     hostid = _ico_sys_config->host[j].id;
483                     break;
484                 }
485             }
486         }
487     }
488
489     if (hostid < 0)    {
490         FILE *fp = popen("/sbin/ifconfig", "r");
491         int foundeth = 0;
492         char sBuf[128];
493
494         if (fp)    {
495             while (fgets(sBuf, sizeof(sBuf)-1, fp))  {
496                 if ((! foundeth) || (sBuf[0] != ' '))  {
497                     foundeth = 0;
498                     /* skip to "eth" device     */
499                     if (sBuf[0] == ' ' || sBuf[0] == '\t') continue;
500                     if (strncmp(sBuf, "eth", 3) != 0)    continue;
501                 }
502                 foundeth = 1;
503
504                 for (j = 0; sBuf[j]; j++)  {
505                     if (strncmp(&sBuf[j], "inet6", 5) == 0)  continue;
506                     if (strncmp(&sBuf[j], "inet", 4) == 0)   break;
507                 }
508                 if (sBuf[j])   {
509                     /* forget "inet" device         */
510                     j += 4;
511                     for (; sBuf[j]; j++)   {
512                         if (sBuf[j] == ':')    break;
513                     }
514                     if (sBuf[j] )  {
515                         j++;
516                         int k;
517                         for (k = j +1; sBuf[k]; k++)   {
518                             if (sBuf[k] == ' ' || sBuf[k] == '\t' ||
519                                 sBuf[k] == '\n' || sBuf[k] == '\r')    {
520                                 sBuf[k] = 0;
521                                 break;
522                             }
523                         }
524                         apfw_trace("My Inet Addr = %s", &sBuf[j]);
525                         for (k = 0; k < _ico_sys_config->hostNum; k++) {
526                             if (strcmp(_ico_sys_config->host[k].address, &sBuf[j]) == 0) {
527                                 hostid = _ico_sys_config->host[k].id;
528                                 break;
529                             }
530                         }
531                     }
532                 }
533                 if (hostid >= 0)   break;
534             }
535             fclose(fp);
536         }
537     }
538     if (hostid >= 0)   {
539         _ico_sys_config->misc.myhostId = hostid;
540     }
541     else    {
542         apfw_trace("Default Host = 0, %s", ico_uxf_get_SysLocation(0));
543         _ico_sys_config->misc.myhostId = _ico_sys_config->host[0].id;
544     }
545
546     /* The validity of MyHost is checked.       */
547     Ico_Uxf_conf_host *myhost = (Ico_Uxf_conf_host *)
548             ico_uxf_getSysHostById(_ico_sys_config->misc.myhostId);
549     if (! myhost)  {
550         apfw_critical("MyHostId.%d dose not exist, default 0",
551                       _ico_sys_config->misc.myhostId);
552         myhost = &_ico_sys_config->host[0];
553         if (! myhost)  {
554             apfw_error("HostId.0 dose not exist, GiveUp!");
555             exit(1);
556         }
557         _ico_sys_config->misc.myhostId = myhost->id;
558     }
559
560     _ico_sys_config->misc.myaddress =
561             (char *)ico_uxf_get_SysLocation(_ico_sys_config->misc.myhostId);
562     _ico_sys_config->misc.myhostName = myhost->name;
563
564     _ico_sys_config->misc.homescreen = myhost->homescreen;
565
566     if (myhost->homescreen)    {
567         _ico_sys_config->misc.masterhostId = myhost->id;
568     }
569     else    {
570         _ico_sys_config->misc.masterhostId = _ico_sys_config->misc.myhostId;
571
572         for (i = 0; i < _ico_sys_config->hostNum; i++) {
573             if (_ico_sys_config->host[i].homescreen)   {
574                 _ico_sys_config->misc.masterhostId = _ico_sys_config->host[i].id;
575                 break;
576             }
577         }
578     }
579     _ico_sys_config->misc.masterhostaddress =
580             (char *)ico_uxf_get_SysLocation(_ico_sys_config->misc.masterhostId);
581
582     apfw_trace("MyHost %d[%s] Master Host %d(%s)", _ico_sys_config->misc.myhostId,
583                 _ico_sys_config->misc.myaddress, _ico_sys_config->misc.masterhostId,
584                 _ico_sys_config->misc.masterhostaddress);
585
586     _ico_sys_config->misc.default_hostId = ico_uxf_getSysHostByName(
587                             g_key_file_get_string(keyfile, "default", "host", &error));
588     ico_uxf_conf_checkGerror(&error);
589
590     /* display                  */
591     idlist = ico_uxf_conf_countNumericalKey(keyfile, "display");
592     length = g_list_length(idlist);
593     _ico_sys_config->displayNum = length;
594     _ico_sys_config->display = g_malloc0(sizeof(Ico_Uxf_conf_display) * length);
595     zoneidx = 0;
596
597     for (i = 0; i < (int)length; i++) {
598         const char* key = (const char*) g_list_nth_data(idlist, i);
599         const char* g = "display";
600         Ico_Uxf_conf_display *display = &_ico_sys_config->display[i];
601         display->id = ico_uxf_conf_getUint(key);
602         ico_uxf_conf_checkGerror(&error);
603         display->name = g_key_file_get_string(keyfile, g, key, &error);
604         ico_uxf_conf_checkGerror(&error);
605
606         display->hostId =
607             ico_uxf_getSysHostByName(
608                         g_key_file_get_string(keyfile, g,
609                                               ico_uxf_conf_appendStr(key,".host"), &error));
610         ico_uxf_conf_checkGerror(&error);
611         display->displayno =
612             g_key_file_get_integer(keyfile, g,
613                                    ico_uxf_conf_appendStr(key,".displayno"), &error);
614         if (error) {
615             display->displayno = -1;
616             g_clear_error(&error);
617         }
618         display->wayland =
619             g_key_file_get_string(keyfile, g,
620                                   ico_uxf_conf_appendStr(key,".wayland"), &error);
621         ico_uxf_conf_checkGerror(&error);
622
623         display->type =
624             ico_uxf_getSysDispTypeByName(g_key_file_get_string(keyfile, g,
625                                          ico_uxf_conf_appendStr(key,".type"), &error));
626         ico_uxf_conf_checkGerror(&error);
627
628         display->width =
629             g_key_file_get_integer(keyfile, g, ico_uxf_conf_appendStr(key,".width"), &error);
630         ico_uxf_conf_checkGerror(&error);
631         display->height =
632             g_key_file_get_integer(keyfile, g, ico_uxf_conf_appendStr(key,".height"), &error);
633         ico_uxf_conf_checkGerror(&error);
634         display->layerNum =
635             g_key_file_get_integer(keyfile, g, ico_uxf_conf_appendStr(key,".layer"), &error);
636         ico_uxf_conf_checkGerror(&error);
637
638         /* inch                     */
639         display->inch =
640             g_key_file_get_integer(keyfile,g,ico_uxf_conf_appendStr(key,".inch"),&error);
641         ico_uxf_conf_checkGerror(&error);
642
643         apfw_trace("Display.%d Id = %d Name = %s Host = %d DispNo = %d W/H = %d/%d Wayland = %s inch = %d",
644                    i, display->id, (char *)display->name, display->hostId,
645                    display->displayno, display->width, display->height,
646                    display->wayland, display->inch);
647
648         /* display layer            */
649         int displayer_length;
650         gchar **layerlist;
651         gsize layersize;
652         GString* layer_key = g_string_new("");
653         for (displayer_length = 0;
654              displayer_length < ICO_UXF_DISPLAY_LAYER_MAX; displayer_length++)  {
655             g_string_printf(layer_key,"%s.layer.%d",key,displayer_length);
656             if (g_key_file_has_key(keyfile,g,layer_key->str,NULL) != TRUE)   break;
657         }
658         apfw_trace("Display.%d layerNum = %d" ,i, displayer_length);
659         display->layerNum = displayer_length;
660         display->layer = g_malloc0(sizeof(Ico_Uxf_conf_display_layer)*displayer_length);
661
662         for (j = 0; j < displayer_length; j++)  {
663             g_string_printf(layer_key,"%s.layer.%d",key,j);
664             display->layer[j].id = j;
665             layerlist = g_key_file_get_string_list(keyfile, g, layer_key->str,
666                                                    &layersize, &error);
667             ico_uxf_conf_checkGerror(&error);
668             if (layersize <= 0) {
669                 apfw_error("Display.%d Layer.%d has no name", i, j);
670             }
671             else    {
672                 display->layer[j].name = strdup((char *)layerlist[0]);
673                 for (k = 1; k < (int)layersize; k++)    {
674                     if (strcasecmp((char *)layerlist[k], "menuoverlap") == 0)   {
675                         display->layer[j].menuoverlap = 1;
676                     }
677                 }
678                 apfw_trace("Display.%d Layer.%d id = %d name = %s overlap=%d", i, j,
679                            display->layer[j].id, display->layer[j].name,
680                            display->layer[j].menuoverlap);
681             }
682             if (layerlist)  g_strfreev(layerlist);
683         }
684         g_string_free(layer_key,TRUE);
685
686         /* display zone         */
687         int dispzone_length;
688         GString* zone_key = g_string_new("");
689         for (dispzone_length = 0;
690              dispzone_length < ICO_UXF_DISPLAY_ZONE_MAX; dispzone_length++) {
691             g_string_printf(zone_key,"%s.zone.%d",key,dispzone_length);
692             if (g_key_file_has_key(keyfile,g,zone_key->str,NULL) != TRUE)    break;
693         }
694         apfw_trace("Display.%d zoneNum = %d" ,i, dispzone_length);
695         display->zoneNum = dispzone_length;
696         display->zone = g_malloc0(sizeof(Ico_Uxf_conf_display_zone)*dispzone_length);
697
698         gsize zonesizes[ICO_UXF_DISPLAY_ZONE_MAX];
699         gchar **zonelists[ICO_UXF_DISPLAY_ZONE_MAX];
700         gchar **zonelist;
701         Ico_Uxf_conf_display_zone *zone;
702
703         for (j = 0; j < dispzone_length; j++)   {
704             g_string_printf(zone_key,"%s.zone.%d",key,j);
705             zonelists[j] = g_key_file_get_string_list(
706                                     keyfile, g, zone_key->str, &zonesizes[j], &error);
707             ico_uxf_conf_checkGerror(&error);
708             if ((! zonelists[j]) || (zonesizes[j] <= 0)) {
709                 apfw_error("reloadSysConfig: display.%d zone.%d dose not exist",i,j);
710                 zonesizes[j] = 0;
711             }
712         }
713         for (j = 0; j < dispzone_length; j++)   {
714             zone = &(display->zone[j]);
715             zone->id = j;
716             zone->zoneidx = zoneidx++;
717             zone->display = display;
718             zone->node = ICO_UXF_NODEDISP_2_NODEID(display->hostId, display->displayno);
719
720             if (zonesizes[j] <= 0)  continue;
721
722             zonelist = zonelists[j];
723             zone->name = strdup((char*)zonelist[0]);
724             if (zonesizes[j] < 5)   {
725                 /* default zone is full screen      */
726                 zone->x = 0;
727                 zone->y = 0;
728                 zone->width = display->width;
729                 zone->height = display->height;
730             }
731             else    {
732                 zone->x = pars_dispposition((char *)zonelist[1], display);
733                 zone->y = pars_dispposition((char *)zonelist[2], display);
734                 zone->width = pars_dispposition((char *)zonelist[3], display);
735                 zone->height = pars_dispposition((char *)zonelist[4], display);
736             }
737         }
738         for (j = 0; j < dispzone_length; j++)   {
739             int k, l, m, n;
740             if (zonesizes[j] <= 5)  continue;
741             zonelist = zonelists[j];
742             zone = &(display->zone[j]);
743             m = 0;
744             for (k = 5; (m < ZONE_MAX_OVERLAP) && (k < (int)zonesizes[j]); k++) {
745                 for (l = 0; l < dispzone_length; l++)   {
746                     if (l == j) continue;
747                     if (strcasecmp(zonelist[k], display->zone[l].name) == 0)    {
748                         for (n = 0; n < m; n++) {
749                             if (zone->overlap[n] == display->zone[l].id)    break;
750                         }
751                         if (n >= m) {
752                             zone->overlap[m++] = display->zone[l].id;
753                         }
754                         break;
755                     }
756                 }
757                 if (l >= dispzone_length)   {
758                     apfw_error("reloadSysConfig: disp.%d zone.%d overlap zone(%s) "
759                                "dose not exist", i, j, (char *)zonelist[k]);
760                 }
761             }
762             zone->overlapNum = m;
763         }
764         for (j = 0; j < dispzone_length; j++)   {
765             if (zonelists[j])   g_strfreev(zonelists[j]);
766             zone = &(display->zone[j]);
767             apfw_trace("Disp.%d zone.%d node=%x x/y=%d/%d w/h=%d/%d over=%d.%d %d %d %d %d",
768                        i, j, zone->node, zone->x, zone->y, zone->width, zone->height,
769                        zone->overlapNum, zone->overlap[0], zone->overlap[1],
770                        zone->overlap[2], zone->overlap[3], zone->overlap[4]);
771         }
772         g_string_free(zone_key,TRUE);
773     }
774     g_list_free_full(idlist,g_free);
775
776     /* sound devices                        */
777     idlist = ico_uxf_conf_countNumericalKey(keyfile, "sound");
778     length = g_list_length(idlist);
779     _ico_sys_config->soundNum = length;
780     _ico_sys_config->sound = g_malloc0(sizeof(Ico_Uxf_conf_sound) * length);
781     zoneidx = 0;
782
783     for (i = 0; i < (int)length; i++) {
784         const char* key = (const char*) g_list_nth_data(idlist, i);
785         const char* g = "sound";
786         Ico_Uxf_conf_sound *sound = &_ico_sys_config->sound[i];
787         sound->id = ico_uxf_conf_getUint(key);
788         ico_uxf_conf_checkGerror(&error);
789         sound->name = g_key_file_get_string(keyfile, g, key, &error);
790         ico_uxf_conf_checkGerror(&error);
791
792         sound->hostId =
793             ico_uxf_getSysHostByName(g_key_file_get_string(
794                                     keyfile, g, ico_uxf_conf_appendStr(key,".host"), &error));
795         ico_uxf_conf_checkGerror(&error);
796         sound->soundno =
797             g_key_file_get_integer(keyfile, g,
798                                    ico_uxf_conf_appendStr(key,".soundno"), &error);
799         if (error) {
800             sound->soundno = -1;
801             g_clear_error(&error);
802         }
803
804         apfw_trace("Sound.%d Id = %d Name = %s Host = %d SoundNo = %d",
805                    i, sound->id, (char *)sound->name, sound->hostId, sound->soundno);
806
807         /* sound zone           */
808         int sound_length;
809         GString* sound_key = g_string_new("");
810         for (sound_length = 0;
811              sound_length < ICO_UXF_SOUND_ZONE_MAX; sound_length++) {
812             g_string_printf(sound_key,"%s.zone.%d", key, sound_length);
813             if (g_key_file_has_key(keyfile,g,sound_key->str,NULL) != TRUE)   break;
814         }
815         apfw_trace("Sound.%d zoneNum = %d" ,i, sound_length);
816         sound->zoneNum = sound_length;
817         sound->zone = g_malloc0(sizeof(Ico_Uxf_conf_sound_zone)*sound_length);
818
819         gsize zonesizes[ICO_UXF_SOUND_ZONE_MAX];
820         gchar **zonelists[ICO_UXF_SOUND_ZONE_MAX];
821         gchar **zonelist;
822         Ico_Uxf_conf_sound_zone *zone;
823
824         for (j = 0; j < sound_length; j++)  {
825             g_string_printf(sound_key,"%s.zone.%d",key,j);
826             zonelists[j] =
827                 g_key_file_get_string_list(keyfile,g,sound_key->str,&zonesizes[j],&error);
828             ico_uxf_conf_checkGerror(&error);
829             if ((! zonelists[j]) || (zonesizes[j] <= 0)) {
830                 apfw_error("reloadSysConfig: sound.%d zone.%d dose not exist",i,j);
831                 zonesizes[j] = 0;
832             }
833         }
834         for (j = 0; j < sound_length; j++)  {
835             zone = &(sound->zone[j]);
836             zone->id = j;
837             zone->zoneidx = zoneidx++;
838             zone->sound = sound;
839             if (zonesizes[j] <= 0)  continue;
840
841             zonelist = zonelists[j];
842             zone->name = strdup((char*)zonelist[0]);
843         }
844         for (j = 0; j < sound_length; j++)  {
845             int k, l, m, n;
846             if (zonesizes[j] <= 1)  continue;
847             zonelist = zonelists[j];
848             zone = &(sound->zone[j]);
849             m = 0;
850             for (k = 1; (m < ZONE_MAX_OVERLAP) && (k < (int)zonesizes[j]); k++) {
851                 for (l = 0; l < sound_length; l++)  {
852                     if (l == j) continue;
853                     if (strcasecmp((char*)zonelist[k], sound->zone[l].name) == 0)   {
854                         for (n = 0; n < m; n++) {
855                             if (zone->overlap[n] == sound->zone[l].id)  break;
856                         }
857                         if (n >= m) {
858                             zone->overlap[m++] = sound->zone[l].id;
859                         }
860                         break;
861                     }
862                 }
863                 if (l >= sound_length)  {
864                     apfw_error("reloadSysConfig: sound.%d zone.%d overlap zone(%s) "
865                                "dose not exist", i, j, (char *)zonelist[k]);
866                 }
867             }
868             zone->overlapNum = m;
869         }
870         for (j = 0; j < sound_length; j++)  {
871             if (zonelists[j])   g_strfreev(zonelists[j]);
872             zone = &(sound->zone[j]);
873             apfw_trace("Sound.%d zone.%d(%s) over = %d.%d %d %d %d %d",
874                        i, j, zone->name,
875                        zone->overlapNum, zone->overlap[0], zone->overlap[1],
876                        zone->overlap[2], zone->overlap[3], zone->overlap[4]);
877         }
878         g_string_free(sound_key,TRUE);
879     }
880     g_list_free_full(idlist,g_free);
881
882     /* input devices                        */
883     idlist = ico_uxf_conf_countNumericalKey(keyfile, "input");
884     length = g_list_length(idlist);
885     _ico_sys_config->inputdevNum = length;
886     _ico_sys_config->inputdev = g_malloc0(sizeof(Ico_Uxf_conf_inputdev) * length);
887
888     for (i = 0; i < (int)length; i++) {
889         const char* key = (const char*) g_list_nth_data(idlist, i);
890         const char* g = "input";
891         Ico_Uxf_conf_inputdev *inputdev = &_ico_sys_config->inputdev[i];
892         inputdev->id = ico_uxf_conf_getUint(key);
893         ico_uxf_conf_checkGerror(&error);
894         inputdev->name = g_key_file_get_string(keyfile, g, key, &error);
895         ico_uxf_conf_checkGerror(&error);
896
897         /* input sw             */
898         int sw_length;
899         GString* sw_key = g_string_new("");
900         for (sw_length = 0;; sw_length++)   {
901             g_string_printf(sw_key,"%s.sw.%d",key,sw_length);
902             if (g_key_file_has_key(keyfile,g,sw_key->str,NULL) != TRUE)  break;
903         }
904         apfw_trace("Input.%d swNum = %d" ,i, sw_length);
905         inputdev->inputswNum = sw_length;
906         inputdev->inputsw = g_malloc0(sizeof(Ico_Uxf_conf_inputsw)*sw_length);
907
908         /* input sw         */
909         gchar **swlist;
910         gsize   swsize;
911         for (j = 0; j < sw_length; j++) {
912             g_string_printf(sw_key,"%s.sw.%d",key,j);
913             swlist = g_key_file_get_string_list(keyfile,g,sw_key->str,&swsize,&error);
914             ico_uxf_conf_checkGerror(&error);
915             if ((!swlist) || (swsize <= 0))  {
916                 apfw_error("reloadSysConfig: input.%d sw.%d dose not exist",i,j);
917                 swsize = 0;
918             }
919             else    {
920                 inputdev->inputsw[j].inputdev = inputdev;
921                 inputdev->inputsw[j].name = strdup((char *)swlist[0]);
922                 if (swsize > 1) {
923                     inputdev->inputsw[j].appid = strdup((char *)swlist[1]);
924                     if (swsize > 2) {
925                         inputdev->inputsw[j].keycode = strtol((char *)swlist[2],
926                                                               (char **)0, 0);
927                     }
928                 }
929             }
930             g_strfreev(swlist);
931             uifw_trace("Input %s.%s app = %s key=%d",
932                        inputdev->name,
933                        inputdev->inputsw[j].name ? inputdev->inputsw[j].name : " ",
934                        inputdev->inputsw[j].appid ? inputdev->inputsw[j].appid : " ",
935                        inputdev->inputsw[j].keycode);
936         }
937         g_string_free(sw_key,TRUE);
938     }
939     g_list_free_full(idlist,g_free);
940
941     _ico_sys_config->misc.default_kindId = ico_uxf_getSysKindByName(
942                         g_key_file_get_string(keyfile, "default", "kind", &error));
943     ico_uxf_conf_checkGerror(&error);
944     _ico_sys_config->misc.default_categoryId = ico_uxf_getSysCategoryByName(
945                         g_key_file_get_string(keyfile, "default", "category", &error));
946     ico_uxf_conf_checkGerror(&error);
947     _ico_sys_config->misc.default_displayId = ico_uxf_getSysDisplayByName(
948                         g_key_file_get_string(keyfile, "default", "display", &error));
949     ico_uxf_conf_checkGerror(&error);
950     _ico_sys_config->misc.default_layerId = ico_uxf_getSysLayerByName(
951                         _ico_sys_config->misc.default_displayId,
952                         g_key_file_get_string(keyfile, "default", "layer", &error));
953     ico_uxf_conf_checkGerror(&error);
954     _ico_sys_config->misc.default_dispzoneId = ico_uxf_getSysDispZoneByName(
955                         _ico_sys_config->misc.default_displayId,
956                         g_key_file_get_string(keyfile, "default", "displayzone", &error));
957     _ico_sys_config->misc.default_soundId = ico_uxf_getSysSoundByName(
958                         g_key_file_get_string(keyfile, "default", "sound", &error));
959     _ico_sys_config->misc.default_soundzoneId = ico_uxf_getSysSoundZoneByName(
960                         _ico_sys_config->misc.default_soundId,
961                         g_key_file_get_string(keyfile, "default", "soundzone", &error));
962     ico_uxf_conf_checkGerror(&error);
963     _ico_sys_config->misc.default_inputdevId = ico_uxf_getSysInputdevByName(
964                         g_key_file_get_string(keyfile, "default", "inputdev", &error));
965     _ico_sys_config->misc.default_inputswId = ico_uxf_getSysInputswByName(
966                         _ico_sys_config->misc.default_inputdevId,
967                         g_key_file_get_string(keyfile, "default", "inputsw", &error));
968     ico_uxf_conf_checkGerror(&error);
969
970     apfw_trace("Default host = %d kind = %d category = %d disp = %d layer = %d dispzone = %d "
971                "sound = %d soundzone = %d input = %d/%d",
972                _ico_sys_config->misc.default_hostId,
973                _ico_sys_config->misc.default_kindId,
974                _ico_sys_config->misc.default_categoryId,
975                _ico_sys_config->misc.default_displayId,
976                _ico_sys_config->misc.default_layerId,
977                _ico_sys_config->misc.default_dispzoneId,
978                _ico_sys_config->misc.default_soundId,
979                _ico_sys_config->misc.default_soundzoneId,
980                _ico_sys_config->misc.default_inputdevId,
981                _ico_sys_config->misc.default_inputswId);
982     g_key_file_free(keyfile);
983
984     apfw_trace("reloadSysConfig: Leave");
985     return _ico_sys_config;
986 }
987
988 /*--------------------------------------------------------------------------*/
989 /**
990  * @brief   ico_uxf_getSysHostById: get host configuration by host Id
991  *
992  * @param[in]   hostId      host Id
993  * @return      host configuration table
994  * @retval      != NULL         success(host configuration table address)
995  * @retval      == NULL         error(host Id dose not exist)
996  */
997 /*--------------------------------------------------------------------------*/
998 ICO_APF_API const Ico_Uxf_conf_host *
999 ico_uxf_getSysHostById(const int hostId)
1000 {
1001     int     i;
1002
1003     if (!_ico_sys_config) {
1004         (void)ico_uxf_getSysConfig();
1005     }
1006
1007     for (i = 0; i < _ico_sys_config->hostNum; i++) {
1008         if (_ico_sys_config->host[i].id == hostId) {
1009             return &_ico_sys_config->host[i];
1010         }
1011     }
1012     apfw_warn("ico_uxf_getSysHostById(%d) Illegal Host Number", hostId);
1013     return NULL;
1014 }
1015
1016 /*--------------------------------------------------------------------------*/
1017 /**
1018  * @brief   ico_uxf_get_SysLocation: get host location by host Id
1019  *
1020  * @param[in]   hostId      host Id
1021  * @return      host location name
1022  * @retval      != NULL         success(host location name)
1023  * @retval      == NULL         error(host Id dose not exist)
1024  */
1025 /*--------------------------------------------------------------------------*/
1026 ICO_APF_API const char *
1027 ico_uxf_get_SysLocation(const int hostId)
1028 {
1029     int     i;
1030
1031     if (!_ico_sys_config) {
1032         (void)ico_uxf_getSysConfig();
1033     }
1034
1035     for (i = 0; i < _ico_sys_config->hostNum; i++) {
1036         if (_ico_sys_config->host[i].id == hostId) {
1037             return _ico_sys_config->host[i].address;
1038         }
1039     }
1040     apfw_warn("Ico_uxf_get_SysLocation(%d) Illegal Host Number", hostId);
1041     return "127.0.0.1";
1042 }
1043
1044 /*--------------------------------------------------------------------------*/
1045 /**
1046  * @brief   ico_uxf_getSysDisplayById: get display configuration by display Id
1047  *
1048  * @param[in]   displayId       display Id
1049  * @return      display configuration table address
1050  * @retval      != NULL         success(host oy configuration tabel address)
1051  * @retval      == NULL         error(displayd dose not exist)
1052  */
1053 /*--------------------------------------------------------------------------*/
1054 ICO_APF_API const Ico_Uxf_conf_display *
1055 ico_uxf_getSysDisplayById(const int displayId)
1056 {
1057     int     i;
1058
1059     if (!_ico_sys_config) {
1060         (void)ico_uxf_getSysConfig();
1061     }
1062
1063     for (i = 0; i < _ico_sys_config->displayNum; i++)  {
1064         if (_ico_sys_config->display[i].id == displayId)   {
1065             return &_ico_sys_config->display[i];
1066         }
1067     }
1068     apfw_warn("ico_uxf_getSysDisplayById(%d) Illegal Display Number", displayId);
1069     return NULL;
1070 }
1071
1072 /*--------------------------------------------------------------------------*/
1073 /**
1074  * @brief   ico_uxf_getSysHostByName: get host Id bu host name
1075  *
1076  * @param[in]   shost       host name
1077  * @return      host Id number
1078  */
1079 /*--------------------------------------------------------------------------*/
1080 ICO_APF_API int
1081 ico_uxf_getSysHostByName(const char *shost)
1082 {
1083     int     i;
1084
1085     if (!_ico_sys_config) {
1086         (void)ico_uxf_getSysConfig();
1087     }
1088     if (_ico_sys_config->hostNum <= 0)  {
1089         apfw_critical("ico_uxf_getSysHostByName: can not read configuration file");
1090         return _ico_sys_config->misc.default_hostId;
1091     }
1092
1093     if ((! shost) || (*shost == 0))    {
1094         return _ico_sys_config->host[0].id;
1095     }
1096
1097     for (i = 0; i < _ico_sys_config->hostNum; i++) {
1098         if (strcasecmp(shost, _ico_sys_config->host[i].name) == 0)    {
1099             return _ico_sys_config->host[i].id;
1100         }
1101     }
1102     apfw_warn("ico_uxf_getSysHostByName(%s) Illegal Host Name", shost);
1103     return _ico_sys_config->misc.default_hostId;
1104 }
1105
1106 /*--------------------------------------------------------------------------*/
1107 /**
1108  * @brief   ico_uxf_getSysHostTypeByName: get host type number by name(internal function)
1109  *
1110  * @param[in]   stype       host type name
1111  * @return      host type number
1112  */
1113 /*--------------------------------------------------------------------------*/
1114 int
1115 ico_uxf_getSysHostTypeByName(const char *stype)
1116 {
1117     if ((! stype) || (*stype == 0))    {
1118         return ICO_UXF_HOSTTYPE_CENTER;
1119     }
1120     if (strcasecmp(stype, "center") == 0)    {
1121         return ICO_UXF_HOSTTYPE_CENTER;
1122     }
1123     else if (strcasecmp(stype, "meter") == 0)    {
1124         return ICO_UXF_HOSTTYPE_METER;
1125     }
1126     else if (strcasecmp(stype, "remote") == 0)   {
1127         return ICO_UXF_HOSTTYPE_REMOTE;
1128     }
1129     else if (strcasecmp(stype, "passenger") == 0)    {
1130         return ICO_UXF_HOSTTYPE_PASSENGER;
1131     }
1132     else if (strcasecmp(stype, "rear") == 0) {
1133         return ICO_UXF_HOSTTYPE_REAR;
1134     }
1135     else if (strcasecmp(stype, "rearleft") == 0) {
1136         return ICO_UXF_HOSTTYPE_REARLEFT;
1137     }
1138     else if (strcasecmp(stype, "rearright") == 0)    {
1139         return ICO_UXF_HOSTTYPE_REARRIGHT;
1140     }
1141     apfw_warn("ico_uxf_getSysHostTypeByName(%s) Illegal HostType Name", stype);
1142     return strtol(stype, (char **)0, 0);
1143 }
1144
1145 /*--------------------------------------------------------------------------*/
1146 /**
1147  * @brief   ico_uxf_getSysDispTypeByName: get display type number by name(internal function)
1148  *
1149  * @param[in]   stype       display type name
1150  * @return      display type number
1151  */
1152 /*--------------------------------------------------------------------------*/
1153 int
1154 ico_uxf_getSysDispTypeByName(const char *stype)
1155 {
1156     if ((! stype) || (*stype == 0))    {
1157         apfw_critical("ico_uxf_getSysDispTypeByName(NULL) Illegal HostType Name");
1158         return 0;
1159     }
1160     if (strcasecmp(stype, "center") == 0)    {
1161         return ICO_UXF_DISPLAYTYPE_CENTER;
1162     }
1163     else if (strcasecmp(stype, "meter") == 0)    {
1164         return ICO_UXF_DISPLAYTYPE_METER;
1165     }
1166     else if (strcasecmp(stype, "remote") == 0)   {
1167         return ICO_UXF_DISPLAYTYPE_REMOTE;
1168     }
1169     else if (strcasecmp(stype, "passenger") == 0)    {
1170         return ICO_UXF_DISPLAYTYPE_PASSENGER;
1171     }
1172     else if (strcasecmp(stype, "rear") == 0) {
1173         return ICO_UXF_DISPLAYTYPE_REAR;
1174     }
1175     else if (strcasecmp(stype, "rearleft") == 0) {
1176         return ICO_UXF_DISPLAYTYPE_REARLEFT;
1177     }
1178     else if (strcasecmp(stype, "rearright") == 0)    {
1179         return ICO_UXF_DISPLAYTYPE_REARRIGHT;
1180     }
1181     apfw_warn("ico_uxf_getSysDispTypeByName(%s) Illegal DisplayType Name", stype);
1182     return strtol(stype, (char **)0, 0);
1183 }
1184
1185 /*--------------------------------------------------------------------------*/
1186 /**
1187  * @brief   ico_uxf_getSysBoolByName: get boolian value(internal function)
1188  *
1189  * @param[in]   sbool       boolian value string
1190  * @return      boolian value
1191  * @retval      = 0             false
1192  * @retval      = 1             true
1193  */
1194 /*--------------------------------------------------------------------------*/
1195 int
1196 ico_uxf_getSysBoolByName(const char *sbool)
1197 {
1198     if ((! sbool) || (*sbool == 0))    {
1199         return 0;
1200     }
1201     if ((strcasecmp(sbool, "true") == 0) ||
1202         (strcasecmp(sbool, "yes") == 0) ||
1203         (strcasecmp(sbool, "1") == 0))  {
1204         return 1;
1205     }
1206     return 0;
1207 }
1208
1209 /*--------------------------------------------------------------------------*/
1210 /**
1211  * @brief   ico_uxf_getSysDisplayByName: get display Id by display name
1212  *
1213  * @param[in]   sdisplay        display name
1214  * @return      display Id
1215  */
1216 /*--------------------------------------------------------------------------*/
1217 ICO_APF_API int
1218 ico_uxf_getSysDisplayByName(const char *sdisplay)
1219 {
1220     int     i;
1221
1222     if (!_ico_sys_config) {
1223         (void)ico_uxf_getSysConfig();
1224     }
1225     if ((! sdisplay) || (*sdisplay == 0))  {
1226         apfw_trace("ico_uxf_getSysDisplayByName(NULL) Illegal Display Name");
1227         return _ico_sys_config->misc.default_displayId;
1228     }
1229
1230     for (i = 0; i < _ico_sys_config->displayNum; i++) {
1231         if (strcasecmp(sdisplay, _ico_sys_config->display[i].name) == 0)    {
1232             return _ico_sys_config->display[i].id;
1233         }
1234     }
1235     apfw_warn("ico_uxf_getSysDisplayByName(%s) Illegal Display Name", sdisplay);
1236     return _ico_sys_config->misc.default_displayId;
1237 }
1238
1239 /*--------------------------------------------------------------------------*/
1240 /**
1241  * @brief   ico_uxf_getSysLayerByName: get layer Id by layer name
1242  *
1243  * @param[in]   display     display Id
1244  * @param[in]   slayer      layer name
1245  * @return      layer Id
1246  */
1247 /*--------------------------------------------------------------------------*/
1248 ICO_APF_API int
1249 ico_uxf_getSysLayerByName(const int display, const char *slayer)
1250 {
1251     int     i;
1252     char    *errp;
1253
1254     if (!_ico_sys_config) {
1255         (void)ico_uxf_getSysConfig();
1256     }
1257
1258     if ((display < 0) || (display >= _ico_sys_config->displayNum)) {
1259         apfw_warn("ico_uxf_getSysLayerByName(%d,%s) Illegal Display Number",
1260                             display, slayer);
1261         return _ico_sys_config->misc.default_layerId;
1262     }
1263     if ((! slayer) || (*slayer == 0))  {
1264         apfw_trace("ico_uxf_getSysLayerByName(NULL) Illegal Layer Name");
1265         return _ico_sys_config->misc.default_layerId;
1266     }
1267
1268     for (i = 0; i < _ico_sys_config->display[display].layerNum; i++)    {
1269         if (strcasecmp(slayer, _ico_sys_config->display[display].layer[i].name) == 0)   {
1270             return _ico_sys_config->display[display].layer[i].id;
1271         }
1272     }
1273
1274     errp = NULL;
1275     i = strtol(slayer, &errp, 0);
1276     if ((errp) && (*errp != 0)) {
1277         apfw_warn("ico_uxf_getSysLayerByName(%d,%s) Illegal Layer Name", display, slayer);
1278         i = _ico_sys_config->misc.default_layerId;
1279     }
1280     return i;
1281 }
1282
1283 /*--------------------------------------------------------------------------*/
1284 /**
1285  * @brief   ico_uxf_getSysKindByName: get kind Id by kind name
1286  *
1287  * @param[in]   skind       kind name
1288  * @return      kind Id
1289  */
1290 /*--------------------------------------------------------------------------*/
1291 ICO_APF_API int
1292 ico_uxf_getSysKindByName(const char *skind)
1293 {
1294     int     i;
1295
1296     if (!_ico_sys_config) {
1297         (void)ico_uxf_getSysConfig();
1298     }
1299     if (_ico_sys_config->kindNum <= 0)  {
1300         apfw_critical("ico_uxf_getSysKindByName: can not read configuration file");
1301         return _ico_sys_config->misc.default_kindId;
1302     }
1303
1304     if ((skind) && (*skind != 0))  {
1305         for (i = 0; i < _ico_sys_config->kindNum; i++) {
1306             if (strcasecmp(skind, _ico_sys_config->kind[i].name) == 0)    {
1307                 return _ico_sys_config->kind[i].id;
1308             }
1309         }
1310     }
1311     apfw_warn("ico_uxf_getSysKindByName(%s) Illegal kind name", skind);
1312     return _ico_sys_config->misc.default_kindId;
1313 }
1314
1315 /*--------------------------------------------------------------------------*/
1316 /**
1317  * @brief   ico_uxf_getSysCategoryByName: get category Id by category name
1318  *
1319  * @param[in]   scategory   category name
1320  * @return      category Id
1321  */
1322 /*--------------------------------------------------------------------------*/
1323 ICO_APF_API int
1324 ico_uxf_getSysCategoryByName(const char *scategory)
1325 {
1326     int     i;
1327
1328     if (!_ico_sys_config) {
1329         (void)ico_uxf_getSysConfig();
1330     }
1331     if (_ico_sys_config->categoryNum <= 0)  {
1332         apfw_critical("ico_uxf_getSysCategoryByName: can not read configuration file");
1333         return _ico_sys_config->misc.default_categoryId;
1334     }
1335
1336     if ((scategory) && (*scategory != 0))  {
1337         for (i = 0; i < _ico_sys_config->categoryNum; i++) {
1338             if (strcasecmp(scategory, _ico_sys_config->category[i].name) == 0)    {
1339                 return _ico_sys_config->category[i].id;
1340             }
1341         }
1342     }
1343     apfw_warn("ico_uxf_getSysCategoryByName(%s) Illegal category name", scategory);
1344     return _ico_sys_config->misc.default_categoryId;
1345 }
1346
1347 /*--------------------------------------------------------------------------*/
1348 /**
1349  * @brief   ico_uxf_getSysDispZoneByName: get display zone Id by display zone name
1350  *
1351  * @param[in]   display     display Id
1352  * @param[in]   sdispzone   displahy zone name
1353  * @return      display zone Id
1354  */
1355 /*--------------------------------------------------------------------------*/
1356 ICO_APF_API int
1357 ico_uxf_getSysDispZoneByName(const int display, const char *sdispzone)
1358 {
1359     int     i;
1360
1361     if (!_ico_sys_config) {
1362         (void)ico_uxf_getSysConfig();
1363     }
1364     if ((display < 0) || (display >= _ico_sys_config->displayNum) ||
1365         (_ico_sys_config->display[display].zoneNum <= 0))   {
1366         apfw_critical("ico_uxf_getSysDispZoneByName: can not read configuration file");
1367         return _ico_sys_config->misc.default_dispzoneId;
1368     }
1369
1370     if ((sdispzone) && (*sdispzone != 0))  {
1371         for (i = 0; i < _ico_sys_config->display[display].zoneNum; i++) {
1372             if (strcasecmp(sdispzone, _ico_sys_config->display[display].zone[i].name) == 0) {
1373                 return _ico_sys_config->display[display].zone[i].id;
1374             }
1375         }
1376     }
1377     apfw_warn("ico_uxf_getSysDispZoneByName(%s) Illegal zone name", sdispzone);
1378     return _ico_sys_config->misc.default_dispzoneId;
1379 }
1380
1381 /*--------------------------------------------------------------------------*/
1382 /**
1383  * @brief   ico_uxf_getSysSoundByName: get sound Id by sound name
1384  *
1385  * @param[in]   ssound      sound name
1386  * @return      sound Id
1387  */
1388 /*--------------------------------------------------------------------------*/
1389 ICO_APF_API int
1390 ico_uxf_getSysSoundByName(const char *ssound)
1391 {
1392     int     i;
1393
1394     if (!_ico_sys_config) {
1395         (void)ico_uxf_getSysConfig();
1396     }
1397     if (_ico_sys_config->soundNum <= 0) {
1398         apfw_critical("ico_uxf_getSysSoundByName: can not read configuration file");
1399         return _ico_sys_config->misc.default_soundId;
1400     }
1401
1402     if ((ssound) && (*ssound != 0))    {
1403         for (i = 0; i < _ico_sys_config->soundNum; i++) {
1404             if (strcasecmp(ssound, _ico_sys_config->sound[i].name) == 0)    {
1405                 return _ico_sys_config->sound[i].id;
1406             }
1407         }
1408     }
1409     apfw_warn("ico_uxf_getSysSoundByName(%s) Illegal sound name", ssound);
1410     return _ico_sys_config->misc.default_soundId;
1411 }
1412
1413 /*--------------------------------------------------------------------------*/
1414 /**
1415  * @brief   ico_uxf_getSysSoundZoneByName: get sound zone Id by sound zone name
1416  *
1417  * @param[in]   sound       sound Id
1418  * @param[in]   ssoundzone  sound zone name
1419  * @return      sound zone Id
1420  */
1421 /*--------------------------------------------------------------------------*/
1422 ICO_APF_API int
1423 ico_uxf_getSysSoundZoneByName(const int sound, const char *ssoundzone)
1424 {
1425     int     i;
1426
1427     if (!_ico_sys_config) {
1428         (void)ico_uxf_getSysConfig();
1429     }
1430     if ((sound < 0) || (sound >= _ico_sys_config->soundNum) ||
1431         (_ico_sys_config->sound[sound].zoneNum <= 0))   {
1432         apfw_critical("ico_uxf_getSysSoundZoneByName: can not read configuration file");
1433         return _ico_sys_config->misc.default_soundzoneId;
1434     }
1435
1436     if ((ssoundzone) && (*ssoundzone != 0))    {
1437         for (i = 0; i < _ico_sys_config->sound[sound].zoneNum; i++) {
1438             if (strcasecmp(ssoundzone, _ico_sys_config->sound[sound].zone[i].name) == 0)    {
1439                 return _ico_sys_config->sound[sound].zone[i].id;
1440             }
1441         }
1442     }
1443     apfw_warn("ico_uxf_getSysSoundZoneByName(%s) Illegal zone name", ssoundzone);
1444     return _ico_sys_config->misc.default_soundzoneId;
1445 }
1446
1447 /*--------------------------------------------------------------------------*/
1448 /**
1449  * @brief   ico_uxf_getSysInputdevByName: get input device Id by input device name
1450  *
1451  * @param[in]   sinputdev   input device name
1452  * @return      input device Id
1453  */
1454 /*--------------------------------------------------------------------------*/
1455 ICO_APF_API int
1456 ico_uxf_getSysInputdevByName(const char *sinputdev)
1457 {
1458     int     i;
1459
1460     if (!_ico_sys_config) {
1461         (void)ico_uxf_getSysConfig();
1462     }
1463     if (_ico_sys_config->inputdevNum <= 0)  {
1464         apfw_critical("ico_uxf_getSysInputdevByName: can not read configuration file");
1465         return _ico_sys_config->misc.default_inputdevId;
1466     }
1467
1468     if ((! sinputdev) || (*sinputdev == 0))    {
1469         return _ico_sys_config->misc.default_inputdevId;
1470     }
1471
1472     for (i = 0; i < _ico_sys_config->inputdevNum; i++) {
1473         if (strcasecmp(sinputdev, _ico_sys_config->inputdev[i].name) == 0)    {
1474             return _ico_sys_config->inputdev[i].id;
1475         }
1476     }
1477     apfw_warn("ico_uxf_getSysInputdevByName(%s) Illegal device Name", sinputdev);
1478     return _ico_sys_config->misc.default_inputdevId;
1479 }
1480
1481 /*--------------------------------------------------------------------------*/
1482 /**
1483  * @brief   ico_uxf_getSysInputswByName: get input switch Id by input switch name
1484  *
1485  * @param[in]   inputdev    input device Id
1486  * @param[in]   sinputsw    input switch name
1487  * @return      input switch Id
1488  */
1489 /*--------------------------------------------------------------------------*/
1490 ICO_APF_API int
1491 ico_uxf_getSysInputswByName(const int inputdev, const char *sinputsw)
1492 {
1493     int     i;
1494
1495     if (!_ico_sys_config) {
1496         (void)ico_uxf_getSysConfig();
1497     }
1498     if ((inputdev < 0) || (inputdev >= _ico_sys_config->inputdevNum) ||
1499         (_ico_sys_config->inputdev[inputdev].inputswNum <= 0))  {
1500         apfw_critical("ico_uxf_getSysInputswByName: can not read configuration file");
1501         return 0;
1502     }
1503
1504     if ((sinputsw) && (*sinputsw != 0)) {
1505         for (i = 0; i < _ico_sys_config->inputdev[inputdev].inputswNum; i++)    {
1506             if (strcasecmp(sinputsw, _ico_sys_config->inputdev[inputdev].inputsw[i].name)
1507                     == 0)    {
1508                 return i;
1509             }
1510         }
1511     }
1512     apfw_warn("ico_uxf_getSysInputswByName(%s) Illegal sw name",
1513               sinputsw ? sinputsw : "(NULL)");
1514     return 0;
1515 }
1516
1517 /*--------------------------------------------------------------------------*/
1518 /**
1519  * @brief   ico_uxf_closeSysConfig: close and release system configuration table
1520  *
1521  * @param       none
1522  * @return      none
1523  */
1524 /*--------------------------------------------------------------------------*/
1525 ICO_APF_API void
1526 ico_uxf_closeSysConfig(void)
1527 {
1528     if (_ico_sys_config != NULL)    {
1529         g_free(_ico_sys_config->host);
1530         g_free(_ico_sys_config->display);
1531         g_free(_ico_sys_config);
1532         _ico_sys_config = NULL;
1533     }
1534 }
1535