From: Junghyun Yeon Date: Fri, 10 Jan 2020 08:22:29 +0000 (+0900) Subject: Change pkg signal listening behavior X-Git-Tag: submit/tizen/20200210.091657^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ccfe581e7e3639d37c0f781369f7dd58de08993;p=platform%2Fcore%2Fappfw%2Fslp-pkgmgr.git Change pkg signal listening behavior Add signal name when subscribing pkg signal to let callback to be invoked only when signal interested are broadcasted. Change-Id: Ib9c836620c5ae9efda438054e5841c46365eeac1 Signed-off-by: Junghyun Yeon --- diff --git a/client/src/pkgmgr.c b/client/src/pkgmgr.c index 0ec420c..1300285 100644 --- a/client/src/pkgmgr.c +++ b/client/src/pkgmgr.c @@ -154,7 +154,7 @@ static struct cb_info *__create_size_info_cb_info( static gboolean __free_cb_info_at_main_thread(gpointer user_data) { struct cb_info *cb_info = (struct cb_info *)user_data; - + g_list_free(cb_info->sid_list); free(cb_info->req_key); free(cb_info); diff --git a/client/src/pkgmgr_client_connection.c b/client/src/pkgmgr_client_connection.c index 914ccda..eab1228 100644 --- a/client/src/pkgmgr_client_connection.c +++ b/client/src/pkgmgr_client_connection.c @@ -230,26 +230,72 @@ static void __signal_handler(GDBusConnection *conn, const gchar *sender_name, /* TODO: unsubscribe request callback */ } -int pkgmgr_client_connection_set_callback(struct pkgmgr_client_t *pc, - struct cb_info *cb_info) +static void __set_signal_list(int event, GList **signal_list) +{ + int i; + if (event == PKGMGR_CLIENT_STATUS_ALL) + return; + + for (i = 0; map[i].signal_str != NULL; i++) { + if (event & map[i].signal_type) + *signal_list = g_list_append(*signal_list, + (char *)map[i].signal_str); + } +} + +static int __subscribe_signal(struct pkgmgr_client_t *pc, + struct cb_info *cb_info, const char *signal) { - cb_info->sid = g_dbus_connection_signal_subscribe(pc->conn, NULL, - PKGMGR_INSTALLER_DBUS_INTERFACE, NULL, + guint sid = g_dbus_connection_signal_subscribe(pc->conn, NULL, + PKGMGR_INSTALLER_DBUS_INTERFACE, signal, PKGMGR_INSTALLER_DBUS_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __signal_handler, (gpointer)cb_info, NULL); - if (!cb_info->sid) { + if (!sid) { ERR("failed to subscribe singal"); return PKGMGR_R_ERROR; } + cb_info->sid_list = g_list_append(cb_info->sid_list, + GUINT_TO_POINTER(sid)); return PKGMGR_R_OK; } +int pkgmgr_client_connection_set_callback(struct pkgmgr_client_t *pc, + struct cb_info *cb_info) +{ + GList *signal_list = NULL; + GList *tmp_list = NULL; + int ret; + char *signal_type; + __set_signal_list(pc->status_type, &signal_list); + + if (g_list_length(signal_list) == 0) + return __subscribe_signal(pc, cb_info, NULL); + + for (tmp_list = signal_list; tmp_list != NULL; + tmp_list = g_list_next(tmp_list)) { + signal_type = (char *)tmp_list->data; + ret = __subscribe_signal(pc, cb_info, signal_type); + if (ret != 0) { + g_list_free(signal_list); + return PKGMGR_R_ERROR; + } + } + + g_list_free(signal_list); + return PKGMGR_R_OK; +} + void pkgmgr_client_connection_unset_callback(struct pkgmgr_client_t *pc, struct cb_info *cb_info) { - g_dbus_connection_signal_unsubscribe(pc->conn, cb_info->sid); + GList *tmp = NULL; + guint tmp_sid; + for (tmp = cb_info->sid_list; tmp != NULL; tmp = g_list_next(tmp)) { + tmp_sid = GPOINTER_TO_UINT(tmp->data); + g_dbus_connection_signal_unsubscribe(pc->conn, tmp_sid); + } } int pkgmgr_client_connection_send_request(struct pkgmgr_client_t *pc, diff --git a/client/src/pkgmgr_client_internal.h b/client/src/pkgmgr_client_internal.h index bf799fc..7f434c1 100644 --- a/client/src/pkgmgr_client_internal.h +++ b/client/src/pkgmgr_client_internal.h @@ -43,7 +43,7 @@ struct cb_info { pkgmgr_pkg_size_info_receive_cb size_info_cb; void *data; struct pkgmgr_client_t *client; - guint sid; + GList *sid_list; }; struct pkgmgr_client_t {