block: dbus: (rework)modified to reply error type message if failed 36/207736/3 accepted/tizen/unified/20190617.061800 submit/tizen/20190617.020453
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Wed, 12 Jun 2019 00:16:42 +0000 (09:16 +0900)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Wed, 12 Jun 2019 00:20:47 +0000 (09:20 +0900)
- reply empty body gvariant if there are no matched device
- reply error type msg if error occured

Change-Id: Iec43b9c22284bb717939d219a3d7ac8f17d1be7e
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
apps/extended-sd/src/es-portable-storage-page.c
src/auto-test/block.c
src/block/block.c

index 5826f58..555d6ba 100644 (file)
@@ -137,6 +137,8 @@ mapper_device_cb(int mapper_id, storage_dev_e dev, storage_state_e state,
                break;
        }
 
+       g_variant_iter_free(iter);
+
        ret = dbus_handle_method_async_with_reply_var(STORAGED_BUS_NAME,
                        STORAGED_PATH_BLOCK_MANAGER,
                        STORAGED_INTERFACE_BLOCK_MANAGER,
index 7098387..262ceb9 100644 (file)
@@ -149,6 +149,8 @@ static bool block_getdevicelist(char *type)
                ret = TRUE;
        }
 
+       g_variant_iter_free(iter);
+
        _I("Success. (%s): %d", METHOD_BLOCK_GETDEVICELIST, ret);
        return ret;
 }
@@ -168,7 +170,7 @@ static bool block_getdevicelist2(char *type)
                g_variant_new("(s)", type));
 
        if (!msg) {
-               _E("Failed to call dbus method(%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
+               _E("Failed to call dbus method(%s)", METHOD_BLOCK_GETMMCPRIMARY);
                return ret;
        }
 
@@ -180,6 +182,8 @@ static bool block_getdevicelist2(char *type)
                ret = TRUE;
        }
 
+       g_variant_iter_free(iter);
+
        _I("Success. %s: %d", METHOD_BLOCK_GETDEVICELIST2, ret);
        return ret;
 }
index 8d8e992..193edb2 100644 (file)
@@ -3270,19 +3270,16 @@ static GVariant *request_get_device_list(GDBusConnection *conn,
        enum block_device_type block_type;
        int i;
        GVariantBuilder *builder = NULL;
+       const char *error = NULL;
 
        g_variant_get(param, "(s)", &type);
 
-       if (!type) {
-               _E("Delivered type is NULL.");
-               goto out;
-       }
-
        _D("Block (%s) device list is requested.", type);
 
        block_type = get_bdev_type_from_type_string(type);
        if (block_type == BLOCK_UNKNOWN_DEV) {
                _E("Invalid type (%s) is requested.", type);
+               error = "Invalid type is requested";
                goto out;
        }
 
@@ -3318,13 +3315,18 @@ static GVariant *request_get_device_list(GDBusConnection *conn,
                }
                pthread_mutex_unlock(&(th_manager[i].mutex));
        }
+
        reply = g_variant_new("(a(issssssisibii))", builder);
+
        g_variant_builder_unref(builder);
 
 out:
        g_free(type);
+
        if (!reply)
-               reply = dbus_handle_new_g_variant_tuple();
+               g_dbus_method_invocation_return_error(invocation,
+                               G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+                               "%s", error);
        return reply;
 }
 
@@ -3341,10 +3343,12 @@ static GVariant *request_get_device_list_2(GDBusConnection *conn,
        enum block_device_type block_type;
        int i;
        GVariantBuilder *builder = NULL;
+       const char *error = NULL;
 
        g_variant_get(param, "(s)", &type);
        if (!type) {
                _E("Delivered type is NULL.");
+               error = "Delivered type is NULL";
                goto out;
        }
 
@@ -3353,6 +3357,7 @@ static GVariant *request_get_device_list_2(GDBusConnection *conn,
        block_type = get_bdev_type_from_type_string(type);
        if (block_type == BLOCK_UNKNOWN_DEV) {
                _E("Invalid type (%s) is requested.", type);
+               error = "Invalid type is requested";
                goto out;
        }
 
@@ -3387,11 +3392,18 @@ static GVariant *request_get_device_list_2(GDBusConnection *conn,
                }
                pthread_mutex_unlock(&(th_manager[i].mutex));
        }
+
        reply = g_variant_new("(a(issssssisibi))", builder);
+
        g_variant_builder_unref(builder);
 
 out:
        g_free(type);
+
+       if (!reply)
+               g_dbus_method_invocation_return_error(invocation,
+                               G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+                               "%s", error);
        return reply;
 }