#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;
int storage_ext_get_list(GList **list)
{
- GVariant *result;
+ GVariant *reply;
GVariantIter *iter;
storage_ext_device *elem, info;
- int ret;
+ int ret, ret_dbus;
if (!list)
return -EINVAL;
- result = 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"));
- if (!result) {
+ 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;
+ return -EIO; //LCOV_EXCL_LINE
}
- if (!g_variant_get_safe(result, "(a(issssssisibii))", &iter)) {
+ if (!g_variant_get_safe(reply, "(a(issssssisibii))", &iter)) {
+ //LCOV_EXCL_START Dbus type error
_E("Failed to get params from gvariant.");
- g_variant_unref(result);
+ g_variant_unref(reply);
return -EIO;
+ //LCOV_EXCL_STOP
}
while (g_variant_iter_loop(iter, "(issssssisibii)",
elem = (storage_ext_device *)malloc(sizeof(storage_ext_device));
if (!elem) {
- _E("malloc() failed"); //LCOV_EXCL_LINE
+ //LCOV_EXCL_START System error
+ _E("malloc() failed");
ret = -ENOMEM;
goto out;
+ //LCOV_EXCL_STOP
}
elem->type = info.type;
if (ret < 0)
storage_ext_release_list(list); //LCOV_EXCL_LINE System Error
g_variant_iter_free(iter);
- g_variant_unref(result);
+ g_variant_unref(reply);
return ret;
}
int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf)
{
- GVariant *result;
+ GVariant *reply;
+ int ret_dbus;
guint64 bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax;
assert(buf);
memset(buf, 0, sizeof(struct statvfs_32));
- result = 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));
- if (!result) {
+ 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;
+ return -EIO; //LCOV_EXCL_LINE
}
- if (!g_variant_get_safe(result, "(ttttttttttt)",
+ if (!g_variant_get_safe(reply, "(ttttttttttt)",
&bsize, &frsize, &blocks,
&bfree, &bavail, &files,
&ffree, &favail, &fsid,
&flag, &namemax)) {
_E("Failed to get params from gvariant.");
- g_variant_unref(result);
+ g_variant_unref(reply);
return -EIO;
}
// %llu bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax
int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf)
{
- GVariant *result;
+ GVariant *reply;
+ int ret_dbus;
assert(buf);
memset(buf, 0, sizeof(struct statvfs));
- result = 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));
- if (!result) {
+ 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;
+ return -EIO; //LCOV_EXCL_LINE
}
- if (!g_variant_get_safe(result, "(ttttttttttt)",
+ if (!g_variant_get_safe(reply, "(ttttttttttt)",
&(buf->f_bsize), &(buf->f_frsize), &(buf->f_blocks),
&(buf->f_bfree), &(buf->f_bavail), &(buf->f_files),
&(buf->f_ffree), &(buf->f_favail), &(buf->f_fsid),
&(buf->f_flag), &(buf->f_namemax))) {
+ //LCOV_EXCL_START Dbus type error
_E("Failed to get params from gvariant.");
- g_variant_unref(result);
+ g_variant_unref(reply);
return -EIO;
+ //LCOV_EXCL_STOP
}
// %lu buf->f_bsize, buf->f_frsize, buf->f_fsid, buf->f_flag, buf->f_namemax
int storage_ext_get_storage_level(const char *path, char **level)
{
- GVariant *result;
- char *tmp;
+ GVariant *reply;
+ int ret_dbus;
+ char *reply_val;
enum tzplatform_variable id;
if (!strcmp(path, tzplatform_getenv(TZ_SYS_USER)))
return -EINVAL;
}
- result = 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));
- if (!result) {
+ g_variant_new("(i)", id),
+ &reply);
+
+ gdbus_free_connection(dbus_handle);
+
+ if (ret_dbus < 0) {
+ //LCOV_EXCL_START Dbus error
_E("Failed to get %d level", id);
return -EIO;
+ //LCOV_EXCL_STOP
}
- if (!g_variant_get_safe(result, "(s)", &tmp)) {
+ if (!g_variant_get_safe(reply, "(s)", &reply_val)) {
+ //LCOV_EXCL_START Dbus type error
_E("Failed to get params from gvariant.");
- g_variant_unref(result);
+ g_variant_unref(reply);
return -EIO;
+ //LCOV_EXCL_STOP
}
- *level = strdup(tmp);
- g_free(tmp);
- g_variant_unref(result);
+ *level = strdup(reply_val);
+ g_free(reply_val);
+ g_variant_unref(reply);
if (*level == NULL)
- return -ENOMEM;
+ return -ENOMEM; //LCOV_EXCL_LINE
return 0;
}
storage_ext_device *dev;
GList *elem;
struct storage_ext_callback *callback;
- int ret;
+ int ret_val;
if (!params)
return;
SYS_G_LIST_FOREACH(changed_list, elem, callback) {
if (!callback->func)
continue;
- ret = callback->func(dev, state, callback->data);
- if (ret < 0)
- _E("Failed to call callback for devnode(%s, %d)", dev->devnode, ret);
+ ret_val = callback->func(dev, state, callback->data);
+ if (ret_val < 0)
+ _E("Failed to call callback for devnode(%s, %d)", dev->devnode, ret_val);
}
storage_ext_release_device(&dev);
//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,
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);
int storage_ext_get_device_info(int storage_id, storage_ext_device *info)
{
- GVariant *result;
- int ret;
+ GVariant *reply;
+ int ret_dbus;
- result = 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));
- if (!result) {
+ 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;
+ return -ENODEV; //LCOV_EXCL_LINE
}
- if (!g_variant_get_safe(result, "(issssssisibii)",
+ if (!g_variant_get_safe(reply, "(issssssisibii)",
&info->type, &info->devnode, &info->syspath,
&info->fs_usage, &info->fs_type,
&info->fs_version, &info->fs_uuid,
&info->readonly, &info->mount_point,
&info->state, &info->primary,
&info->flags, &info->storage_id)) {
- _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
- ret = -ENODEV;
+ //LCOV_EXCL_START Dbus error
+ _E("No storage with the storage id (%d)", storage_id);
+ ret_dbus = -ENODEV;
goto out;
+ //LCOV_EXCL_STOP
}
if (info->storage_id < 0) {
- _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
- ret = -ENODEV;
+ //LCOV_EXCL_START Dbus error
+ _E("No storage with the storage id (%d)", storage_id);
+ ret_dbus = -ENODEV;
goto out;
+ //LCOV_EXCL_STOP
}
- ret = 0;
out:
- g_variant_unref(result);
- return ret;
+ g_variant_unref(reply);
+ return 0;
}