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 <package-manager.h>
28 #include "ico_apf_log.h"
29 #include "ico_apf_apimacro.h"
30 #include "ico_uxf_conf_common.h"
32 /*==============================================================================*/
34 /*==============================================================================*/
35 #define APP_CONF_AIL_NULL_STR "(NULL)"
37 #define APP_CONF_EVENT_OK (0)
38 #define APP_CONF_EVENT_FAIL (1)
40 typedef struct _conf_pkgmgr_event conf_pkgmgr_event_t;
42 struct _conf_pkgmgr_event {
43 conf_pkgmgr_event_t *next;
44 char pkg_name[ICO_UXF_MAX_PROCESS_NAME];
48 /*==============================================================================*/
49 /* define static function prototype */
50 /*==============================================================================*/
51 static Ico_Uxf_App_Config *readAilApplist(void);
52 static void ico_uxf_conf_remakeAppHash(void);
53 static int ico_uxf_conf_pkgmgrEvent(int req_id, const char *pkg_type,
54 const char *pkg_name, const char *key, const char *val,
55 const void *pmsg, void *data);
56 static int ico_uxf_conf_addPkgmgrEventListener(void);
57 static int ico_uxf_conf_startEvent(const char *pkg_name, int type);
58 static int ico_uxf_conf_endEvent(const char *pkg_name, int status);
60 /*==============================================================================*/
62 /*==============================================================================*/
63 static Ico_Uxf_App_Config *_ico_app_config = NULL;
64 static Ico_Uxf_App_Config *_ico_app_config_update = NULL;
65 static Ico_Uxf_Sys_Config *sys_config = NULL;
66 static GKeyFile *sappfile = NULL;
67 static char *default_icon = NULL;
69 static pkgmgr_client *conf_pc = NULL;
70 static conf_pkgmgr_event_t *conf_prog_event = NULL;
71 static Ico_Uxf_AppUpdata_Cb conf_cb_func = NULL;
73 /*--------------------------------------------------------------------------*/
75 * @brief ico_uxf_getAppConfig: get application configurations
78 * @return application configuration table
79 * @retval !=NULL success(application configuration table address)
80 * @retval ==NULL error(can not read configuration files)
82 /*--------------------------------------------------------------------------*/
83 ICO_APF_API const Ico_Uxf_App_Config *
84 ico_uxf_getAppConfig(void)
86 if (_ico_app_config) {
87 return _ico_app_config;
89 _ico_app_config = g_new0(Ico_Uxf_App_Config,1);
90 _ico_app_config_update = _ico_app_config;
91 return readAilApplist();
94 /*--------------------------------------------------------------------------*/
96 * @brief infoAilpkg: callback function for configuration from AppCore(static function)
98 * @param[in] appinfo AppCore(AIL) application information
99 * @param[in] data user data(application index)
101 * @retval AIL_CB_RET_CONTINUE success(continue next application)
102 * @retval AIL_CB_RET_CANCEL error(stop all application search)
104 /*--------------------------------------------------------------------------*/
106 infoAilpkg(const ail_appinfo_h appinfo, void *data)
117 int app_category_type;
118 char add_category[400];
119 int add_category_len;
124 Ico_Uxf_conf_application *apptbl;
126 _ico_app_config_update->ailNum++;
128 /* get package name for appid */
129 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
130 if (strcasecmp(package, APP_CONF_AIL_NULL_STR) == 0) {
134 ail_appinfo_get_str(appinfo, AIL_PROP_ICON_STR, &icon);
135 if (strcasecmp(icon, APP_CONF_AIL_NULL_STR) == 0) {
138 if ((icon == NULL) || (*icon == 0)) {
142 ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &name);
143 if (strcasecmp(name, APP_CONF_AIL_NULL_STR) == 0) {
147 /* get default category of this application */
150 app_category = g_key_file_get_string(sappfile, "app-attributes", package, &error);
152 app_category_type = 0;
155 g_clear_error(&error);
157 app_category = g_key_file_get_string(sappfile, "app-attributes", name, &error);
159 app_category_type = 1;
162 add_category_len = 0;
164 g_clear_error(&error);
165 apfw_trace("infoAilpkg: %s(%s) dose not has app-attributes", package, name);
169 strncpy(&add_category[add_category_len],
170 app_category, sizeof(add_category)-add_category_len-2);
171 add_category[sizeof(add_category)-2] = 0;
172 add_category_len = strlen(add_category);
173 if (add_category_len > 0) {
174 if (add_category[add_category_len-1] != ';') {
175 strcpy(&add_category[add_category_len++], ";");
178 snprintf(work, sizeof(work)-1, "%s.%d",
179 app_category_type == 0 ? package : name, i);
181 app_category = g_key_file_get_string(sappfile, "app-attributes", work, &error);
183 g_clear_error(&error);
187 apfw_trace("infoAilpkg: %s(%s) has app-category=%s", package, name, add_category);
189 g_clear_error(&error);
192 ail_appinfo_get_str(appinfo, AIL_PROP_CATEGORIES_STR, &category);
193 if (strcasecmp(category, APP_CONF_AIL_NULL_STR) != 0) {
194 apfw_trace("infoAilpkg: %s + %s", add_category, category);
195 strncpy(&add_category[add_category_len],
196 category, sizeof(add_category)-add_category_len-1);
197 add_category[sizeof(add_category)-1] = 0;
199 if (add_category[0]) {
200 category = add_category;
207 ail_appinfo_get_str(appinfo, AIL_PROP_TYPE_STR, &type);
209 ail_appinfo_get_str(appinfo, AIL_PROP_EXEC_STR, &exec);
210 if (strcasecmp(exec, APP_CONF_AIL_NULL_STR) == 0) {
214 if ((package != NULL) && (*package != 0)) {
215 apptbl = &_ico_app_config_update->application[_ico_app_config_update->applicationNum];
216 apptbl->appid = strdup(package);
218 if ((stat(icon, &buff) == 0) &&
219 (! S_ISDIR(buff.st_mode))) {
220 apptbl->icon_key_name = strdup(icon);
223 apptbl->icon_key_name = "\0";
227 apptbl->icon_key_name = "\0";
229 if ((name != NULL) && (*name != 0)) {
230 apptbl->name = strdup(name);
233 apptbl->name = strdup(package);
235 if (strcasecmp(type, APP_CONF_AIL_NULL_STR) == 0) {
239 apptbl->type = strdup(type);
242 /* set default values */
243 apptbl->hostId = sys_config->misc.default_hostId;
244 apptbl->kindId = sys_config->misc.default_kindId;
245 apptbl->categoryId = sys_config->misc.default_categoryId;
246 apptbl->invisiblecpu = 100;
249 if ((apptbl->icon_key_name != NULL) && (*apptbl->icon_key_name != 0)) {
251 ail_appinfo_get_bool(appinfo, AIL_PROP_NODISPLAY_BOOL, &bval);
252 apptbl->noicon = (int)bval;
255 apfw_trace("infoAilpkg: %s(%s) has no icon", package, name);
259 /* analize categorys for extended attributes */
263 int dispidx = sys_config->misc.default_displayId;;
264 int soundidx = sys_config->misc.default_soundId;;
265 int inputidx = sys_config->misc.default_inputdevId;
266 Ico_Uxf_conf_display *display;
267 Ico_Uxf_conf_sound *sound;
270 apfw_trace("Ail.%d category=%s", _ico_app_config_update->applicationNum, category);
274 if ((category[i] == 0) || (category[i] == ';')) {
276 if (k >= ((int)sizeof(work)-1)) k = sizeof(work)-1;
277 memcpy(work, &category[j], k);
281 /* find running host */
282 if (strncasecmp(work, "run=", 4) == 0) {
285 for (k = 0; k < sys_config->hostNum; k++) {
286 if (strcasecmp(&work[found], sys_config->host[k].name) == 0) {
287 apptbl->hostId = sys_config->host[k].id;
293 apfw_error("infoAilpkg: [%s] unknown running host", work);
297 if (strncasecmp(work, "kind=", 5) == 0) {
300 for (k = 0; k < sys_config->kindNum; k++) {
301 if (strcasecmp(&work[found],
302 sys_config->kind[k].name) == 0) {
303 apptbl->kindId = sys_config->kind[k].id;
310 apfw_error("infoAilpkg: [%s] unknown kind", work);
314 if (strncasecmp(work, "category=", 9) == 0) {
317 for (k = 0; k < sys_config->categoryNum; k++) {
318 if (strcasecmp(&work[found],
319 sys_config->category[k].name) == 0) {
320 apptbl->categoryId = sys_config->category[k].id;
327 apfw_error("infoAilpkg: [%s] unknown category", work);
331 if (strncasecmp(work, "type=", 5) == 0) {
336 apptbl->type = strdup(&work[5]);
341 (strncasecmp(work, "display", 7) == 0)) {
342 if (work[7] == '=') {
346 else if ((work[7] == '.') && (work[9] == '=')) {
347 dispidx = work[8] - '0';
349 if ((dispidx < 0) || (dispidx >= ICO_UXF_APPDISPLAY_MAX)) {
350 apfw_error("infoAilpkg: [%s] unknown display number", work);
356 apfw_error("infoAilpkg: [%s] unknown display number", work);
360 if (apptbl->displayzoneNum <= dispidx) {
361 apptbl->display[dispidx].displayId
362 = sys_config->misc.default_displayId;
363 apptbl->display[dispidx].layerId
364 = sys_config->misc.default_layerId;
365 apptbl->display[dispidx].zoneId
366 = sys_config->misc.default_dispzoneId;
368 for (k = 0; k < sys_config->displayNum; k++) {
369 if (strcasecmp(&work[found],
370 sys_config->display[k].name) == 0) {
371 apptbl->display[dispidx].displayId
372 = sys_config->display[k].id;
373 if (apptbl->displayzoneNum <= dispidx) {
374 apptbl->displayzoneNum = dispidx + 1;
382 apfw_error("infoAilpkg: [%s] unknown display", work);
384 /* find display layer */
386 (strncasecmp(work, "layer", 5) == 0)) {
387 if (work[5] == '=') {
391 else if ((work[5] == '.') && (work[7] == '=')) {
392 dispidx = work[6] - '0';
394 if ((dispidx < 0) || (dispidx >= ICO_UXF_APPDISPLAY_MAX)) {
395 apfw_error("infoAilpkg: [%s] unknown display number", work);
401 apfw_error("infoAilpkg: [%s] unknown display number", work);
405 if (apptbl->displayzoneNum <= dispidx) {
406 apptbl->display[dispidx].displayId
407 = sys_config->misc.default_displayId;
408 apptbl->display[dispidx].layerId
409 = sys_config->misc.default_layerId;
410 apptbl->display[dispidx].zoneId
411 = sys_config->misc.default_dispzoneId;
413 display = &sys_config->display[apptbl->display[dispidx].displayId];
415 for (k = 0; k < display->layerNum; k++) {
416 if (strcasecmp(&work[found], display->layer[k].name) == 0) {
417 apptbl->display[dispidx].layerId = display->layer[k].id;
418 if (apptbl->displayzoneNum <= dispidx) {
419 apptbl->displayzoneNum = dispidx + 1;
427 apfw_error("infoAilpkg: [%s] unknown layer", work);
429 /* find display zone */
431 (strncasecmp(work, "dispzone", 8) == 0)) {
432 if (work[8] == '=') {
436 else if ((work[8] == '.') && (work[10] == '=')) {
437 dispidx = work[9] - '0';
439 if ((dispidx < 0) || (dispidx >= ICO_UXF_APPDISPLAY_MAX)) {
440 apfw_error("infoAilpkg: [%s] unknown display number", work);
446 apfw_error("infoAilpkg: [%s] unknown display number", work);
450 if (apptbl->displayzoneNum <= dispidx) {
451 apptbl->display[dispidx].displayId
452 = sys_config->misc.default_displayId;
453 apptbl->display[dispidx].layerId
454 = sys_config->misc.default_layerId;
455 apptbl->display[dispidx].zoneId
456 = sys_config->misc.default_dispzoneId;
458 display = &sys_config->display[apptbl->display[dispidx].displayId];
460 for (k = 0; k < display->zoneNum; k++) {
461 if (strcasecmp(&work[found], display->zone[k].name) == 0) {
462 apptbl->display[dispidx].zoneId = display->zone[k].id;
463 if (apptbl->displayzoneNum <= dispidx) {
464 apptbl->displayzoneNum = dispidx + 1;
472 apfw_error("infoAilpkg: [%s] unknown display zone", work);
475 /* find sound zone */
477 (strncasecmp(work, "soundzone", 9) == 0)) {
478 if (work[9] == '=') {
482 else if ((work[9] == '.') && (work[11] == '=')) {
483 soundidx = work[10] - '0';
485 if ((soundidx < 0) || (soundidx >= ICO_UXF_APPSOUND_MAX)) {
486 apfw_error("infoAilpkg: [%s] unknown sound number", work);
492 apfw_error("infoAilpkg: [%s] unknown sound number", work);
496 if (apptbl->soundzoneNum <= soundidx) {
497 apptbl->sound[soundidx].soundId
498 = sys_config->misc.default_soundId;
499 apptbl->sound[soundidx].zoneId
500 = sys_config->misc.default_soundzoneId;
502 sound = &sys_config->sound[apptbl->sound[soundidx].soundId];
504 for (k = 0; k < sound->zoneNum; k++) {
505 if (strcasecmp(&work[found], sound->zone[k].name) == 0) {
506 apptbl->sound[soundidx].zoneId = sound->zone[k].id;
507 if (apptbl->soundzoneNum <= soundidx) {
508 apptbl->soundzoneNum = soundidx + 1;
516 apfw_error("infoAilpkg: [%s] unknown sound zone", work);
521 (strncasecmp(work, "sound", 5) == 0)) {
522 if (work[5] == '=') {
526 else if ((work[5] == '.') && (work[7] == '=')) {
527 soundidx = work[6] - '0';
529 if ((soundidx < 0) || (soundidx >= ICO_UXF_APPSOUND_MAX)) {
530 apfw_error("infoAilpkg: [%s] unknown sound number", work);
536 apfw_error("infoAilpkg: [%s] unknown sound number", work);
540 if (apptbl->soundzoneNum <= soundidx) {
541 apptbl->sound[soundidx].soundId
542 = sys_config->misc.default_soundId;
543 apptbl->sound[soundidx].zoneId
544 = sys_config->misc.default_soundzoneId;
546 for (k = 0; k < sys_config->soundNum; k++) {
547 if (strcasecmp(&work[found], sys_config->sound[k].name) == 0) {
548 apptbl->sound[soundidx].soundId = sys_config->sound[k].id;
549 if (apptbl->soundzoneNum <= soundidx) {
550 apptbl->soundzoneNum = soundidx + 1;
558 apfw_error("infoAilpkg: [%s] unknown sound", work);
561 /* find input device */
563 (strncasecmp(work, "input", 5) == 0)) {
564 if (work[5] == '=') {
568 else if ((work[5] == '.') && (work[7] == '=')) {
569 inputidx = work[6] - '0';
570 if ((inputidx < 0) || (inputidx >= ICO_UXF_APPINPUT_MAX)) {
571 apfw_error("infoAilpkg: [%s] unknown input number", work);
578 apfw_error("infoAilpkg: [%s] unknown input number", work);
581 if (apptbl->inputdevNum <= inputidx) {
582 apptbl->input[inputidx].inputdevId
583 = sys_config->misc.default_inputdevId;
585 for (k = 0; k < sys_config->inputdevNum; k++) {
586 m = strlen(sys_config->inputdev[k].name);
587 if (strncasecmp(&work[found],
588 sys_config->inputdev[k].name, m) == 0) {
589 if (work[found+m] != '.') {
590 apfw_error("infoAilpkg: [%s] unknown input sw", work);
593 apptbl->input[inputidx].inputdevId
594 = sys_config->inputdev[k].id;
596 for (n = 0; n < sys_config->inputdev[k].inputswNum; n++) {
597 if (strcasecmp(&work[m],
598 sys_config->inputdev[k].inputsw[n].name)
600 apptbl->input[inputidx].inputswId = n;
604 if (n < sys_config->inputdev[k].inputswNum) {
605 if (apptbl->inputdevNum <= inputidx) {
606 apptbl->inputdevNum = inputidx + 1;
610 apfw_error("infoAilpkg: [%s] unknown input sw", work);
616 if (k >= sys_config->inputdevNum) {
617 apfw_error("infoAilpkg: [%s] unknown input device", work);
623 apfw_error("infoAilpkg: [%s] unknown input", work);
627 if ((found == 0) && (work[0] != 0)) {
628 if (strncasecmp(work, "NoDisplay", 9) == 0) {
630 if (work[9] == '=') {
631 if (strcasecmp(&work[10], "false") == 0) {
639 /* surface animation */
640 if ((found == 0) && (work[0] != 0)) {
641 if (strncasecmp(work, "Animation=", 10) == 0) {
642 apptbl->animation = strdup(&work[10]);
646 /* surface animation time */
647 if ((found == 0) && (work[0] != 0)) {
648 if (strncasecmp(work, "Animation_time=", 15) == 0) {
649 apptbl->animation_time = strtol(&work[15], (char **)0, 0);
654 /* cpu % at invisible */
655 if ((found == 0) && (work[0] != 0)) {
656 if (strncasecmp(work, "invisiblecpu", 12) == 0) {
657 apptbl->invisiblecpu = 0;
658 if (work[12] == '=') {
659 if (strcasecmp(&work[13], "yes") == 0) {
660 apptbl->invisiblecpu = 100;
662 else if (strcasecmp(&work[13], "no") != 0) {
663 apptbl->invisiblecpu = strtol(&work[13], (char **)0, 0);
664 if (apptbl->invisiblecpu > 100)
665 apptbl->invisiblecpu = 100;
672 /* configure event */
673 if ((found == 0) && (work[0] != 0)) {
674 if (strcasecmp(work, "noconfigure") == 0) {
675 apptbl->noconfigure = 1;
680 /* overlap on HomeScreen menu */
681 if ((found == 0) && (work[0] != 0)) {
682 if (strcasecmp(work, "menuoverlap") == 0) {
683 apptbl->menuoverlap = 1;
689 if ((found == 0) && (work[0] != 0)) {
690 if (strncasecmp(work, "auto", 4) == 0) {
691 apptbl->autostart = 1;
693 else if (strncasecmp(work, "noauto", 6) == 0) {
694 apptbl->autostart = 0;
697 apfw_error("infoAilpkg: [%s] unknown key", work);
700 if (category[i] == 0) break;
705 apptbl->exec = strdup(exec);
706 if (apptbl->displayzoneNum == 0) {
707 apptbl->displayzoneNum = 1;
708 apptbl->display[0].displayId = sys_config->misc.default_displayId;
709 apptbl->display[0].layerId = sys_config->misc.default_layerId;
710 apptbl->display[0].zoneId = sys_config->misc.default_dispzoneId;
712 if (apptbl->soundzoneNum == 0) {
713 apptbl->soundzoneNum = 1;
714 apptbl->sound[0].soundId = sys_config->misc.default_soundId;
715 apptbl->sound[0].zoneId = sys_config->misc.default_soundzoneId;
717 apfw_trace("Ail.%d: appid=%s name=%s exec=%s icon=%s type=%s",
718 _ico_app_config_update->applicationNum, apptbl->appid, apptbl->name,
719 apptbl->exec, apptbl->icon_key_name, apptbl->type);
720 apfw_trace("Ail.%d: categ=%d kind=%d disp=%d layer=%d zone=%d "
721 "sound=%d zone=%d auto=%d noicon=%d anim=%s.%d overlap=%d cpu=%d",
722 _ico_app_config_update->applicationNum, apptbl->categoryId, apptbl->kindId,
723 apptbl->display[0].displayId, apptbl->display[0].layerId,
724 apptbl->display[0].zoneId, apptbl->sound[0].soundId,
725 apptbl->sound[0].zoneId, apptbl->autostart, apptbl->noicon,
726 apptbl->animation ? apptbl->animation : "(none)",
727 apptbl->animation_time, apptbl->menuoverlap, apptbl->invisiblecpu);
728 _ico_app_config_update->applicationNum++;
731 if (_ico_app_config_update->applicationNum > num)
732 return AIL_CB_RET_CANCEL;
734 return AIL_CB_RET_CONTINUE;
737 /*--------------------------------------------------------------------------*/
739 * @brief readAilApplist: get all application configuration from AppCore(static function)
742 * @return application configuration table
743 * @retval !=NULL success(application configuration table address)
744 * @retval ==NULL error(can not read configuration files)
746 /*--------------------------------------------------------------------------*/
747 static Ico_Uxf_App_Config *
752 GError *error = NULL;
754 _ico_app_config_update->applicationNum = 0;
756 /* get system configuration */
757 sys_config = (Ico_Uxf_Sys_Config *)ico_uxf_getSysConfig();
759 apfw_error("readAilApplist: can not read system configuration");
763 /* read system configuration file for application default category */
764 sappfile = g_key_file_new();
766 GString* filepath = g_string_new("xx");
767 g_string_printf(filepath, "%s/%s", sys_config->misc.confdir, ICO_UXF_CONFIG_APPATTR);
769 if (g_key_file_load_from_file(sappfile, filepath->str,
770 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
773 default_icon = g_key_file_get_string(sappfile, "app-icon", "default-icon", &error);
775 g_clear_error(&error);
780 apfw_error("readAilApplist: %s %s", (char *)filepath->str, error->message);
781 g_key_file_free(sappfile);
784 g_string_free(filepath, TRUE);
787 ret = ail_filter_count_appinfo(NULL, &num);
788 if (ret != AIL_ERROR_OK) {
790 g_key_file_free(sappfile);
793 apfw_trace("readAilApplist: Leave(Ail:cannot count appinfo) = %d", ret);
796 apfw_trace("readAilApplist: number of off AIL package = %d", num);
798 ail_filter_new(&filter);
799 ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "menu");
800 ret = ail_filter_count_appinfo(filter, &num);
801 if (ret != AIL_ERROR_OK) {
803 g_key_file_free(sappfile);
806 apfw_trace("readAilApplist: Leave(Ail:cannot count appinfo(menu)) = %d", ret);
809 apfw_trace("readAilApplist: number of menu AIL package = %d", num);
810 ail_filter_destroy(filter);
812 ail_filter_new(&filter);
813 ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
814 ret = ail_filter_count_appinfo(filter, &wnum);
815 if (ret != AIL_ERROR_OK) {
817 g_key_file_free(sappfile);
820 apfw_trace("readAilApplist: Leave(Ail:cannot count appinfo(Application)) = %d", ret);
823 apfw_trace("readAilApplist: number of Application AIL package = %d", wnum);
824 ail_filter_destroy(filter);
827 _ico_app_config_update->application = g_new0(Ico_Uxf_conf_application, num);
829 ail_filter_new(&filter);
830 ret = ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "menu");
831 ret = ail_filter_list_appinfo_foreach(filter, infoAilpkg, (void *)num);
832 if (ret != AIL_ERROR_OK) {
834 g_key_file_free(sappfile);
837 ail_filter_destroy(filter);
838 apfw_trace("readAilApplist: Leave(Ail:cannot get appinfo(menu)) = %d", ret);
841 ail_filter_destroy(filter);
843 ail_filter_new(&filter);
844 ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
845 ret = ail_filter_list_appinfo_foreach(filter, infoAilpkg, (void *)num);
846 if (ret != AIL_ERROR_OK) {
848 g_key_file_free(sappfile);
851 ail_filter_destroy(filter);
852 apfw_trace("readAilApplist: Leave(Ail:cannot get appinfo(Application)) = %d", ret);
855 ail_filter_destroy(filter);
857 if (_ico_app_config_update->ailNum != num) {
859 g_key_file_free(sappfile);
862 apfw_trace("readAilApplist: Leave(cannot read ail correctly %d =! %d",
863 _ico_app_config_update->ailNum, num);
867 /* create Hash Table */
868 ico_uxf_conf_remakeAppHash();
871 g_key_file_free(sappfile);
874 apfw_trace("readAilApplist: Leave");
876 return _ico_app_config_update;
879 /*--------------------------------------------------------------------------*/
881 * @brief ico_uxf_closeAppConfig: close application configuration table
886 /*--------------------------------------------------------------------------*/
888 ico_uxf_closeAppConfig(void)
890 if(_ico_app_config != NULL){
891 g_free(_ico_app_config->application);
892 g_free(_ico_app_config);
893 _ico_app_config = NULL;
897 /*--------------------------------------------------------------------------*/
899 * @brief ico_uxf_conf_remakeAppHash: make application hash table(static function)
904 /*--------------------------------------------------------------------------*/
906 ico_uxf_conf_remakeAppHash(void)
910 Ico_Uxf_conf_application *app;
912 memset(_ico_app_config_update->hashnametable, 0, sizeof(_ico_app_config_update->hashnametable));
914 for (i = 0; i < _ico_app_config_update->applicationNum; i++) {
916 _ico_app_config_update->application[i].nextidhash = NULL;
917 hash = ICO_UXF_MISC_HASHBYID(i);
918 app = _ico_app_config_update->hashidtable[hash];
920 _ico_app_config_update->hashidtable[hash] = &_ico_app_config_update->application[i];
923 while (app->nextidhash) {
924 app = app->nextidhash;
926 app->nextidhash = &_ico_app_config_update->application[i];
929 _ico_app_config_update->application[i].nextnamehash = NULL;
930 hash = ICO_UXF_MISC_HASHBYNAME(_ico_app_config_update->application[i].appid);
931 app = _ico_app_config_update->hashnametable[hash];
933 _ico_app_config_update->hashnametable[hash] = &_ico_app_config_update->application[i];
936 while (app->nextnamehash) {
937 app = app->nextnamehash;
939 app->nextnamehash = &_ico_app_config_update->application[i];
944 /*--------------------------------------------------------------------------*/
946 * @brief ico_uxf_getAppByAppid: get application configuration by application Id
948 * @param[in] appid application Id
949 * @return application configuration table
950 * @retval !=NULL success(application configuration table address)
951 * @retval ==NULL error(application dose not exist)
953 /*--------------------------------------------------------------------------*/
954 ICO_APF_API const Ico_Uxf_conf_application *
955 ico_uxf_getAppByAppid(const char *appid)
957 Ico_Uxf_conf_application *app;
959 if (!_ico_app_config) {
960 (void)ico_uxf_getAppConfig();
962 app = _ico_app_config->hashnametable[ICO_UXF_MISC_HASHBYNAME(appid)];
965 if (strcasecmp(app->appid, appid) == 0) break;
966 app = app->nextnamehash;
969 apfw_warn("ico_uxf_getAppByAppid: appid(%s) dose not exist", appid);
974 /*--------------------------------------------------------------------------*/
976 * @brief ico_uxf_getAppByName: get application configuration by application name
978 * @param[in] name application name
979 * @return application configuration table
980 * @retval !=NULL success(application configuration table address)
981 * @retval ==NULL error(application dose not exist)
983 /*--------------------------------------------------------------------------*/
984 ICO_APF_API const Ico_Uxf_conf_application *
985 ico_uxf_getAppByName(const char *name)
988 Ico_Uxf_conf_application *app = NULL;
990 if (!_ico_app_config) {
991 (void)ico_uxf_getAppConfig();
994 for (i = 0; i < _ico_app_config->applicationNum; i++) {
995 if (strcasecmp(_ico_app_config->application[i].name, name) == 0) {
996 app = &_ico_app_config->application[i];
1001 apfw_warn("ico_uxf_getAppByName: name(%s) dose not exist", name);
1006 /*--------------------------------------------------------------------------*/
1008 * @brief ico_uxf_getAppDisplay: get application display
1010 * @param[in] app application configuration table
1011 * @param[in] idx display zone index
1012 * @param[out] x zone X coodinate
1013 * @param[out] y zone Y coodinate
1014 * @param[out] width zone width
1015 * @param[out] height zone height
1017 * @retval ICO_UXF_EOK succes
1018 * @retval ICO_UXF_EINVAL error(illegal idx)
1019 * @retval ICO_UXF_ENOSYS error(can not read configuration files)
1021 /*--------------------------------------------------------------------------*/
1023 ico_uxf_getAppDisplay(const Ico_Uxf_conf_application *app, const int idx,
1024 int *x, int *y, int *width, int *height)
1026 Ico_Uxf_conf_display_zone *zone;
1029 return ICO_UXF_ENOSYS;
1031 if ((! app) || (idx < 0) || (idx >= app->displayzoneNum)) {
1032 return ICO_UXF_EINVAL;
1035 zone = &sys_config->display[app->display[idx].displayId].zone[app->display[idx].zoneId];
1037 if (x) *x = zone->x;
1038 if (y) *y = zone->y;
1039 if (width) *width = zone->width;
1040 if (height) *height = zone->height;
1045 /*--------------------------------------------------------------------------*/
1047 * @brief ico_uxf_conf_addPkgmgrEventListener:
1048 * request to listen the pkgmgr's broadcasting.
1052 * @retval ICO_UXF_EOK success
1053 * @retval ICO_UXF_ENOSYS cannot regist listener
1055 /*--------------------------------------------------------------------------*/
1057 ico_uxf_conf_addPkgmgrEventListener(void)
1062 /* already registied listener */
1066 conf_pc = pkgmgr_client_new(PC_LISTENING);
1067 if (conf_pc == NULL) {
1068 apfw_trace("ico_uxf_conf_addPkgmgrEventListener: cannot create pkgmgr client");
1069 return ICO_UXF_ENOSYS;
1072 ret = pkgmgr_client_listen_status(conf_pc, ico_uxf_conf_pkgmgrEvent, NULL);
1074 apfw_trace("ico_uxf_conf_addPkgmgrEventListener: "
1075 "cannot register listener of pkgmgr(%d)", ret);
1076 pkgmgr_client_free(conf_pc);
1078 return ICO_UXF_ENOSYS;
1084 /*--------------------------------------------------------------------------*/
1086 * @brief ico_uxf_conf_pkgmgrEvent:
1087 * This is callback function from pkgmgr.
1089 * @param[in] req_id request id
1090 * @param[in] pkg_type package type
1091 * @param[in] pkg_name package name
1092 * @param[in] key broadcast key(=start/end/...)
1093 * @param[in] val broadcast value(=install/uninstall/ok/fail)
1094 * @param[in] pmsg broadcast comment
1095 * @param[in] data user data
1098 /*--------------------------------------------------------------------------*/
1100 ico_uxf_conf_pkgmgrEvent(int req_id, const char *pkg_type, const char *pkg_name,
1101 const char *key, const char *val, const void *pmsg, void *data)
1103 apfw_trace("ico_uxf_conf_PkgmgrEvent: "
1104 "Enter(pkg_type=%s, pkg_name=%s, key=%s, val=%s, pmsg=%s)",
1105 pkg_type, pkg_name, key, val, pmsg);
1107 if (strcasecmp(key, "start") == 0) {
1108 if (strcasecmp(val, "install") == 0) {
1109 ico_uxf_conf_startEvent(pkg_name, ICO_UXF_CONF_EVENT_INSTALL);
1111 else if (strcasecmp(val, "uninstall") == 0) {
1112 ico_uxf_conf_startEvent(pkg_name, ICO_UXF_CONF_EVENT_UNINSTALL);
1115 else if (strcasecmp(key, "install_percent") == 0) {
1116 ico_uxf_conf_startEvent(pkg_name, ICO_UXF_CONF_EVENT_INSTALL);
1118 else if (strcasecmp(key, "progress_percent") == 0) {
1121 else if (strcasecmp(key, "error") == 0) {
1123 else if (strcasecmp(key, "end") == 0) {
1124 if (strcasecmp(val, "ok") == 0) {
1125 ico_uxf_conf_endEvent(pkg_name, APP_CONF_EVENT_OK);
1127 else if (strcasecmp(val, "fail") == 0) {
1128 ico_uxf_conf_endEvent(pkg_name, APP_CONF_EVENT_FAIL);
1135 /*--------------------------------------------------------------------------*/
1137 * @brief ico_uxf_conf_startEvent: mark event is start
1139 * @param[in] pkg_name package name
1140 * @param[in] type event type
1142 * @retval ICO_UXF_EOK success
1143 * @retval ICO_UXF_ENOMEM cannot allocate memory
1145 /*--------------------------------------------------------------------------*/
1147 ico_uxf_conf_startEvent(const char *pkg_name, int type)
1149 conf_pkgmgr_event_t *new = NULL;
1150 conf_pkgmgr_event_t *event = NULL;
1152 /* check the queue whether the package' event is exist */
1153 event = conf_prog_event;
1155 if (strncmp(event->pkg_name, pkg_name, ICO_UXF_MAX_PROCESS_NAME) == 0) {
1159 event = event->next;
1163 new = malloc(sizeof(conf_pkgmgr_event_t));
1165 apfw_warn("ico_uxf_conf_startEvent: cannot allocate memory");
1166 return ICO_UXF_ENOMEM;
1168 memset(new, 0, sizeof(new));
1170 event = conf_prog_event;
1175 event = event->next;
1178 conf_prog_event = new;
1183 strncpy(new->pkg_name, pkg_name, ICO_UXF_MAX_PROCESS_NAME);
1192 /*--------------------------------------------------------------------------*/
1194 * @brief ico_uxf_conf_endEvent: mark event is end
1196 * @param[in] pkg_name package name
1197 * @param[in] status end status
1199 * @retval ICO_UXF_EOK success
1201 /*--------------------------------------------------------------------------*/
1203 ico_uxf_conf_endEvent(const char *pkg_name, int status)
1209 conf_pkgmgr_event_t *current = NULL;
1210 conf_pkgmgr_event_t *event;
1211 conf_pkgmgr_event_t *bevent;
1212 static Ico_Uxf_App_Config *config = NULL;
1213 static Ico_Uxf_App_Config *tmp = NULL;
1215 apfw_trace("ico_uxf_conf_endEvent: Enter(pkg=%s, stat=%d)", pkg_name, status);
1216 /* get start event from queue */
1217 event = conf_prog_event;
1220 if (strncmp(event->pkg_name, pkg_name, ICO_UXF_MAX_PROCESS_NAME) == 0) {
1225 event = event->next;
1230 conf_prog_event = current->next;
1231 current->next = NULL;
1234 bevent->next = current->next;
1235 current->next = NULL;
1239 return ICO_UXF_ENOSYS;
1242 type = current->type;
1245 if (status == APP_CONF_EVENT_OK) {
1246 config = g_new0(Ico_Uxf_App_Config, 1);
1247 _ico_app_config_update = config;
1248 config = readAilApplist();
1252 apfw_trace("ico_uxf_conf_endEvent: Retry %d", cnt);
1253 config = readAilApplist();
1262 apfw_warn("ico_uxf_getAppByAppid: cannot access ail normally");
1263 return ICO_UXF_EBUSY;
1267 config = _ico_app_config;
1269 _ico_app_config = tmp;
1271 if (type == ICO_UXF_CONF_EVENT_INSTALL) {
1272 for (ii = 0; ii < _ico_app_config->applicationNum; ii++) {
1274 for (jj = 0; jj < config->applicationNum; jj++) {
1275 if (strcmp(_ico_app_config->application[ii].appid,
1276 config->application[jj].appid) == 0) {
1281 if ((exist == 0) && conf_cb_func) {
1282 conf_cb_func(_ico_app_config->application[ii].appid,
1283 ICO_UXF_CONF_EVENT_INSTALL);
1287 else if (type == ICO_UXF_CONF_EVENT_UNINSTALL) {
1288 for (jj = 0; jj < config->applicationNum; jj++) {
1290 for (ii = 0; ii < _ico_app_config->applicationNum; ii++) {
1291 if (strcmp(config->application[jj].appid,
1292 _ico_app_config->application[ii].appid) == 0) {
1297 if ((exist == 0) && conf_cb_func) {
1298 conf_cb_func(config->application[jj].appid,
1299 ICO_UXF_CONF_EVENT_UNINSTALL);
1304 if (config != NULL) {
1305 g_free(config->application);
1310 apfw_trace("ico_uxf_conf_endEvent: Leave");
1315 /*--------------------------------------------------------------------------*/
1317 * @brief ico_uxf_setAppUpdateCb:
1321 * @retval ICO_UXF_EOK success
1322 * @retval ICO_UXF_ENOSYS cannot regist callback
1324 /*--------------------------------------------------------------------------*/
1326 ico_uxf_conf_setAppUpdateCb(Ico_Uxf_AppUpdata_Cb func)
1330 ret = ico_uxf_conf_addPkgmgrEventListener();
1332 if (ret != ICO_UXF_EOK) {
1333 apfw_trace("ico_uxf_conf_setAppUpdateCb: cannot add listener");
1334 return ICO_UXF_ENOSYS;
1336 conf_cb_func = func;