2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
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
10 * @brief user experiance library(read apprication's configuration file)
17 #include <sys/types.h>
26 #include "ico_apf_log.h"
27 #include "ico_apf_apimacro.h"
28 #include "ico_uxf_conf_common.h"
30 #define APP_CONF_AIL_NULL_STR "(null)"
32 static Ico_Uxf_App_Config *readAilApplist(void);
33 static void Ico_Uxf_conf_remakeAppHash(void);
35 static Ico_Uxf_App_Config *_ico_app_config = NULL;
36 static Ico_Uxf_Sys_Config *sys_config = NULL;
37 static GKeyFile *sappfile = NULL;
40 /*--------------------------------------------------------------------------*/
42 * @brief ico_uxf_getAppConfig: get application configurations
45 * @return application configuration table
46 * @retval !=NULL success(application configuration table address)
47 * @retval ==NULL error(can not read configuration files)
49 /*--------------------------------------------------------------------------*/
50 ICO_APF_API const Ico_Uxf_App_Config *
51 ico_uxf_getAppConfig(void)
53 if (_ico_app_config) {
54 return _ico_app_config;
56 _ico_app_config = g_new0(Ico_Uxf_App_Config,1);
57 return readAilApplist();
60 /*--------------------------------------------------------------------------*/
62 * @brief infoAilpkg: callback function for configuration from AppCore(static function)
64 * @param[in] appinfo AppCore(AIL) application information
65 * @param[in] data user data(application index)
67 * @retval AIL_CB_RET_CONTINUE success(continue next application)
68 * @retval AIL_CB_RET_CANCEL error(stop all application search)
70 /*--------------------------------------------------------------------------*/
72 infoAilpkg(const ail_appinfo_h appinfo, void *data)
83 char add_category[256];
87 Ico_Uxf_conf_application *apptbl;
89 /* get package name for appid */
90 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
91 if (strcmp(package, APP_CONF_AIL_NULL_STR) == 0) {
95 ail_appinfo_get_str(appinfo, AIL_PROP_ICON_STR, &icon);
96 if (strcmp(icon, APP_CONF_AIL_NULL_STR) == 0) {
99 else if (icon != NULL) {
101 memset(&buff, 0, sizeof(buff));
102 if (stat(icon, &buff) == 0) {
103 if (S_ISDIR(buff.st_mode)) {
114 ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &name);
115 if (strcmp(name, APP_CONF_AIL_NULL_STR) == 0) {
119 /* get default category of this application */
122 app_category = g_key_file_get_string(sappfile, "app-attributes", package, &error);
124 g_clear_error(&error);
126 app_category = g_key_file_get_string(sappfile, "app-attributes", name, &error);
129 g_clear_error(&error);
130 apfw_trace("infoAilpkg: %s(%s) dose not has app-attributes", package, name);
133 apfw_trace("infoAilpkg: %s(%s) has app-category=%s", package, name, app_category);
134 strncpy(add_category, app_category, sizeof(add_category)-2);
135 add_category[sizeof(add_category)-2] = 0;
136 i = strlen(add_category);
138 if (add_category[i-1] != ';') {
139 strcpy(&add_category[i], ";");
143 g_clear_error(&error);
146 ail_appinfo_get_str(appinfo, AIL_PROP_CATEGORIES_STR, &category);
147 if (strcmp(category, APP_CONF_AIL_NULL_STR) != 0) {
148 apfw_trace("infoAilpkg: %s + %s", add_category, category);
149 i = strlen(add_category);
150 strncpy(&add_category[i], category, sizeof(add_category)-i-1);
151 add_category[sizeof(add_category)-i-1] = 0;
153 if (add_category[0]) {
154 category = add_category;
161 ail_appinfo_get_str(appinfo, AIL_PROP_TYPE_STR, &type);
162 if (strcmp(type, APP_CONF_AIL_NULL_STR) == 0) {
166 ail_appinfo_get_str(appinfo, AIL_PROP_EXEC_STR, &exec);
167 if (strcmp(exec, APP_CONF_AIL_NULL_STR) == 0) {
171 if ((package != NULL) && (*package != 0)) {
172 apptbl = &_ico_app_config->application[_ico_app_config->applicationNum];
173 apptbl->appid = strdup(package);
175 apptbl->icon_key_name = strdup(icon);
178 apptbl->icon_key_name = strdup("\0");
180 if ((name != NULL) && (*name != 0)) {
181 apptbl->name = strdup(name);
184 apptbl->name = strdup(package);
187 /* set default values */
188 apptbl->hostId = sys_config->misc.default_hostId;
189 apptbl->kindId = sys_config->misc.default_kindId;
190 apptbl->categoryId = sys_config->misc.default_categoryId;
193 if ((icon != NULL) && (*icon != 0)) {
195 ail_appinfo_get_bool(appinfo, AIL_PROP_NODISPLAY_BOOL, &bval);
196 apptbl->noicon = (int)bval;
199 apfw_trace("infoAilpkg: %s(%s) has no icon", package, name);
203 /* analize categorys for extended attributes */
207 int dispidx = sys_config->misc.default_displayId;;
208 int soundidx = sys_config->misc.default_soundId;;
209 int inputidx = sys_config->misc.default_inputdevId;
210 Ico_Uxf_conf_display *display;
211 Ico_Uxf_conf_sound *sound;
214 apfw_trace("Ail.%d category=%s", _ico_app_config->applicationNum, category);
218 if ((category[i] == 0) || (category[i] == ';')) {
220 if (k >= ((int)sizeof(work)-1)) k = sizeof(work)-1;
221 memcpy(work, &category[j], k);
225 /* find running host */
226 if (strncasecmp(work, "run=", 4) == 0) {
229 for (k = 0; k < sys_config->hostNum; k++) {
230 if (strcasecmp(&work[found], sys_config->host[k].name) == 0) {
231 apptbl->hostId = sys_config->host[k].id;
237 apfw_error("infoAilpkg: [%s] unknown running host", work);
241 if (strncasecmp(work, "kind=", 5) == 0) {
244 for (k = 0; k < sys_config->kindNum; k++) {
245 if (strcasecmp(&work[found],
246 sys_config->kind[k].name) == 0) {
247 apptbl->kindId = sys_config->kind[k].id;
254 apfw_error("infoAilpkg: [%s] unknown kind", work);
258 if (strncasecmp(work, "category=", 9) == 0) {
261 for (k = 0; k < sys_config->categoryNum; k++) {
262 if (strcasecmp(&work[found],
263 sys_config->category[k].name) == 0) {
264 apptbl->categoryId = sys_config->category[k].id;
271 apfw_error("infoAilpkg: [%s] unknown category", work);
275 (strncasecmp(work, "display", 7) == 0)) {
276 if (work[7] == '=') {
280 else if ((work[7] == '.') && (work[9] == '=')) {
281 dispidx = work[8] - '0';
283 if ((dispidx < 0) || (dispidx >= ICO_UXF_APPDISPLAY_MAX)) {
284 apfw_error("infoAilpkg: [%s] unknown display number", work);
290 apfw_error("infoAilpkg: [%s] unknown display number", work);
294 if (apptbl->displayzoneNum <= dispidx) {
295 apptbl->display[dispidx].displayId
296 = sys_config->misc.default_displayId;
297 apptbl->display[dispidx].layerId
298 = sys_config->misc.default_layerId;
299 apptbl->display[dispidx].zoneId
300 = sys_config->misc.default_dispzoneId;
302 for (k = 0; k < sys_config->displayNum; k++) {
303 if (strcasecmp(&work[found],
304 sys_config->display[k].name) == 0) {
305 apptbl->display[dispidx].displayId
306 = sys_config->display[k].id;
307 if (apptbl->displayzoneNum <= dispidx) {
308 apptbl->displayzoneNum = dispidx + 1;
316 apfw_error("infoAilpkg: [%s] unknown display", work);
318 /* find display layer */
320 (strncasecmp(work, "layer", 5) == 0)) {
321 if (work[5] == '=') {
325 else if ((work[5] == '.') && (work[7] == '=')) {
326 dispidx = work[6] - '0';
328 if ((dispidx < 0) || (dispidx >= ICO_UXF_APPDISPLAY_MAX)) {
329 apfw_error("infoAilpkg: [%s] unknown display number", work);
335 apfw_error("infoAilpkg: [%s] unknown display number", work);
339 if (apptbl->displayzoneNum <= dispidx) {
340 apptbl->display[dispidx].displayId
341 = sys_config->misc.default_displayId;
342 apptbl->display[dispidx].layerId
343 = sys_config->misc.default_layerId;
344 apptbl->display[dispidx].zoneId
345 = sys_config->misc.default_dispzoneId;
347 display = &sys_config->display[apptbl->display[dispidx].displayId];
349 for (k = 0; k < display->layerNum; k++) {
350 if (strcasecmp(&work[found], display->layer[k].name) == 0) {
351 apptbl->display[dispidx].layerId = display->layer[k].id;
352 if (apptbl->displayzoneNum <= dispidx) {
353 apptbl->displayzoneNum = dispidx + 1;
361 apfw_error("infoAilpkg: [%s] unknown layer", work);
363 /* find display zone */
365 (strncasecmp(work, "dispzone", 8) == 0)) {
366 if (work[8] == '=') {
370 else if ((work[8] == '.') && (work[10] == '=')) {
371 dispidx = work[9] - '0';
373 if ((dispidx < 0) || (dispidx >= ICO_UXF_APPDISPLAY_MAX)) {
374 apfw_error("infoAilpkg: [%s] unknown display number", work);
380 apfw_error("infoAilpkg: [%s] unknown display number", work);
384 if (apptbl->displayzoneNum <= dispidx) {
385 apptbl->display[dispidx].displayId
386 = sys_config->misc.default_displayId;
387 apptbl->display[dispidx].layerId
388 = sys_config->misc.default_layerId;
389 apptbl->display[dispidx].zoneId
390 = sys_config->misc.default_dispzoneId;
392 display = &sys_config->display[apptbl->display[dispidx].displayId];
394 for (k = 0; k < display->zoneNum; k++) {
395 if (strcasecmp(&work[found], display->zone[k].name) == 0) {
396 apptbl->display[dispidx].zoneId = display->zone[k].id;
397 if (apptbl->displayzoneNum <= dispidx) {
398 apptbl->displayzoneNum = dispidx + 1;
406 apfw_error("infoAilpkg: [%s] unknown display zone", work);
409 /* find sound zone */
411 (strncasecmp(work, "soundzone", 9) == 0)) {
412 if (work[9] == '=') {
416 else if ((work[9] == '.') && (work[11] == '=')) {
417 soundidx = work[10] - '0';
419 if ((soundidx < 0) || (soundidx >= ICO_UXF_APPSOUND_MAX)) {
420 apfw_error("infoAilpkg: [%s] unknown sound number", work);
426 apfw_error("infoAilpkg: [%s] unknown sound number", work);
430 if (apptbl->soundzoneNum <= soundidx) {
431 apptbl->sound[soundidx].soundId
432 = sys_config->misc.default_soundId;
433 apptbl->sound[soundidx].zoneId
434 = sys_config->misc.default_soundzoneId;
436 sound = &sys_config->sound[apptbl->sound[soundidx].soundId];
438 for (k = 0; k < sound->zoneNum; k++) {
439 if (strcasecmp(&work[found], sound->zone[k].name) == 0) {
440 apptbl->sound[soundidx].zoneId = sound->zone[k].id;
441 if (apptbl->soundzoneNum <= soundidx) {
442 apptbl->soundzoneNum = soundidx + 1;
450 apfw_error("infoAilpkg: [%s] unknown sound zone", work);
455 (strncasecmp(work, "sound", 5) == 0)) {
456 if (work[5] == '=') {
460 else if ((work[5] == '.') && (work[7] == '=')) {
461 soundidx = work[6] - '0';
463 if ((soundidx < 0) || (soundidx >= ICO_UXF_APPSOUND_MAX)) {
464 apfw_error("infoAilpkg: [%s] unknown sound number", work);
470 apfw_error("infoAilpkg: [%s] unknown sound number", work);
474 if (apptbl->soundzoneNum <= soundidx) {
475 apptbl->sound[soundidx].soundId
476 = sys_config->misc.default_soundId;
477 apptbl->sound[soundidx].zoneId
478 = sys_config->misc.default_soundzoneId;
480 for (k = 0; k < sys_config->soundNum; k++) {
481 if (strcasecmp(&work[found], sys_config->sound[k].name) == 0) {
482 apptbl->sound[soundidx].soundId = sys_config->sound[k].id;
483 if (apptbl->soundzoneNum <= soundidx) {
484 apptbl->soundzoneNum = soundidx + 1;
492 apfw_error("infoAilpkg: [%s] unknown sound", work);
495 /* find input device */
497 (strncasecmp(work, "input", 5) == 0)) {
498 if (work[5] == '=') {
502 else if ((work[5] == '.') && (work[7] == '=')) {
503 inputidx = work[6] - '0';
504 if ((inputidx < 0) || (inputidx >= ICO_UXF_APPINPUT_MAX)) {
505 apfw_error("infoAilpkg: [%s] unknown input number", work);
512 apfw_error("infoAilpkg: [%s] unknown input number", work);
515 if (apptbl->inputdevNum <= inputidx) {
516 apptbl->input[inputidx].inputdevId
517 = sys_config->misc.default_inputdevId;
519 for (k = 0; k < sys_config->inputdevNum; k++) {
520 m = strlen(sys_config->inputdev[k].name);
521 if (strncasecmp(&work[found],
522 sys_config->inputdev[k].name, m) == 0) {
523 if (work[found+m] != '.') {
524 apfw_error("infoAilpkg: [%s] unknown input sw", work);
527 apptbl->input[inputidx].inputdevId
528 = sys_config->inputdev[k].id;
530 for (n = 0; n < sys_config->inputdev[k].inputswNum; n++) {
531 if (strcasecmp(&work[m],
532 sys_config->inputdev[k].inputsw[n].name)
534 apptbl->input[inputidx].inputswId = n;
538 if (n < sys_config->inputdev[k].inputswNum) {
539 if (apptbl->inputdevNum <= inputidx) {
540 apptbl->inputdevNum = inputidx + 1;
544 apfw_error("infoAilpkg: [%s] unknown input sw", work);
550 if (k >= sys_config->inputdevNum) {
551 apfw_error("infoAilpkg: [%s] unknown input device", work);
557 apfw_error("infoAilpkg: [%s] unknown input", work);
561 if ((found == 0) && (work[0] != 0)) {
562 if (strcasecmp(work, "auto") == 0) {
563 apptbl->autostart = 1;
565 else if (strcasecmp(work, "noauto") == 0) {
566 apptbl->autostart = 0;
569 apfw_error("infoAilpkg: [%s] unknown key", work);
572 if (category[i] == 0) break;
577 apptbl->exec = strdup(exec);
578 apptbl->type = strdup(type);
579 if (apptbl->displayzoneNum == 0) {
580 apptbl->displayzoneNum = 1;
581 apptbl->display[0].displayId = sys_config->misc.default_displayId;
582 apptbl->display[0].layerId = sys_config->misc.default_layerId;
583 apptbl->display[0].zoneId = sys_config->misc.default_dispzoneId;
585 if (apptbl->soundzoneNum == 0) {
586 apptbl->soundzoneNum = 1;
587 apptbl->sound[0].soundId = sys_config->misc.default_soundId;
588 apptbl->sound[0].zoneId = sys_config->misc.default_soundzoneId;
590 apfw_trace("Ail.%d: appid=%s name=%s exec=%s type=%s",
591 _ico_app_config->applicationNum, apptbl->appid, apptbl->name,
592 apptbl->exec, apptbl->type);
593 apfw_trace("Ail.%d: categ=%d kind=%d disp=%d layer=%d zone=%d "
594 "sound=%d zone=%d auto=%d noicon=%d",
595 _ico_app_config->applicationNum, apptbl->categoryId, apptbl->kindId,
596 apptbl->display[0].displayId, apptbl->display[0].layerId,
597 apptbl->display[0].zoneId, apptbl->sound[0].soundId,
598 apptbl->sound[0].zoneId, apptbl->autostart, apptbl->noicon);
599 _ico_app_config->applicationNum++;
604 if (_ico_app_config->applicationNum > num)
605 return AIL_CB_RET_CANCEL;
607 return AIL_CB_RET_CONTINUE;
610 /*--------------------------------------------------------------------------*/
612 * @brief readAilApplist: get all application configuration from AppCore(static function)
615 * @return application configuration table
616 * @retval !=NULL success(application configuration table address)
617 * @retval ==NULL error(can not read configuration files)
619 /*--------------------------------------------------------------------------*/
620 static Ico_Uxf_App_Config *
625 GError *error = NULL;
627 /* get system configuration */
628 sys_config = (Ico_Uxf_Sys_Config *)ico_uxf_getSysConfig();
630 apfw_error("readAilApplist: can not read system configuration");
634 /* read system configuration file for application default category */
635 sappfile = g_key_file_new();
637 GString* filepath = g_string_new("xx");
638 g_string_printf(filepath, "%s/%s", sys_config->misc.confdir, ICO_UXF_CONFIG_APPATTR);
640 if (! g_key_file_load_from_file(sappfile, filepath->str,
641 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
643 apfw_error("readAilApplist: %s %s", (char *)filepath->str, error->message);
644 g_key_file_free(sappfile);
647 g_string_free(filepath, TRUE);
650 ret = ail_filter_count_appinfo(NULL, &num);
651 if (ret != AIL_ERROR_OK) {
653 g_key_file_free(sappfile);
658 apfw_trace("readAilApplist: number of off AIL package = %d", num);
660 ail_filter_new(&filter);
661 ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "menu");
662 ail_filter_count_appinfo(filter, &num);
663 apfw_trace("readAilApplist: number of menu AIL package = %d", num);
664 ail_filter_destroy(filter);
666 ail_filter_new(&filter);
667 ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
668 ail_filter_count_appinfo(filter, &wnum);
669 apfw_trace("readAilApplist: number of Application AIL package = %d", wnum);
670 ail_filter_destroy(filter);
673 _ico_app_config->application = g_new0(Ico_Uxf_conf_application, num);
675 ail_filter_new(&filter);
676 ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "menu");
677 ail_filter_list_appinfo_foreach(filter, infoAilpkg, (void *)num);
678 ail_filter_destroy(filter);
680 ail_filter_new(&filter);
681 ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
682 ail_filter_list_appinfo_foreach(filter, infoAilpkg, (void *)num);
683 ail_filter_destroy(filter);
685 /* create Hash Table */
686 Ico_Uxf_conf_remakeAppHash();
689 g_key_file_free(sappfile);
692 return _ico_app_config;
695 /*--------------------------------------------------------------------------*/
697 * @brief ico_uxf_closeAppConfig: close application configuration table
702 /*--------------------------------------------------------------------------*/
704 ico_uxf_closeAppConfig(void)
706 if(_ico_app_config != NULL){
707 g_free(_ico_app_config->application);
708 g_free(_ico_app_config);
709 _ico_app_config = NULL;
713 /*--------------------------------------------------------------------------*/
715 * @brief Ico_Uxf_conf_remakeAppHash: make application hash table(static function)
720 /*--------------------------------------------------------------------------*/
722 Ico_Uxf_conf_remakeAppHash(void)
726 Ico_Uxf_conf_application *app;
728 memset(_ico_app_config->hashnametable, 0, sizeof(_ico_app_config->hashnametable));
730 for (i = 0; i < _ico_app_config->applicationNum; i++) {
732 _ico_app_config->application[i].nextidhash = NULL;
733 hash = ICO_UXF_MISC_HASHBYID(i);
734 app = _ico_app_config->hashidtable[hash];
736 _ico_app_config->hashidtable[hash] = &_ico_app_config->application[i];
739 while (app->nextidhash) {
740 app = app->nextidhash;
742 app->nextidhash = &_ico_app_config->application[i];
745 _ico_app_config->application[i].nextnamehash = NULL;
746 hash = ICO_UXF_MISC_HASHBYNAME(_ico_app_config->application[i].appid);
747 app = _ico_app_config->hashnametable[hash];
749 _ico_app_config->hashnametable[hash] = &_ico_app_config->application[i];
752 while (app->nextnamehash) {
753 app = app->nextnamehash;
755 app->nextnamehash = &_ico_app_config->application[i];
760 /*--------------------------------------------------------------------------*/
762 * @brief ico_uxf_getAppByAppid: get application configuration by application Id
764 * @param[in] appid application Id
765 * @return application configuration table
766 * @retval !=NULL success(application configuration table address)
767 * @retval ==NULL error(application dose not exist)
769 /*--------------------------------------------------------------------------*/
770 ICO_APF_API const Ico_Uxf_conf_application *
771 ico_uxf_getAppByAppid(const char *appid)
773 Ico_Uxf_conf_application *app;
775 if (!_ico_app_config) {
776 (void)ico_uxf_getAppConfig();
778 app = _ico_app_config->hashnametable[ICO_UXF_MISC_HASHBYNAME(appid)];
781 if (strcasecmp(app->appid, appid) == 0) break;
782 app = app->nextnamehash;
785 apfw_warn("ico_uxf_getAppByAppid: appid(%s) dose not exist", appid);
790 /*--------------------------------------------------------------------------*/
792 * @brief ico_uxf_getAppByName: get application configuration by application name
794 * @param[in] name application name
795 * @return application configuration table
796 * @retval !=NULL success(application configuration table address)
797 * @retval ==NULL error(application dose not exist)
799 /*--------------------------------------------------------------------------*/
800 ICO_APF_API const Ico_Uxf_conf_application *
801 ico_uxf_getAppByName(const char *name)
804 Ico_Uxf_conf_application *app = NULL;
806 if (!_ico_app_config) {
807 (void)ico_uxf_getAppConfig();
810 for (i = 0; i < _ico_app_config->applicationNum; i++) {
811 if (strcasecmp(_ico_app_config->application[i].name, name) == 0) {
812 app = &_ico_app_config->application[i];
817 apfw_warn("ico_uxf_getAppByName: name(%s) dose not exist", name);
822 /*--------------------------------------------------------------------------*/
824 * @brief ico_uxf_getAppDisplay: get application display
826 * @param[in] app application configuration table
827 * @param[in] idx display zone index
828 * @param[out] x zone X coodinate
829 * @param[out] y zone Y coodinate
830 * @param[out] width zone width
831 * @param[out] height zone height
833 * @retval ICO_UXF_EOK succes
834 * @retval ICO_UXF_EINVAL error(illegal idx)
835 * @retval ICO_UXF_ENOSYS error(can not read configuration files)
837 /*--------------------------------------------------------------------------*/
839 ico_uxf_getAppDisplay(const Ico_Uxf_conf_application *app, const int idx,
840 int *x, int *y, int *width, int *height)
842 Ico_Uxf_conf_display_zone *zone;
845 return ICO_UXF_ENOSYS;
847 if ((! app) || (idx < 0) || (idx >= app->displayzoneNum)) {
848 return ICO_UXF_EINVAL;
851 zone = &sys_config->display[app->display[idx].displayId].zone[app->display[idx].zoneId];
855 if (width) *width = zone->width;
856 if (height) *height = zone->height;