Replace IPC using dbus to using gdbus 97/52097/1 accepted/tizen/mobile/20151120.070656 accepted/tizen/tv/20151120.070706 accepted/tizen/wearable/20151120.070713 submit/tizen/20151120.020949
authorJi Yong Min <jiyong.min@samsung.com>
Thu, 19 Nov 2015 05:06:27 +0000 (14:06 +0900)
committerJi Yong Min <jiyong.min@samsung.com>
Thu, 19 Nov 2015 05:08:04 +0000 (14:08 +0900)
Change-Id: Ib2b9a05fd76444ae2e998bc208386d2e3d1ff1b3
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
lib/media-util-noti-internal.c
packaging/media-server.spec
src/common/media-common-system.c

index 269c77b..781645a 100755 (executable)
@@ -33,9 +33,7 @@
 #include <sys/stat.h>
 #include <string.h>
 #include <glib.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
 
 #include "media-util-internal.h"
 #include "media-util-dbg.h"
 
 GArray *handle_list_internal;
 static GMutex mutex_internal;
-int ref_count;
 
 #define MS_MEDIA_DBUS_NAME_INTERNAL "ms_db_updated_internal"
 
 typedef struct internal_noti_cb_data {
-       DBusConnection *dbus;
+       GDBusConnection *gdbus;
+       int handler;
        db_update_cb user_callback;
        void *user_data;
 } internal_noti_cb_data;
