diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2016-06-24 09:29:30 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2016-06-24 09:29:30 +0900 |
commit | a4e9b4594f65e07023f35db38c8571a73450689a (patch) | |
tree | e80221a0292502ec0040af6475236c58ebdeb23c | |
parent | c43e5fe6d1351bb29f6ebbb54c235404774a62ad (diff) | |
download | appcore-watch-a4e9b4594f65e07023f35db38c8571a73450689a.tar.gz appcore-watch-a4e9b4594f65e07023f35db38c8571a73450689a.tar.bz2 appcore-watch-a4e9b4594f65e07023f35db38c8571a73450689a.zip |
Use gdbus instead of dbus-glibsubmit/tizen_common/20160701.180000submit/tizen/20160627.042541accepted/tizen/wearable/20160629.015538accepted/tizen/tv/20160629.015734accepted/tizen/mobile/20160629.015618accepted/tizen/ivi/20160629.015700accepted/tizen/common/20160703.125822
Change-Id: I73cded5e4865e10669cf12b7164740292f14193b
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | packaging/appcore-watch.spec | 3 | ||||
-rwxr-xr-x | src/appcore-watch-signal.c | 133 | ||||
-rwxr-xr-x | src/appcore-watch-signal.h | 4 |
4 files changed, 60 insertions, 83 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c27e0d..2e216ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") diff --git a/packaging/appcore-watch.spec b/packaging/appcore-watch.spec index fa9c568..5e69f1a 100644 --- a/packaging/appcore-watch.spec +++ b/packaging/appcore-watch.spec @@ -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 diff --git a/src/appcore-watch-signal.c b/src/appcore-watch-signal.c index a281fdf..c3830ee 100755 --- a/src/appcore-watch-signal.c +++ b/src/appcore-watch-signal.c @@ -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" @@ -38,92 +38,64 @@ #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"); diff --git a/src/appcore-watch-signal.h b/src/appcore-watch-signal.h index a3178e5..69c54a5 100755 --- a/src/appcore-watch-signal.h +++ b/src/appcore-watch-signal.h @@ -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 |