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