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