Use private dbus connection for synchronous calls.
[platform/core/system/libstorage.git] / src / storage-external-dbus.c
index 1b71d56..de90ace 100755 (executable)
@@ -28,7 +28,7 @@
 #include <glib.h>
 #include <sys/statvfs.h>
 #include <tzplatform_config.h>
-#include <libsyscommon/dbus-system.h>
+#include <libsyscommon/libgdbus.h>
 #include <libsyscommon/list.h>
 
 #include "log.h"
 
 #define DBUS_REPLY_TIMEOUT (-1)
 
+#define GET_DBUS_CONN_OR_EXIT() \
+       ({ \
+               dbus_handle_h dbus_handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, true); \
+               if (dbus_handle == NULL) { \
+                       _E("Failed to get dbus connection"); \
+                       return -EIO; \
+               } \
+               dbus_handle; \
+       })
+
+
 struct storage_ext_callback {
        storage_ext_changed_cb func;
        void *data;
@@ -104,12 +115,18 @@ int storage_ext_get_list(GList **list)
        if (!list)
                return -EINVAL;
 
-       ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        STORAGE_EXT_GET_LIST,
                        g_variant_new("(s)", "all"),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE
                return -EIO;
@@ -173,12 +190,18 @@ int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf)
 
        memset(buf, 0, sizeof(struct statvfs_32));
 
-       ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_STORAGE,
                        STORAGE_EXT_IFACE_STORAGE,
                        STORAGE_EXT_GET_STATVFS,
                        g_variant_new("(s)", path),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE
                return -EIO;
@@ -220,12 +243,18 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf)
 
        memset(buf, 0, sizeof(struct statvfs));
 
-       ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_STORAGE,
                        STORAGE_EXT_IFACE_STORAGE,
                        STORAGE_EXT_GET_STATVFS,
                        g_variant_new("(s)", path),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE
                return -EIO;
@@ -265,12 +294,19 @@ int storage_ext_get_storage_level(const char *path, char **level)
                return -EINVAL;
        }
 
-       ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(
+                       dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_STORAGE,
                        STORAGE_EXT_IFACE_STORAGE,
                        STORAGE_EXT_GET_STORAGE_LEVEL,
                        g_variant_new("(i)", id),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                _E("Failed to get %d level", id);
                return -EIO;
@@ -407,7 +443,7 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data)
                //LCOV_EXCL_STOP
        }
 
-       block_id = subscribe_dbus_signal(NULL, NULL,
+       block_id = gdbus_signal_subscribe(NULL, NULL,
                        STORAGE_EXT_IFACE_MANAGER,
                        NULL,
                        storage_ext_changed,
@@ -443,7 +479,7 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func)
                if (callback->func != func)
                        continue;
                if (callback->block_id > 0)
-                       unsubscribe_dbus_signal(NULL, callback->block_id);
+                       gdbus_signal_unsubscribe(NULL, callback->block_id);
 
                SYS_G_LIST_REMOVE(changed_list, callback);
                free(callback);
@@ -455,12 +491,18 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info)
        GVariant *reply;
        int ret_dbus;
 
-       ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        "GetDeviceInfo",
                        g_variant_new("(i)", storage_id),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                _E("There is no storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
                return -ENODEV;