@@ -63,192 +61,166 @@ int media_db_update_send_internal(int pid, /* mandatory */
                                                        char *mime_type /* optional */
                                                        )
 {
-       DBusMessage *message = NULL;
-       DBusConnection *bus = NULL;
-       DBusError error;
+       GVariant *message = NULL;
+       GDBusConnection *bus = NULL;
+       GError *error = NULL;
        unsigned char *path_array = NULL;
        int path_length = strlen(path) + 1;
 
-       /* Get a connection to the session bus */
-       dbus_error_init(&error);
-       bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+       bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
        if (!bus) {
-               MSAPI_DBG("Failed to connect to the D-BUS daemon: %s", error.message);
-               dbus_error_free(&error);
+               MSAPI_DBG("Failed to get gdbus connection: %s", error->message);
+               g_error_free(error);
                return MS_MEDIA_ERR_INTERNAL;
        }
 
-       message = dbus_message_new_signal(MS_MEDIA_DBUS_PATH, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME_INTERNAL);
-       if (message != NULL) {
-               path_array = malloc(sizeof(unsigned char) * path_length);
-               memcpy(path_array, path, path_length);
+       MSAPI_DBG("update path[%s]", path);
 
-               if (item == MS_MEDIA_ITEM_FILE) {
-                       MSAPI_DBG("FILE CHANGED");
-                       if (uuid != NULL && mime_type != NULL) {
+       path_array = malloc(sizeof(unsigned char) * path_length);
+       memcpy(path_array, path, path_length);
+
+       if (item == MS_MEDIA_ITEM_FILE) {
+               MSAPI_DBG("FILE CHANGED");
+               if (uuid != NULL && mime_type != NULL) {
                        /* fill all datas */
-                               dbus_message_append_args(message,
-                                                                               DBUS_TYPE_INT32, &item,
-                                                                               DBUS_TYPE_INT32, &pid,
-                                                                               DBUS_TYPE_INT32, &update_type,
-                                                                               DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &path_array, path_length,
-                                                                               DBUS_TYPE_STRING, &uuid,
-                                                                               DBUS_TYPE_INT32, &media_type,
-                                                                               DBUS_TYPE_STRING, &mime_type,
-                                                                               DBUS_TYPE_INVALID);
-                       } else {
-                               MSAPI_DBG_ERR("uuid or mime_type is NULL");
-                               MS_SAFE_FREE(path_array);
-                               dbus_message_unref(message);
-                               return MS_MEDIA_ERR_INVALID_PARAMETER;
-                       }
-               } else if (item == MS_MEDIA_ITEM_DIRECTORY) {
-                       MSAPI_DBG("DIRECTORY CHANGED");
+                       message = g_variant_new("(iiioisis)", item, pid, update_type, path_array, path_length, uuid, media_type, mime_type);
+               } else {
+                       MSAPI_DBG("this request is wrong");
+               }
+       } else if (item == MS_MEDIA_ITEM_DIRECTORY) {
+               MSAPI_DBG("DIRECTORY CHANGED");
+               if (uuid != NULL) {
                        /* fill all datas */
-                       if (uuid != NULL) {
-                               dbus_message_append_args(message,
-                                                                               DBUS_TYPE_INT32, &item,
-                                                                               DBUS_TYPE_INT32, &pid,
-                                                                               DBUS_TYPE_INT32, &update_type,
-                                                                               DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &path_array, path_length,
-                                                                               DBUS_TYPE_STRING, &uuid,
-                                                                               DBUS_TYPE_INVALID);
-                       } else {
-                               dbus_message_append_args(message,
-                                                                               DBUS_TYPE_INT32, &item,
-                                                                               DBUS_TYPE_INT32, &pid,
-                                                                               DBUS_TYPE_INT32, &update_type,
-                                                                               DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &path_array, path_length,
-                                                                               DBUS_TYPE_INVALID);
-                       }
+                       message = g_variant_new("(iiiois)", item, pid, update_type, path_array, path_length, uuid);
                } else {
                        MSAPI_DBG("this request is wrong");
                }
+       } else {
+               MSAPI_DBG("this request is wrong");
+       }
 
-               MS_SAFE_FREE(path_array);
-
-               /* Send the signal */
-               dbus_connection_send(bus, message, NULL);
+       MS_SAFE_FREE(path_array);
 
-               /* Free the signal now we have finished with it */
-               dbus_message_unref(message);
+       if (message == NULL) {
+               MSAPI_DBG_ERR("g_dbus_message_new_signal failed");
+               return MS_MEDIA_ERR_INTERNAL;
+       }
 
-               MSAPI_DBG_ERR("success send notification");
-       } else {
-               MSAPI_DBG_ERR("dbus_message_new_signal failed");
+       /* Send the signal */
+       gboolean emmiting = g_dbus_connection_emit_signal(
+                                       bus,
+                                       NULL,
+                                       MS_MEDIA_DBUS_PATH,
+                                       MS_MEDIA_DBUS_INTERFACE,
+                                       MS_MEDIA_DBUS_NAME_INTERNAL,
+                                       message,
+                                       &error);
+       if (!emmiting) {
+               MSAPI_DBG_ERR("g_dbus_connection_emit_signal failed : %s", error ? error->message : "none");
+               if (error) {
+                       MSAPI_DBG_ERR("Error in g_dbus_connection_emit_signal");
+                       g_object_unref(bus);
+                       g_error_free(error);
+               }
+               return MS_MEDIA_ERR_INTERNAL;
        }
+       MSAPI_DBG_ERR("success send notification");
 
-       dbus_connection_unref(bus);
+       g_object_unref(bus);
 
        /* Return TRUE to tell the event loop we want to be called again */
        return MS_MEDIA_ERR_NONE;
 }
 
-
-DBusHandlerResult
-__get_message_internal(DBusMessage *message, db_update_cb user_cb, void *userdata)
+static bool __gdbus_message_is_signal(const char *iface, const char *signal)
 {
-       /* A Ping signal on the com.burtonini.dbus.Signal interface */
-       if (dbus_message_is_signal(message, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME_INTERNAL)) {
-               int i = 0;
-               int current_type = DBUS_TYPE_INVALID;
-               DBusError error;
-               DBusMessageIter read_iter;
-               DBusBasicValue value[6];
-
-               dbus_int32_t item = -1;
-               dbus_int32_t pid = 0;
-               dbus_int32_t update_type = MS_MEDIA_UNKNOWN;
-               dbus_int32_t content_type = -1;
-               char *update_path = NULL;
-               char *uuid = NULL;
-               char *mime_type = NULL;
-               void *recevie_path = NULL;
-               int path_len = 0;
-
-               dbus_error_init(&error);
-               MSAPI_DBG("size [%d]", sizeof(value));
-               memset(value, 0x0, sizeof(value));
-
-               /* get data from dbus message */
-               dbus_message_iter_init(message, &read_iter);
-               while ((current_type = dbus_message_iter_get_arg_type(&read_iter)) != DBUS_TYPE_INVALID) {
-                       if (current_type == DBUS_TYPE_ARRAY) {
-                               DBusMessageIter sub;
-                               dbus_message_iter_recurse(&read_iter, &sub);
-                               dbus_message_iter_get_fixed_array(&sub, &recevie_path, &path_len);
-                       } else {
-                               dbus_message_iter_get_basic(&read_iter, &value[i]);
-                               i++;
-                       }
-                       dbus_message_iter_next(&read_iter);
-               }
+       if ((strcmp(iface, MS_MEDIA_DBUS_INTERFACE) == 0) && (strcmp(signal, MS_MEDIA_DBUS_NAME_INTERNAL) == 0))
+               return TRUE;
 
-               item = value[0].i32;
-               pid = value[1].i32;
-               update_type = value[2].i32;
-               update_path = strndup(recevie_path, path_len);
-               if (value[3].str != NULL) uuid = strdup(value[3].str);
-               content_type = value[4].i32;
-               if (value[5].str != NULL) mime_type = strdup(value[5].str);
-
-               if (item == MS_MEDIA_ITEM_DIRECTORY)
-                       content_type = MS_MEDIA_UNKNOWN;
-
-               /* getting data complete */
-               MSAPI_DBG("update type[%d]", update_type);
-               user_cb(pid,
-                               item,
-                               update_type,
-                               update_path,
-                               uuid,
-                               content_type,
-                               mime_type,
-                               userdata);
-
-               MS_SAFE_FREE(update_path);
-               MS_SAFE_FREE(uuid);
-               MS_SAFE_FREE(mime_type);
-
-               return DBUS_HANDLER_RESULT_HANDLED;
-       }
-
-       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+       return FALSE;
 }
 
-DBusHandlerResult
-__message_filter_internal(DBusConnection *connection, DBusMessage *message, void *user_data)
+static void __get_message_internal(GVariant *message, db_update_cb user_cb, void *userdata)
 {
-       db_update_cb user_cb = ((internal_noti_cb_data*)user_data)->user_callback;
-       void *userdata = ((internal_noti_cb_data*)user_data)->user_data;
-       DBusHandlerResult ret;
+       gint32 item = -1;
+       gint32 pid = 0;
+       gint32 update_type = MS_MEDIA_UNKNOWN;
+       gint32 content_type = -1;
+       char *update_path = NULL;
+       char *uuid = NULL;
+       char *mime_type = NULL;
+       char *receive_path = NULL;
+       int path_len = 0;
+
+       int item_number = g_variant_n_children(message);
+
+       if (item_number == 8)
+               g_variant_get(message, "(iiioisis)", &item, &pid, &update_type, &receive_path, &path_len, &uuid, &content_type, &mime_type);
+       else if (item_number == 6)
+               g_variant_get(message, "(iiiois)", &item, &pid, &update_type, &receive_path, &path_len, &uuid);
+
+       update_path = strndup(receive_path, path_len);
+       MSAPI_DBG("update path[%s]", update_path);
+
+       if (item == MS_MEDIA_ITEM_DIRECTORY)
+               content_type = MS_MEDIA_UNKNOWN;
+
+       /* getting data complete */
+       user_cb(pid,
+                       item,
+                       update_type,
+                       update_path,
+                       uuid,
+                       content_type,
+                       mime_type,
+                       userdata);
+
+       MS_SAFE_FREE(update_path);
+       MS_SAFE_FREE(uuid);
+       MS_SAFE_FREE(mime_type);
+}
 
-       ret = __get_message_internal(message, user_cb, userdata);
+static void __message_filter_internal(GDBusConnection* connection,
+                                       const gchar* sender_name,
+                                       const gchar* object_path,
+                                       const gchar* interface_name,
+                                       const gchar* signal_name,
+                                       GVariant* parameters,
+                                       gpointer user_data)
+{
+       if (__gdbus_message_is_signal(interface_name, signal_name)) {
+               db_update_cb user_cb = ((internal_noti_cb_data*)user_data)->user_callback;
+               void *userdata = ((internal_noti_cb_data*)user_data)->user_data;
 
-       return ret;
+               __get_message_internal(parameters, user_cb, userdata);
+       }
 }
 
 int media_db_update_subscribe_internal(MediaNotiHandle *handle, db_update_cb user_cb, void *user_data)
 {
        int ret = MS_MEDIA_ERR_NONE;
+       int handler = 0;
        internal_noti_cb_data *noti_data = NULL;
-       DBusError error;
-       DBusConnection *dbus;
-
-       dbus_g_thread_init();
-
-       dbus_error_init(&error);
-
-       dbus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
-       if (!dbus) {
-               MSAPI_DBG("Failed to connect to the D-BUS daemon: %s", error.message);
-               dbus_error_free(&error);
-               ret = MS_MEDIA_ERR_INTERNAL;
-               goto ERROR;
+       GError *error = NULL;
+       GDBusConnection *gdbus = NULL;
+
+       if (gdbus == NULL) {
+               gchar *address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+               if (!address) {
+                       MSAPI_DBG_ERR("Failed to get the address: %s", error ? error->message : "none");
+                       g_error_free(error);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
+               MSAPI_DBG("\tType(%s)", address);
+               gdbus = g_dbus_connection_new_for_address_sync(address, G_DBUS_CONNECTION_FLAGS_NONE, NULL, NULL, &error);
+//             gdbus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+               if (!gdbus) {
+                       MSAPI_DBG_ERR("Failed to connect to the g D-BUS daemon: %s", error ? error->message : "none");
+                       g_error_free(error);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
        }
 
-       dbus_connection_setup_with_g_main(dbus, NULL);
-
        MS_MALLOC(noti_data, sizeof(internal_noti_cb_data));
        if (noti_data == NULL) {
                MSAPI_DBG_ERR("MS_MALLOC failed");
@@ -258,15 +230,20 @@ int media_db_update_subscribe_internal(MediaNotiHandle *handle, db_update_cb use
        noti_data->user_callback = user_cb;
        noti_data->user_data = user_data;
 
-       /* listening to messages from all objects as no path is specified */
-       dbus_bus_add_match(dbus, MS_MEDIA_DBUS_MATCH_RULE, &error);
-       if (!dbus_connection_add_filter(dbus, __message_filter_internal, noti_data, NULL)) {
-               dbus_bus_remove_match(dbus, MS_MEDIA_DBUS_MATCH_RULE, NULL);
-               ret = MS_MEDIA_ERR_INTERNAL;
-               goto ERROR;
-       }
-
-       noti_data->dbus = dbus;
+       handler = g_dbus_connection_signal_subscribe(
+                                               gdbus,
+                                               NULL,
+                                               MS_MEDIA_DBUS_INTERFACE,
+                                               MS_MEDIA_DBUS_NAME_INTERNAL,
+                                               MS_MEDIA_DBUS_PATH,
+                                               NULL,
+                                               G_DBUS_SIGNAL_FLAGS_NONE,
+                                               __message_filter_internal,
+                                               noti_data,
+                                               NULL);
+
+       noti_data->gdbus = gdbus;
+       noti_data->handler = handler;
        *handle = noti_data;
 
        g_mutex_lock(&mutex_internal);
@@ -288,10 +265,9 @@ int media_db_update_subscribe_internal(MediaNotiHandle *handle, db_update_cb use
 
 ERROR:
 
-       if (dbus != NULL) {
-               dbus_connection_close(dbus);
-               dbus_connection_unref(dbus);
-               dbus = NULL;
+       if (gdbus != NULL) {
+               g_object_unref(gdbus);
+               gdbus = NULL;
        }
 
        MS_SAFE_FREE(noti_data);
@@ -343,12 +319,9 @@ int media_db_update_unsubscribe_internal(MediaNotiHandle handle, clear_user_data
 
        err = _find_handle(handle, &idx);
        if (err == MS_MEDIA_ERR_NONE) {
-               DBusConnection *dbus = ((internal_noti_cb_data*)handle)->dbus;
-
-               dbus_connection_remove_filter(dbus, __message_filter_internal, (internal_noti_cb_data*)handle);
-               dbus_bus_remove_match(dbus, MS_MEDIA_DBUS_MATCH_RULE, NULL);
-               dbus_connection_close(dbus);
-               dbus_connection_unref(dbus);
+               GDBusConnection *gdbus = ((internal_noti_cb_data*)handle)->gdbus;
+               g_dbus_connection_signal_unsubscribe(gdbus, ((internal_noti_cb_data*)handle)->handler);
+               g_object_unref(gdbus);
                g_array_remove_index(handle_list_internal, idx);
 
                if (clear_cb != NULL)
index f187874..d0e23ba 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    File manager service server.
-Version:    0.2.63
+Version:    0.2.64
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
index 1e5c50f..907806a 100755 (executable)
@@ -24,9 +24,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <gio/gio.h>
-#include <dbus/dbus-glib.h>
 #include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
 #include <sys/stat.h>
 
 #include "media-util.h"
@@ -367,70 +365,98 @@ int ms_sys_release_device_list(GArray **dev_list)
 #define UID_DBUS_INTERFACE      UID_DBUS_NAME".Manager"
 #define UID_DBUS_METHOD                 "ListUsers"
 
-static int __ms_dbus_get_uid(const char *dest, const char *path, const char *interface, const char *method, uid_t *uid)
+static int __ms_gdbus_get_uid(const char *dest, const char *path, const char *interface, const char *method, uid_t *uid)
 {
-       DBusConnection *conn;
-       DBusMessage *msg;
-       DBusMessageIter iiiter;
-       DBusMessage *reply;
-       DBusError err;
-       DBusMessageIter iter;
-       DBusMessageIter aiter, piter;
-       int result;
+       GDBusConnection *gdbus = NULL;
+       GError *error = NULL;
+       GDBusMessage *message = NULL;
+       GDBusMessage *reply = NULL;
+       GVariant *reply_var = NULL;
+       GVariantIter *iter;
+       char *type_str = NULL;
+       int val_int = 0;
+       char *val_str = NULL;
+       char *val_str2 = NULL;
+
+       int result = 0;
+       int ret = MS_MEDIA_ERR_NONE;
 
-       int val_int;
-       char *val_str;
+       MS_DBG_FENTER();
 
-       conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-       if (!conn) {
-               MS_DBG_ERR("dbus_bus_get error");
-               return MS_MEDIA_ERR_INTERNAL;
+       if (gdbus == NULL) {
+               gdbus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+               if (!gdbus) {
+                       MS_DBG_ERR("Failed to connect to the g D-BUS daemon: %s", error ? error->message : "none");
+                       g_error_free(error);
+                       ret = MS_MEDIA_ERR_INTERNAL;
+                       goto ERROR;
+               }
        }
 
-       msg = dbus_message_new_method_call(dest, path, interface, method);
-       if (!msg) {
-               MS_DBG_ERR("dbus_message_new_method_call(%s:%s-%s)",
+       message = g_dbus_message_new_method_call (dest, path, interface, method);
+       if (!message) {
+               MS_DBG_ERR("g_dbus_message_new_method_call(%s:%s-%s)",
                path, interface, method);
-               return MS_MEDIA_ERR_INTERNAL;
+               ret = MS_MEDIA_ERR_INTERNAL;
+               goto ERROR;
        }
 
-       dbus_message_iter_init_append(msg, &iiiter);
+       reply = g_dbus_connection_send_message_with_reply_sync(gdbus, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, NULL, &error);
+       if (!reply) {
+               MS_DBG_ERR("Failed to connect to the g D-BUS daemon: %s", error ? error->message : "none");
+               g_error_free(error);
+               ret = MS_MEDIA_ERR_INTERNAL;
+               goto ERROR;
+       }
 
-       dbus_error_init(&err);
+       reply_var = g_dbus_message_get_body(reply);
+       if (!reply_var) {
+               MS_DBG_ERR("Failed to get the body of message");
+               ret = MS_MEDIA_ERR_INTERNAL;
+               goto ERROR;
+       }
 
-       reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
-       dbus_message_unref(msg);
-       if (!reply) {
-               MS_DBG_ERR("dbus_connection_send error(%s:%s) %s %s:%s-%s",
-               err.name, err.message, dest, path, interface, method);
-               dbus_error_free(&err);
-               return MS_MEDIA_ERR_INTERNAL;
+       type_str = (char *)g_variant_get_type_string(reply_var);
+       if (!type_str) {
+               MS_DBG_ERR("Failed to get the type-string of message");
+               ret = MS_MEDIA_ERR_INTERNAL;
+               goto ERROR;
        }
 
-       dbus_message_iter_init(reply, &iter);
-       dbus_message_iter_recurse(&iter, &aiter);
+       g_variant_get(reply_var, type_str, &iter);
 
-       result = 0;
-       while (dbus_message_iter_get_arg_type(&aiter) != DBUS_TYPE_INVALID) {
+       while(g_variant_iter_loop(iter, "(uso)", &val_int, &val_str, &val_str2)) {
                result++;
                MS_DBG("(%d)th block device information", result);
-
-               dbus_message_iter_recurse(&aiter, &piter);
-               dbus_message_iter_get_basic(&piter, &val_int);
                MS_DBG("\tType(%d)", val_int);
-
-               dbus_message_iter_next(&piter);
-               dbus_message_iter_get_basic(&piter, &val_str);
                MS_DBG("\tdevnode(%s)", val_str);
+               MS_DBG("\tsyspath(%s)", val_str2);
+               *uid = (uid_t) val_int;
+               MS_SAFE_FREE(val_str);
+               MS_SAFE_FREE(val_str2);
+       }
 
-               dbus_message_iter_next(&piter);
-               dbus_message_iter_get_basic(&piter, &val_str);
-               MS_DBG("\tsyspath(%s)", val_str);
+ERROR:
 
-               dbus_message_iter_next(&aiter);
-       }
+       if (iter != NULL)
+               g_variant_iter_free(iter);
+
+       if (reply_var != NULL)
+               g_variant_unref(reply_var);
+
+       if (message != NULL)
+               g_object_unref(message);
+
+       if (reply != NULL)
+               g_object_unref(reply);
+
+       if (gdbus != NULL)
+               g_object_unref(gdbus);
+
+       MS_DBG_FLEAVE();
 
-       *uid = (uid_t) val_int;
+       if (ret != MS_MEDIA_ERR_NONE)
+               return ret;
 
        return result;
 }
@@ -439,7 +465,7 @@ int ms_sys_get_uid(uid_t *uid)
 {
        int ret;
 
-       ret = __ms_dbus_get_uid(UID_DBUS_NAME, UID_DBUS_PATH, UID_DBUS_INTERFACE, UID_DBUS_METHOD, uid);
+       ret = __ms_gdbus_get_uid(UID_DBUS_NAME, UID_DBUS_PATH, UID_DBUS_INTERFACE, UID_DBUS_METHOD, uid);
        if (ret < 0) {
                MS_DBG("Failed to send dbus (%d)", ret);
        } else {
@@ -463,74 +489,74 @@ typedef struct pwoff_cb_data {
        void *usr_data;
 } pwoff_cb_data;
 
-DBusConnection *g_pwr_dbus;
+static GDBusConnection *g_pwr_bus;
+static int g_pwr_handler;
 
 pwoff_cb_data *g_pwr_cb_data = NULL;
 
-static DBusHandlerResult __poweroff_msg_filter(DBusConnection *connection, DBusMessage *message, void *user_data)
+static void __poweroff_signal_cb(GDBusConnection *connection,
+                                                                       const gchar *sender_name,
+                                                                       const gchar *object_path,
+                                                                       const gchar *interface_name,
+                                                                       const gchar *signal_name,
+                                                                       GVariant *parameters,
+                                                                       gpointer user_data)
 {
        pwoff_cb_data *cb_data = (pwoff_cb_data *)user_data;
        void *usr_cb = cb_data->usr_cb;
        void *usr_data = cb_data->usr_data;
+       char *type_str = NULL;
+       int val_int = 0;
+
+       power_off_cb cb_func = (power_off_cb)usr_cb;
+       ms_power_info_s *power_info = NULL;
 
        MS_DBG_FENTER();
 
-       /* A Ping signal on the com.burtonini.dbus.Signal interface */
-       if (dbus_message_is_signal(message, POWER_DBUS_INTERFACE, POWER_DBUS_NAME)) {
-               int current_type = DBUS_TYPE_INVALID;
-               DBusError error;
-               DBusMessageIter read_iter;
-               DBusBasicValue value;
-               power_off_cb cb_func = (power_off_cb)usr_cb;
-               ms_power_info_s *power_info = NULL;
-
-               dbus_error_init(&error);
-
-               /* get data from dbus message */
-               dbus_message_iter_init(message, &read_iter);
-               while ((current_type = dbus_message_iter_get_arg_type(&read_iter)) != DBUS_TYPE_INVALID) {
-                       dbus_message_iter_get_basic(&read_iter, &value);
-                       switch (current_type) {
-                               case DBUS_TYPE_INT32:
-                                       MS_DBG_WARN("value[%d]", value.i32);
-                                       break;
-                               default:
-                                       MS_DBG_ERR("current type : %d", current_type);
-                                       break;
-                       }
-
-                       if (value.i32 == 2 || value.i32 == 3) {
-                               MS_DBG_WARN("PREPARE POWER OFF");
-                               break;
-                       }
-
-                       dbus_message_iter_next(&read_iter);
-               }
+       if (!parameters) {
+               MS_DBG_ERR("Error - The body of message is NULL!");
+               return ;
+       }
+
+       type_str = strdup((char *)g_variant_get_type_string(parameters));
+       if (!type_str) {
+               MS_DBG_ERR("Failed to get the type-string of message");
+               return ;
+       }
 
-               if (value.i32 == 2 || value.i32 == 3)
-                       cb_func(power_info, usr_data);
+       if (strcmp(type_str, "(i)") == 0) {
+               g_variant_get(parameters, type_str, &val_int);
+               MS_DBG_WARN("value[%d]", val_int);
+       } else {
+               MS_DBG_ERR("current type : %s", type_str);
+       }
 
-               return DBUS_HANDLER_RESULT_HANDLED;
+       if (val_int == 2 || val_int == 3) {
+               MS_DBG_WARN("PREPARE POWER OFF");
        }
 
-       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+       if (val_int == 2 || val_int == 3)
+               cb_func(power_info, usr_data);
+
+       MS_SAFE_FREE(type_str);
 }
 
 int ms_sys_set_poweroff_cb(power_off_cb user_callback, void *user_data)
 {
-       DBusError error;
+       GError *error = NULL;
 
-       /*add noti receiver for power off*/
-       dbus_error_init(&error);
+       MS_DBG_FENTER();
 
-       g_pwr_dbus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
-       if (!g_pwr_dbus) {
-               MS_DBG_ERR("Failed to connect to the D-BUS daemon: %s", error.message);
-               return MS_MEDIA_ERR_INTERNAL;
+       /*add noti receiver for power off*/
+       if (g_pwr_bus == NULL) {
+               g_pwr_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+               if (!g_pwr_bus) {
+                       MS_DBG_ERR("Failed to connect to the g D-BUS daemon: %s", error?error->message:"none");
+                       g_error_free(error);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
        }
 
-       dbus_connection_setup_with_g_main(g_pwr_dbus, NULL);
-
        g_pwr_cb_data = malloc(sizeof(pwoff_cb_data));
        if (g_pwr_cb_data == NULL) {
                MS_DBG_ERR("malloc failed");
@@ -541,26 +567,31 @@ int ms_sys_set_poweroff_cb(power_off_cb user_callback, void *user_data)
        g_pwr_cb_data->usr_data = user_data;
 
        /* listening to messages from all objects as no path is specified */
-       dbus_bus_add_match(g_pwr_dbus, POWER_DBUS_MATCH_RULE, &error);
-       if (!dbus_connection_add_filter(g_pwr_dbus, __poweroff_msg_filter, g_pwr_cb_data, NULL)) {
-               dbus_bus_remove_match(g_pwr_dbus, POWER_DBUS_MATCH_RULE, NULL);
-               MS_DBG_ERR("dbus_connection_add_filter failed");
-               return MS_MEDIA_ERR_INTERNAL;
-       }
+       g_pwr_handler = g_dbus_connection_signal_subscribe(g_pwr_bus,
+               NULL,
+               POWER_DBUS_INTERFACE,
+               POWER_DBUS_NAME,
+               NULL,
+               NULL,
+               G_DBUS_SIGNAL_FLAGS_NONE,
+               __poweroff_signal_cb,
+               g_pwr_cb_data,
+               NULL);
+
+       MS_DBG_FLEAVE();
 
        return MS_MEDIA_ERR_NONE;
 }
 
 int ms_sys_unset_poweroff_cb(void)
 {
-       if (g_pwr_dbus == NULL) {
+       if (g_pwr_bus == NULL) {
                return MS_MEDIA_ERR_NONE;
        }
 
-       dbus_connection_remove_filter(g_pwr_dbus, __poweroff_msg_filter, g_pwr_cb_data);
-       dbus_bus_remove_match(g_pwr_dbus, MS_MEDIA_DBUS_MATCH_RULE, NULL);
-       dbus_connection_unref(g_pwr_dbus);
-       g_pwr_dbus = NULL;
+       g_dbus_connection_signal_unsubscribe(g_pwr_bus, g_pwr_handler);
+       g_object_unref(g_pwr_bus);
+       g_pwr_bus = NULL;
 
        MS_SAFE_FREE(g_pwr_cb_data);