From beb374d6666eb323ae9ce6aeb43934a3907e4ab3 Mon Sep 17 00:00:00 2001 From: Myungki Lee Date: Wed, 25 May 2016 14:30:48 +0900 Subject: [PATCH] Use g_dbus for some notification_status api - remove dependency of the unused package Change-Id: I2460d9f72ab58e88be9d178a52ddf1d05da2e47c Signed-off-by: Myungki Lee --- CMakeLists.txt | 4 -- packaging/notification.spec | 4 -- src/notification_noti.c | 3 - src/notification_status.c | 169 +++++++++++++++++++++----------------------- 4 files changed, 81 insertions(+), 99 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7ebcd6..b27a4e0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,10 +60,6 @@ pkg_check_modules(pkgs REQUIRED capi-appfw-app-manager capi-appfw-package-manager pkgmgr-info - edbus - elementary - ecore - eina libtzplatform-config glib-2.0 gio-2.0 diff --git a/packaging/notification.spec b/packaging/notification.spec index 575a78f..d248b77 100755 --- a/packaging/notification.spec +++ b/packaging/notification.spec @@ -20,10 +20,6 @@ BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(capi-appfw-package-manager) BuildRequires: pkgconfig(pkgmgr-info) -BuildRequires: pkgconfig(edbus) -BuildRequires: pkgconfig(elementary) -BuildRequires: pkgconfig(ecore) -BuildRequires: pkgconfig(eina) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) diff --git a/src/notification_noti.c b/src/notification_noti.c index 1ca42eb..362e894 100755 --- a/src/notification_noti.c +++ b/src/notification_noti.c @@ -19,9 +19,6 @@ #include #include -#include -#include -#include #include #include diff --git a/src/notification_status.c b/src/notification_status.c index 377162a..e9d79af 100755 --- a/src/notification_status.c +++ b/src/notification_status.c @@ -19,11 +19,8 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include #include #include @@ -41,42 +38,30 @@ struct _message_cb_data { notification_status_message_cb callback; void *data; - E_DBus_Connection *dbus_connection; - E_DBus_Signal_Handler *dbus_hdlr; + GDBusConnection *conn; + uint message_id; }; static struct _message_cb_data md; -static void __notification_status_message_dbus_callback(void *data, DBusMessage *msg) +static void __notification_status_message_dbus_callback(GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) { - int ret = 0; - DBusError err; char *message = NULL; - if (data == NULL || msg == NULL) { - NOTIFICATION_ERR("message is NULL"); - return; - } - - dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &message, - DBUS_TYPE_INVALID); - if (ret == 0) { - NOTIFICATION_ERR("dbus_message_get_args error"); - return; - } - - if (dbus_error_is_set(&err)) { - NOTIFICATION_ERR("Dbus err: %s", err.message); - dbus_error_free(&err); + g_variant_get(parameters, "(&s)", &message); + if (strlen(message) <= 0) { + NOTIFICATION_ERR("message has only NULL"); return; } - if (!md.callback) - return; - if (strlen(message) <= 0) { - NOTIFICATION_ERR("message has only NULL"); + if (!md.callback) { + NOTIFICATION_ERR("no callback"); return; } @@ -86,33 +71,41 @@ static void __notification_status_message_dbus_callback(void *data, DBusMessage EXPORT_API int notification_status_monitor_message_cb_set(notification_status_message_cb callback, void *user_data) { + GError *error = NULL; + if (!callback) return NOTIFICATION_ERROR_INVALID_PARAMETER; - E_DBus_Connection *dbus_connection; - E_DBus_Signal_Handler *dbus_handler_size = NULL; - e_dbus_init(); - dbus_connection = e_dbus_bus_get(DBUS_BUS_SYSTEM); - if (dbus_connection == NULL) { - NOTIFICATION_ERR("noti register : failed to get dbus bus"); - return NOTIFICATION_ERROR_FROM_DBUS; - } - dbus_handler_size = - e_dbus_signal_handler_add(dbus_connection, NULL, - PATH_NAME, - INTERFACE_NAME, MEMBER_NAME, - __notification_status_message_dbus_callback, - user_data); - if (dbus_handler_size == NULL) { - NOTIFICATION_ERR("fail to add size signal"); - return NOTIFICATION_ERROR_FROM_DBUS; + if (md.conn == NULL) { + md.conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (md.conn == NULL) { + NOTIFICATION_ERR("Failed to connect to the D-BUS Daemon: %s", + error->message); + g_error_free(error); + return NOTIFICATION_ERROR_FROM_DBUS; + } } + if (!md.message_id) { + md.message_id = g_dbus_connection_signal_subscribe(md.conn, + NULL, + INTERFACE_NAME, + MEMBER_NAME, + PATH_NAME, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + __notification_status_message_dbus_callback, + NULL, + NULL); + if (md.message_id == 0) { + NOTIFICATION_ERR("g_dbus_connection_signal_subscribe() failed."); + g_object_unref(md.conn); + return NOTIFICATION_ERROR_FROM_DBUS; + } + } md.callback = callback; md.data = user_data; - md.dbus_connection = dbus_connection; - md.dbus_hdlr = dbus_handler_size; return NOTIFICATION_ERROR_NONE; } @@ -120,15 +113,14 @@ int notification_status_monitor_message_cb_set(notification_status_message_cb ca EXPORT_API int notification_status_monitor_message_cb_unset(void) { - if (md.dbus_hdlr != NULL) { - e_dbus_signal_handler_del(md.dbus_connection, - md.dbus_hdlr); - md.dbus_hdlr = NULL; + if (md.message_id) { + g_dbus_connection_signal_unsubscribe(md.conn, md.message_id); + md.message_id = 0; } - if (md.dbus_connection != NULL) { - e_dbus_connection_close(md.dbus_connection); - md.dbus_connection = NULL; - e_dbus_shutdown(); + + if (md.conn) { + g_object_unref(md.conn); + md.conn = NULL; } md.callback = NULL; @@ -140,50 +132,51 @@ int notification_status_monitor_message_cb_unset(void) EXPORT_API int notification_status_message_post(const char *message) { - DBusConnection *connection = NULL; - DBusMessage *signal = NULL; - DBusError err; - dbus_bool_t ret; + GError *err = NULL; + GDBusConnection *conn; + GVariant *param; + int ret = NOTIFICATION_ERROR_NONE; if (!message) { NOTIFICATION_ERR("message is NULL"); return NOTIFICATION_ERROR_INVALID_PARAMETER; } - if (strlen(message) <= 0) { - NOTIFICATION_ERR("message has only NULL"); - return NOTIFICATION_ERROR_INVALID_PARAMETER; + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (conn == NULL) { + NOTIFICATION_ERR("g_bus_get_sync() failed: %s", err->message); + ret = NOTIFICATION_ERROR_FROM_DBUS; + goto end; } - dbus_error_init(&err); - connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err); - if (!connection) { - NOTIFICATION_ERR("Fail to dbus_bus_get"); + param = g_variant_new("(s)", message); + + if (g_dbus_connection_emit_signal(conn, + NULL, + PATH_NAME, + INTERFACE_NAME, + MEMBER_NAME, + param, + &err) == FALSE) { + NOTIFICATION_ERR("g_dbus_connection_emit_signal() failed: %s", + err->message); return NOTIFICATION_ERROR_FROM_DBUS; + goto end; } - signal = - dbus_message_new_signal(PATH_NAME, INTERFACE_NAME, - MEMBER_NAME); - if (!signal) { - NOTIFICATION_ERR("Fail to dbus_message_new_signal"); + if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE) { + NOTIFICATION_ERR("g_dbus_connection_flush_sync() failed: %s", + err->message); return NOTIFICATION_ERROR_FROM_DBUS; + goto end; } - ret = dbus_message_append_args(signal, - DBUS_TYPE_STRING, &message, - DBUS_TYPE_INVALID); - if (ret) { - ret = dbus_connection_send(connection, signal, NULL); - - if (ret) - dbus_connection_flush(connection); - } +end: + if (err) + g_error_free(err); - dbus_message_unref(signal); - dbus_connection_unref(connection); + if (conn) + g_object_unref(conn); - return NOTIFICATION_ERROR_NONE; + return ret; } - - -- 2.7.4