Use gdbus instead of dbus-glib 15/76415/1 accepted/tizen/common/20160703.125822 accepted/tizen/ivi/20160629.015700 accepted/tizen/mobile/20160629.015618 accepted/tizen/tv/20160629.015734 accepted/tizen/wearable/20160629.015538 submit/tizen/20160627.042541 submit/tizen_common/20160701.180000
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 24 Jun 2016 00:29:30 +0000 (09:29 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 24 Jun 2016 00:29:30 +0000 (09:29 +0900)
Change-Id: I73cded5e4865e10669cf12b7164740292f14193b
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
packaging/appcore-watch.spec
src/appcore-watch-signal.c
src/appcore-watch-signal.h

index 5c27e0d7f4030860850b94db0ec101a2f45327c4..2e216ee7b72ad5d24190f40c5f619e9517009ff8 100644 (file)
@@ -36,7 +36,6 @@ INCLUDE(FindPkgConfig)
 pkg_check_modules(pkg_watch REQUIRED
                aul
                dlog
-               dbus-glib-1
                alarm-service
                capi-appfw-app-control
                capi-appfw-app-common
@@ -47,6 +46,8 @@ pkg_check_modules(pkg_watch REQUIRED
                libtzplatform-config
                capi-appfw-widget-application
                icu-i18n
+               glib-2.0
+               gio-2.0
                )
 FOREACH(flag ${pkg_watch_CFLAGS})
        SET(EXTRA_CFLAGS_watch "${EXTRA_CFLAGS_watch} ${flag}")
index fa9c568970996fbcc2a4398fe3fa21bb93ef6033..5e69f1a08b1200e8d692f749103d2396aa9cd842 100644 (file)
@@ -8,7 +8,6 @@ Source0:    appcore-watch-%{version}.tar.gz
 BuildRequires:  pkgconfig(aul)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(elementary)
-BuildRequires:  pkgconfig(dbus-glib-1)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(vconf-internal-keys)
 BuildRequires:  pkgconfig(alarm-service)
@@ -18,6 +17,8 @@ BuildRequires:        pkgconfig(capi-appfw-widget-application)
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(icu-uc)
 BuildRequires: pkgconfig(ecore-wayland)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-2.0)
 BuildRequires:  cmake
 
 
index a281fdf2989695d6a02ef4048856304425863485..c3830ee1833b703b9fc4462de515f7a3d347136a 100755 (executable)
@@ -24,8 +24,8 @@
 #include <malloc.h>
 
 #include <dlog.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <glib.h>
+#include <gio/gio.h>
 
 #include "appcore-watch-log.h"
 #include "appcore-watch-signal.h"
 
 #define MAX_BUFFER_SIZE                512
 
-static DBusConnection *bus = NULL;
-static int (*_deviced_signal_alpm_handler) (int ambient, void *data);
+static GDBusConnection *conn;
+static guint s_id;
+static int (*_deviced_signal_alpm_handler)(int ambient, void *data);
 static void *_deviced_signal_alpm_data;
 
-static DBusHandlerResult __dbus_signal_filter(DBusConnection *conn,
-               DBusMessage *message, void *user_data)
+static void __dbus_signal_filter(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_name,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
 {
-       const char *sender;
-       const char *interface;
-       const char *value;
-
-       DBusError error;
-       dbus_error_init(&error);
-
-       sender = dbus_message_get_sender(message);
-       if (sender == NULL)
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-       interface = dbus_message_get_interface(message);
-       if (interface == NULL) {
-               _E("reject by security issue - no interface\n");
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-       }
-
-       if (dbus_message_is_signal(message, interface,
-                               DEVICED_SIGNAL_HOME_SCREEN)) {
-               if (dbus_message_get_args(message, &error, DBUS_TYPE_STRING,
-                                       &value, DBUS_TYPE_INVALID) == FALSE) {
-                       _E("Failed to get data: %s", error.message);
-                       dbus_error_free(&error);
-               }
+       gchar *value = NULL;
 
+       if (g_strcmp0(signal_name, DEVICED_SIGNAL_HOME_SCREEN) == 0) {
                if (_deviced_signal_alpm_handler) {
-                       if (strcmp(value, CLOCK_START) == 0)
+                       g_variant_get(parameters, "(&s)", &value);
+                       if (g_strcmp0(value, CLOCK_START) == 0) {
                                _deviced_signal_alpm_handler(1,
                                                _deviced_signal_alpm_data);
-                       else if (strcmp(value, CLOCK_STOP) == 0)
+                       } else if (g_strcmp0(value, CLOCK_STOP) == 0) {
                                _deviced_signal_alpm_handler(0,
                                                _deviced_signal_alpm_data);
+                       }
                }
        }
-
-       return DBUS_HANDLER_RESULT_HANDLED;
 }
 
 static int __dbus_init(void)
 {
-       DBusError error;
-
-       if (bus)
-               return 0;
-
-       dbus_error_init(&error);
-       bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
-       if (!bus) {
-               _E("Failed to connect to the D-BUS daemon: %s", error.message);
-               dbus_error_free(&error);
-               return -1;
+       GError *err = NULL;
+
+       if (conn == NULL) {
+               conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+               if (conn == NULL) {
+                       _E("g_bus_get_sync() is failed. %s", err->message);
+                       g_error_free(err);
+                       return -1;
+               }
        }
 
-       dbus_connection_setup_with_g_main(bus, NULL);
+       g_clear_error(&err);
 
        return 0;
 }
 
 static int __dbus_signal_handler_init(const char *path, const char *interface)
 {
-       char rule[MAX_BUFFER_SIZE] = {0,};
-       DBusError error;
-
-       dbus_error_init(&error);
-
-       snprintf(rule, MAX_BUFFER_SIZE,
-                       "path='%s',type='signal',interface='%s'", path,
-                       interface);
-
-       dbus_bus_add_match(bus, rule, &error);
-       if (dbus_error_is_set(&error)) {
-               _E("Fail to rule set: %s", error.message);
-               dbus_error_free(&error);
-               return -1;
-       }
-
-       if (dbus_connection_add_filter(bus, __dbus_signal_filter, NULL,
-                               NULL) == FALSE) {
-               _E("add filter fail");
+       s_id = g_dbus_connection_signal_subscribe(conn,
+                                       NULL,
+                                       interface,
+                                       NULL,
+                                       path,
+                                       NULL,
+                                       G_DBUS_SIGNAL_FLAGS_NONE,
+                                       __dbus_signal_filter,
+                                       NULL,
+                                       NULL);
+       if (s_id == 0) {
+               _E("g_dbus_connection_signal_subscribe() is failed.");
                return -1;
        }
 
@@ -134,7 +106,8 @@ int _watch_core_listen_alpm_handler(int (*func) (int, void *), void *data)
 {
        _D("watch_core_listen_deviced_alpm");
 
-       __dbus_init();
+       if (__dbus_init() < 0)
+               return -1;
 
        if (__dbus_signal_handler_init(DEVICED_PATH, DEVICED_INTERFACE) < 0) {
                _E("error app signal init");
@@ -149,26 +122,30 @@ int _watch_core_listen_alpm_handler(int (*func) (int, void *), void *data)
 
 int _watch_core_send_alpm_update_done(void)
 {
-       DBusMessage *message;
+       GError *err = NULL;
 
-       __dbus_init();
-
-       message = dbus_message_new_signal(ALPM_VIEWER_PATH,
-                       ALPM_VIEWER_INTERFACE, ALPM_VIEWER_SIGNAL_DRAW_DONE);
+       if (__dbus_init() < 0)
+               return -1;
 
-       if (dbus_message_append_args(message,
-                               DBUS_TYPE_INVALID) == FALSE) {
-               _E("Failed to load data error");
+       if (g_dbus_connection_emit_signal(conn,
+                                       NULL,
+                                       ALPM_VIEWER_PATH,
+                                       ALPM_VIEWER_INTERFACE,
+                                       ALPM_VIEWER_SIGNAL_DRAW_DONE,
+                                       NULL,
+                                       &err) == FALSE) {
+               _E("g_dbus_connection_emit_signal() is failed. %s",
+                               err->message);
                return -1;
        }
 
-       if (dbus_connection_send(bus, message, NULL) == FALSE) {
-               _E("dbus send error");
+       if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE) {
+               _E("g_dbus_connection_flush_sync() is failed. %s",
+                               err->message);
                return -1;
        }
 
-       dbus_connection_flush(bus);
-       dbus_message_unref(message);
+       g_clear_error(&err);
 
        _I("send a alpm update done signal");
 
index a3178e500b9e0a89b85325583cec249f466eb218..69c54a554b778706e6aa8168af18eae222cc7a50 100755 (executable)
@@ -17,8 +17,6 @@
 #ifndef __APPCORE_WATCH_SIGNAL_H__
 #define __APPCORE_WATCH_SIGNAL_H__
 
-#include <dbus/dbus.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -33,7 +31,7 @@ extern "C" {
 #define CLOCK_START "clockbegin"
 #define CLOCK_STOP "clockstop"
 
-int _watch_core_listen_alpm_handler(int (*func) (int, void *), void *data);
+int _watch_core_listen_alpm_handler(int (*func)(int, void *), void *data);
 int _watch_core_send_alpm_update_done(void);
 
 #ifdef __cplusplus