int ms_sys_get_device_list(GSList **dev_list)
{
- GDBusConnection *g_bus = NULL;
- GError *error = NULL;
- GVariant *reply_var = NULL;
+ g_autoptr(GDBusConnection) g_bus = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) reply_var = NULL;
+ g_autoptr(GVariant) devices_var = NULL;
GVariantIter iter;
GVariant *block_device = NULL;
int state = 0;
g_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!g_bus) {
MS_DBG_ERR("Failed to connect to the g D-BUS daemon: %s", error->message);
- g_error_free(error);
return MS_MEDIA_ERR_INTERNAL;
}
BLOCK_DEVICE_METHOD,
g_variant_new("(s)", BLOCK_DEVICE_ALL),
NULL,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (!reply_var) {
MS_DBG_ERR("Failed to get GVariant[%s]", error->message);
- g_error_free(error);
- g_object_unref(g_bus);
return MS_MEDIA_ERR_INTERNAL;
}
- g_variant_iter_init(&iter, reply_var);
+ devices_var = g_variant_get_child_value(reply_var, 0);
+ if (g_variant_iter_init(&iter, devices_var) == 0) {
+ MS_DBG_INFO("There is no external storage mounted..");
+ return MS_MEDIA_ERR_NONE;
+ }
while ((block_device = g_variant_iter_next_value(&iter))) {
- if (g_variant_n_children(block_device) == 0) {
- MS_DBG_INFO("There is no external storage mounted..");
- g_variant_unref(block_device);
- break;
- }
-
g_variant_get_child(block_device, 9, "i", &state);
if (state == 0) {
+ MS_DBG_INFO("invalid state");
g_variant_unref(block_device);
continue;
}
g_variant_unref(block_device);
}
- g_variant_unref(reply_var);
- g_object_unref(g_bus);
-
MS_DBG_FLEAVE();
return MS_MEDIA_ERR_NONE;