From 9a408929dd7d252197bcd1dcbc1bd0d497b37e72 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 18 Jan 2016 13:33:15 +0900 Subject: [PATCH] Use gdbus instead of dbus-glib Change-Id: I2fe3b2be992683b93eca14843f120e32a56b2d6d Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 2 +- packaging/app-core.spec | 2 +- src/appcore-efl.c | 66 +++++++++++++---------------- src/appcore.c | 109 ++++++++++++++++++------------------------------ 4 files changed, 71 insertions(+), 108 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54923d5..b411592 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ ENDIF(_APPFW_FEATURE_BACKGROUND_MANAGEMENT) SET(HEADERS_common appcore-common.h) INCLUDE(FindPkgConfig) -SET(APPCORE_PKG_CHECK_MODULES "dbus-glib-1 vconf sensor aul dlog libtzplatform-config ecore") +SET(APPCORE_PKG_CHECK_MODULES "gio-2.0 vconf sensor aul dlog libtzplatform-config ecore") IF(_WITH_X11) SET(APPCORE_PKG_CHECK_MODULES "${APPCORE_PKG_CHECK_MODULES} x11 eina ecore-x") ENDIF(_WITH_X11) diff --git a/packaging/app-core.spec b/packaging/app-core.spec index 9441160..5a103e4 100644 --- a/packaging/app-core.spec +++ b/packaging/app-core.spec @@ -18,7 +18,7 @@ BuildRequires: pkgconfig(ecore-wayland) %endif %endif Source1001: app-core.manifest -BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(sensor) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(aul) diff --git a/src/appcore-efl.c b/src/appcore-efl.c index a261aa4..b30e865 100644 --- a/src/appcore-efl.c +++ b/src/appcore-efl.c @@ -1,9 +1,5 @@ /* - * app-core - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ #include @@ -44,14 +39,17 @@ #include #include #include -#include -#include +#include #include #include #include "appcore-internal.h" #include "appcore-efl.h" +#define RESOURCED_PROCESS_PATH "/Org/Tizen/ResourceD/Process" +#define RESOURCED_PROCESS_INTERFACE "org.tizen.resourced.process" +#define RESOURCED_PROCSTATUS_SIGNAL "ProcStatus" + static pid_t _pid; static bool resource_reclaiming = TRUE; static int tmp_val = 0; @@ -133,43 +131,37 @@ static struct ui_wm_rotate wm_rotate; #endif static Eina_Bool __visibility_cb(void *data, int type, void *event); -static void _send_to_resourced(enum proc_status_type type) +static void __send_to_resourced(enum proc_status_type type) { - DBusConnection *conn; - DBusMessage* msg; - DBusError dbus_error; + GDBusConnection *conn; + GError *err = NULL; - dbus_error_init(&dbus_error); - - conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error); + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); if (!conn) { - _ERR("dbus_bus_get failed : [%s]", dbus_error.message); - dbus_error_free(&dbus_error); - return; - } - - msg = dbus_message_new_signal("/Org/Tizen/ResourceD/Process", - "org.tizen.resourced.process", - "ProcStatus"); - if (!msg) { - _ERR("dbus_message_new_signal is failed"); + _ERR("g_bus_bus_get() is failed: [%s]", err->message); + g_error_free(err); return; } - if (!dbus_message_append_args(msg, - DBUS_TYPE_INT32, &type, - DBUS_TYPE_INT32, &_pid, - DBUS_TYPE_INVALID)) { - _ERR("dbus_message_append_args is failed. type = %d, pid = %d", - type, _pid); - dbus_message_unref(msg); + if (g_dbus_connection_emit_signal(conn, + NULL, + RESOURCED_PROCESS_PATH, + RESOURCED_PROCESS_INTERFACE, + RESOURCED_PROCSTATUS_SIGNAL, + g_variant_new("(ii)", type, _pid), + &err) == FALSE) { + _ERR("g_dbus_connection_emit_signal() is failed: [%s]", + err->message); + g_error_free(err); return; } - if (!dbus_connection_send(conn, msg, NULL)) - _ERR("dbus_connection_send is failed"); + if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE) + _ERR("g_dbus_connection_flush_sync() is failed: [%s]", + err->message); - dbus_message_unref(msg); + g_clear_error(&err); + g_object_unref(conn); } static GSList *g_winnode_list; @@ -403,7 +395,7 @@ static void __do_app(enum app_event event, void *data, bundle * b) /* TODO : rotation stop */ /* r = appcore_pause_rotation_cb(); */ aul_status_update(STATUS_BG); - _send_to_resourced(PROC_STATUS_BACKGRD); + __send_to_resourced(PROC_STATUS_BACKGRD); break; case AE_RESUME: LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]", @@ -434,7 +426,7 @@ static void __do_app(enum app_event event, void *data, bundle * b) LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]", ui->name); aul_status_update(STATUS_VISIBLE); - _send_to_resourced(PROC_STATUS_FOREGRD); + __send_to_resourced(PROC_STATUS_FOREGRD); break; case AE_TERMINATE_BGAPP: if (ui->state == AS_PAUSED) { diff --git a/src/appcore.c b/src/appcore.c index 2d12064..8c6c9cc 100644 --- a/src/appcore.c +++ b/src/appcore.c @@ -1,9 +1,5 @@ /* - * app-core - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ @@ -40,8 +35,7 @@ #include "appcore-internal.h" #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT -#include -#include +#include #define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer" #define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer" @@ -147,8 +141,8 @@ static struct evt_ops evtops[] = { }; #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT -static DBusConnection *bus = NULL; -static int __suspend_dbus_handler_initialized = 0; +static GDBusConnection *bus = NULL; +static guint __suspend_dbus_handler_initialized = 0; #endif static int __get_dir_name(char *dirname) @@ -759,88 +753,65 @@ EXPORT_API int appcore_flush_memory(void) } #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT -static DBusHandlerResult __suspend_dbus_signal_filter(DBusConnection *conn, - DBusMessage *message, void *user_data) -{ - const char *sender; - const char *interface; - int pid; - int state; - int suspend; - - 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) { - _ERR("reject by security issue - no interface\n"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - if (dbus_message_is_signal(message, interface, RESOURCED_FREEZER_SIGNAL)) { - if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &state, - DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID) == FALSE) { - _ERR("Failed to get data: %s", error.message); - dbus_error_free(&error); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - if (pid == getpid() && state == 0) { /* thawed */ - suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND; - SECURE_LOGD("[__SUSPEND__] state: %d (0: thawed, 1: frozen), pid: %d", state, pid); - - struct appcore *ac = (struct appcore *)user_data; - if (!ac->allowed_bg && ac->suspended_state) { +static void __suspend_dbus_signal_handler(GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + struct appcore *ac = (struct appcore *)user_data; + gint suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND; + gint pid; + gint status; + + if (g_strdmp0(signal_name, RESOURCED_FREEZER_SIGNAL) == 0) { + g_variant_get(parameters, "(ii)", &status, &pid); + if (pid == getpid() && status == 0) { /* thawed */ + if (ac && !ac->allowed_bg && ac->suspended_state) { __remove_suspend_timer(ac); - __sys_do(user_data, &suspend, SE_SUSPENDED_STATE); + __sys_do(ac, &suspend, SE_SUSPENDED_STATE); ac->suspended_state = false; __add_suspend_timer(ac); } } } - - return DBUS_HANDLER_RESULT_HANDLED; } int _appcore_init_suspend_dbus_handler(void *data) { - DBusError error; - char rule[MAX_LOCAL_BUFSZ]; + GError *err = NULL; if (__suspend_dbus_handler_initialized) return 0; - dbus_error_init(&error); if (!bus) { - bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); + bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); if (!bus) { - _ERR("Failed to connect to the D-BUS daemon: %s", error.message); - dbus_error_free(&error); + _ERR("Failed to connect to the D-BUS daemon: %s", + err->message); + g_error_free(err); return -1; } } - dbus_connection_setup_with_g_main(bus, NULL); - - snprintf(rule, MAX_LOCAL_BUFSZ, - "path='%s',type='signal',interface='%s'", RESOURCED_FREEZER_PATH, RESOURCED_FREEZER_INTERFACE); - /* listening to messages */ - dbus_bus_add_match(bus, rule, &error); - if (dbus_error_is_set(&error)) { - _ERR("Fail to rule set: %s", error.message); - dbus_error_free(&error); - return -1; - } - if (dbus_connection_add_filter(bus, __suspend_dbus_signal_filter, data, NULL) == FALSE) { - _ERR("add filter fail"); + __suspend_dbus_handler_initialized = g_dbus_connection_signal_subscribe( + bus, + NULL, + RESOURCED_FREEZER_PATH, + RESOURCED_FREEZER_SIGNAL, + RESOURCED_FREEZER_INTERFACE, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + __suspend_dbus_signal_handler, + data, + NULL); + if (__suspend_dbus_handler_initialized == 0) { + _E("g_dbus_connection_signal_subscribe() is failed."); return -1; } - __suspend_dbus_handler_initialized = 1; _DBG("[__SUSPEND__] suspend signal initialized"); return 0; -- 2.7.4