From 6a8bdd91dc18bf4ecfab992604bc666889ff2e96 Mon Sep 17 00:00:00 2001 From: MyoungJune Park Date: Sun, 20 Jan 2013 20:35:23 +0900 Subject: [PATCH] fixed N_SE-21943 - if there's more than two plugins, dbus communication is working abnormally. - when loading new plugin, reset the dbus_signal callback handler. --- src/setting-main.c | 44 ++++++++++++------------- src/setting-plugin.c | 92 +++++++++++++++++++++++++++++++++++++++++++++------- src/setting.c | 2 +- 3 files changed, 102 insertions(+), 36 deletions(-) diff --git a/src/setting-main.c b/src/setting-main.c index aec632f..eaa7d1a 100755 --- a/src/setting-main.c +++ b/src/setting-main.c @@ -1105,6 +1105,8 @@ bool is_3rdapp_installed_setting_cfg(char* pkgname) /** * @param data + * ex) name : AppSetting4 + * ex) pkgname : UBKFwQidax.AppSetting4 */ static void draw_3rdapp(void* data, char* name, char* pkgname) { @@ -1123,21 +1125,15 @@ static void draw_3rdapp(void* data, char* name, char* pkgname) if (ad) { - if (ad->plugin_path) - { - free(ad->plugin_path); - ad->plugin_path = NULL; - } - ad->plugin_path = strdup(fullpath); - - setting_create_Gendial_field_groupitem(ad->main_genlist, + char* plugin_path = strdup(fullpath); + Setting_GenGroupItem_Data * plugin_node = setting_create_Gendial_field_groupitem(ad->main_genlist, &(ad->itc[GENDIAL_Type_1text_1icon_2]), NULL, setting_main_click_list_plugin_cb, ad, SWALLOW_Type_INVALID, IMG_DefaultIcon, NULL, - 0, name, NULL, + 0, name, plugin_path, // <<-- refactoring NULL); } SETTING_TRACE_END; @@ -1778,6 +1774,7 @@ static int setting_main_create(void *cb) setting_view_main.is_create = 1; + setting_drawer_list_init(); return SETTING_RETURN_SUCCESS; } @@ -1839,6 +1836,9 @@ static int setting_main_destroy(void *cb) evas_object_smart_callback_del(ad->main_genlist, "realized", __gl_realized); + setting_dbus_handler_fini(); + setting_drawer_list_fini(); + setting_view_main.is_create = 0; SETTING_TRACE_END; return SETTING_RETURN_SUCCESS; @@ -2193,25 +2193,23 @@ setting_main_click_list_plugin_cb(void *data, Evas_Object *obj, retm_if(event_info == NULL, "Invalid argument: event info is NULL"); Elm_Object_Item *item = (Elm_Object_Item *) event_info; elm_genlist_item_selected_set(item, EINA_FALSE); + Setting_GenGroupItem_Data *selected_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item); setting_main_appdata *ad = data; - if (ad->plugin_path) - { - PluginNode* plugin_node = setting_plugin_create(); - plugin_node->plugin_path = strdup(ad->plugin_path); - setting_plugin_load(plugin_node, (const char *)ad->plugin_path); - ad->plugin_node = (void*)plugin_node; + ad->plugin_path = strdup(selected_item->sub_desc); + SETTING_TRACE(" >> SELECTED plugin name : %s \n", ad->plugin_path); - #if 0 - if(ad->plugin_path) - { - free(ad->plugin_path); - ad->plugin_path = NULL; - } - #endif - } + setting_dbus_handler_init( ad ); + + #if 1 + PluginNode* plugin_node = setting_plugin_create(ad); + plugin_node->plugin_path = strdup(ad->plugin_path); + setting_plugin_load(plugin_node, (const char *)plugin_node->plugin_path); + + ad->plugin_node = plugin_node; // the selected plugin name + #endif } /** diff --git a/src/setting-plugin.c b/src/setting-plugin.c index feaa148..8d02efa 100755 --- a/src/setting-plugin.c +++ b/src/setting-plugin.c @@ -31,11 +31,10 @@ #include +extern setting_main_appdata *g_main_ad; static Setting_GenGroupItem_Data *g_list_item; /*TEST*/ - - /* * UI draw handler table : _g_draw_list * - contains Object_Drawer typed object. @@ -237,8 +236,14 @@ static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* mess dbus_error_init(&error); setting_main_appdata *ad = user_data; + char* plugin_path = ad->plugin_path; + char* pkg_name = get_app_string(plugin_path); - char* pkg_name = get_app_string(ad->plugin_path); + if (pkg_name == NULL) + { + SETTING_TRACE("pkg_name is NULL - it's abnormal operation"); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } char str_buf[MAX_COMMON_BUFFER_LEN]; snprintf(str_buf, MAX_COMMON_BUFFER_LEN, "Update_%s", pkg_name); @@ -291,9 +296,8 @@ static DBusHandlerResult __signal_filter(DBusConnection* conn, DBusMessage* mess char* val_name = strchr(value, '|'); val_name++; - // ad->plugin_path // access xml file - doc = xmlParseFile(ad->plugin_path); + doc = xmlParseFile(plugin_path); // generate xml tree xmlNode *root = xmlDocGetRootElement(doc); // find a node @@ -329,6 +333,7 @@ static int __send_msg(char* key, char* value) if (bus == NULL) return -1; + // ex) in gdb --> $15 = 0x43b6eb78 "Update_(null)" -> error codintion if (s_pkg_name == NULL) { SETTING_TRACE("s_pkg_name is NULL - it's abnormal operation"); @@ -365,6 +370,7 @@ static int __send_msg(char* key, char* value) static void __send_int_msg(xmlNode* xmlObj, int val) { + SETTING_TRACE_BEGIN; const char *id = (char*)xmlGetProp(xmlObj, "id"); const char *title = (char*)xmlGetProp(xmlObj, "title"); char key[MAX_CONTENT_LEN] = {0,}; @@ -373,6 +379,7 @@ static void __send_int_msg(xmlNode* xmlObj, int val) char value[MAX_CONTENT_LEN] = {0,}; snprintf(value, sizeof(value), "INT|%d", val); __send_msg(key, value); + SETTING_TRACE_END; } @@ -396,6 +403,7 @@ int setting_dbus_handler_init(void* user_data) { SETTING_TRACE("already get a bus, need release first."); setting_dbus_handler_fini(); +// return -1; } DBusError error; memset(&error, 0, sizeof(DBusError)); @@ -438,6 +446,7 @@ int setting_dbus_handler_init(void* user_data) int setting_dbus_handler_fini(void) { + SETTING_TRACE_BEGIN; //do safty checking first. setting_retvm_if(!bus, 0, "!bus"); DBusError error; @@ -445,7 +454,13 @@ int setting_dbus_handler_fini(void) char rule[MAX_LOCAL_BUFSIZE + 1] = {0, }; dbus_error_init(&error); + + // why?? + bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); + //dbus_connection_remove_filter(bus, __signal_filter, NULL); + + snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE); dbus_bus_remove_match(bus, rule, &error); @@ -482,6 +497,7 @@ static int __cfg_file_write(Draw_Data *pd) SETTING_TRACE("__cfg_file_write successful"); } + SETTING_TRACE_END; return TRUE; } @@ -576,7 +592,7 @@ static void* __link_list_cb(void *data, Evas_Object *obj, void *event_info) snprintf(file, sizeof(file), "%s/%s", PLUGIN_CFG_DIR, link_file); SETTING_TRACE("file:%s", file); - PluginNode* plugin_node = setting_plugin_create(); + PluginNode* plugin_node = setting_plugin_create(file); setting_plugin_load(plugin_node, (const char *)file); //setting_plugin_load(NULL, file); @@ -1253,6 +1269,8 @@ static int __node_walker(PluginNode* context, xmlNode* cur) Draw_Data *pd = context->pd; retv_if(!pd, -1); + retv_if(!context->ui_list, -1); + xmlNode *cur_node = NULL; for (cur_node = cur; cur_node;cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { @@ -1292,6 +1310,13 @@ static int __node_finder(PluginNode* context, xmlNode* cur, char* id_str, char* SETTING_TRACE_BEGIN; xmlNode *cur_node = NULL; + if (! context) + { + SETTING_TRACE("context is NULL - it's error CONDITION "); + return -1; + } + + retv_if(!context->ui_list, -1); if (*is_end == true) return 0; for (cur_node = cur; cur_node;cur_node = cur_node->next) { @@ -1442,16 +1467,13 @@ static void _plugin_entry_free_cb(void* data) } } -//static PluginNode* g_context; - PluginNode* setting_plugin_create() { PluginNode *node = calloc(1, sizeof(PluginNode)); - setting_retvm_if(!node, -1, "Create PluginNode obj failed"); - Draw_Data *pd = calloc(1, sizeof(Draw_Data)); + if (!pd) { FREE(node); } @@ -1493,6 +1515,7 @@ void setting_plugin_destroy(PluginNode* node) } free(node); node = NULL; +// PLUGIN_FINI; } } @@ -1508,7 +1531,9 @@ static Eina_Bool _plugin_foreach_cb(const Eina_Hash *hash, const void*key, void* void setting_plugin_debug(PluginNode* context) { // SETTING_TRACE("HASH TABLE -------------------------------------"); - eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL); + if (context->ui_list) { + eina_hash_foreach(context->ui_list,_plugin_foreach_cb, NULL); + } // SETTING_TRACE("HASH TABLE -------------------------------------"); } @@ -1545,11 +1570,54 @@ bool setting_plugin_load(PluginNode* context, const char *cfg_file) context->pd->cfg_file = cfg_file; context->pd->win_get = (Evas_Object *) ug_get_window(); - GError *error = NULL; + //GError *error = NULL; context->pd->doc = xmlParseFile(cfg_file); context->pd->root = xmlDocGetRootElement(context->pd->doc); + // signal filter change + //setting_dbus_handler_init(g_main_ad); + void* user_data = (void*)g_main_ad; + + DBusError error; + dbus_error_init(&error); + char rule[MAX_LOCAL_BUFSIZE + 1] = {0,}; + bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); + if (!bus) + { + SETTING_TRACE("Fail to connect to the D-BUS daemon: %s", error.message); + dbus_error_free(&error); + return -1; + } + + // remove filter + // dbus_connection_remove_filter(bus, __signal_filter, NULL); + + // get rule + snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE); + dbus_bus_add_match(bus, rule, &error); + if (dbus_error_is_set(&error)) + { + SETTING_TRACE("Fail to rule set; %s", error.message); + dbus_bus_remove_match(bus, rule, &error); + dbus_error_free(&error); + dbus_connection_close(bus); + bus = NULL; + return -1; + } + + // re-add filter + if (dbus_connection_add_filter(bus, __signal_filter, user_data, NULL) == FALSE) + { + dbus_bus_remove_match(bus, rule, &error); + dbus_error_free(&error); + dbus_connection_close(bus); + bus = NULL; + return -1; + } + + + // TODO: error handler here __node_walker(context, context->pd->root); diff --git a/src/setting.c b/src/setting.c index 30a73ea..6149e69 100755 --- a/src/setting.c +++ b/src/setting.c @@ -753,7 +753,7 @@ static bool setting_main_app_create(void *data) /* load config file */ int cfg_operation_ret = setting_cfg_init(); - PLUGIN_INIT(ad); + //PLUGIN_INIT(ad); elm_theme_extension_add(NULL, SETTING_THEME_EDJ_NAME); #if SUPPORT_LCD_TIMEOUT_KEEPING -- 2.7.4