Apply libsyscommon gdbus api improvement on error handling 42/254742/1 accepted/tizen/unified/20210310.145028 submit/tizen/20210309.090957
authortaemin.yeom <taemin.yeom@samsung.com>
Tue, 9 Mar 2021 05:48:10 +0000 (14:48 +0900)
committertaemin.yeom <taemin.yeom@samsung.com>
Tue, 9 Mar 2021 05:51:29 +0000 (14:51 +0900)
Change-Id: I6e5fa21dde4f91ce0caff5a4a7c59c6eb6bfdc14
Signed-off-by: taemin.yeom <taemin.yeom@samsung.com>
apps/extended-sd/src/es-internal-storage-page.c
apps/extended-sd/src/es-portable-storage-page.c
apps/extended-sd/src/extended-sd-main.c
src/auto-test/block.c
src/auto-test/storage.c
src/block/block.c
src/storage/storage.c

index 6b34394..2620b17 100644 (file)
@@ -109,7 +109,7 @@ encryption_format(void *data)
 
        // Unmount sdcard
        ret = dbus_handle_method_sync_var(STORAGED_BUS_NAME,
-                       STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "Unmount", g_variant_new("(ii)", ad->storage_id, UNMOUNT_FORCE));
+                       STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "Unmount", g_variant_new("(ii)", ad->storage_id, UNMOUNT_FORCE), NULL);
        if (ret < 0) {
                DMSG("Failed to mount sd card as portable storage: %d", ret);
                return;
index 0413702..f73f624 100644 (file)
@@ -69,7 +69,7 @@ format_done(GVariant *result, void *data, GError *err)
        }
 
        ret = dbus_handle_method_sync_var(STORAGED_BUS_NAME,
-                       STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "Mount", g_variant_new("(is)", ad->storage_id, ""));
+                       STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "Mount", g_variant_new("(is)", ad->storage_id, ""), NULL);
        if (ret < 0) {
                DMSG("Failed to mount sd card as portable storage: %d", ret);
                goto out;
@@ -116,9 +116,9 @@ mapper_device_cb(int mapper_id, storage_dev_e dev, storage_state_e state,
                return;
 
        if (primary) {
-               output = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
-                               STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "GetDeviceList", g_variant_new("(s)", "mmc"));
-               if (!output) {
+               ret = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
+                               STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "GetDeviceList", g_variant_new("(s)", "mmc"), &output);
+               if (ret < 0) {
                        DMSG("Failed to get storage information.");
                        return;
                }
index 0ba2d0d..1a7629f 100644 (file)
@@ -145,12 +145,13 @@ app_control(app_control_h app_control, void *data)
        } else
                create_home_page_base_layout(ad);
 
-       output = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
+       ret = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
                        STORAGED_PATH_BLOCK_MANAGER,
                        STORAGED_INTERFACE_BLOCK_MANAGER,
                        "GetMmcPrimary",
-                       NULL);
-       if (!output) {
+                       NULL,
+                       &output);
+       if (ret < 0) {
                DMSG("Failed to get storage information.");
                return;
        }
index 2d05608..85cacb5 100644 (file)
 
 static bool request_block_method(const char *method, GVariant *param, int timeout)
 {
-       GVariant *msg;
-       int val;
+       int val, err;
        bool ret = FALSE;
+       GVariant *msg;
 
-       msg = dbus_handle_method_sync_with_reply_var_timeout(STORAGED_BUS_NAME,
+       err = dbus_handle_method_sync_with_reply_var_timeout(STORAGED_BUS_NAME,
                STORAGED_PATH_BLOCK_MANAGER,
                STORAGED_INTERFACE_BLOCK_MANAGER,
-               method, param, timeout);
+               method, param, &msg, timeout);
 
-       if (!msg) {
+       if (err < 0) {
                _E("Failed to call dbus method(%s): no reply", method);
                return ret;
        }
@@ -73,16 +73,17 @@ static bool request_block_method(const char *method, GVariant *param, int timeou
 static int get_id()
 {
        GVariant *msg;
-       int val;
+       int val, err;
        int ret = -1;
 
-       msg = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
+       err = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
                STORAGED_PATH_BLOCK_MANAGER,
                STORAGED_INTERFACE_BLOCK_MANAGER,
                METHOD_BLOCK_GETMMCPRIMARY,
-               NULL);
+               NULL,
+               &msg);
 
-       if (!msg) {
+       if (err < 0) {
                _E("Failed to call dbus method(%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
                return ret;
        }
@@ -101,24 +102,23 @@ static int get_id()
 
 static bool block_showdevicelist()
 {
-       GVariant *msg;
-       int ret = FALSE;
+       int err;
 
        _D("----------------------------------------------------------------------------------");
 
-       msg = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
+       err = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
                STORAGED_PATH_BLOCK_MANAGER,
                STORAGED_INTERFACE_BLOCK_MANAGER,
                METHOD_BLOCK_SHOWDEVICELIST,
+               NULL,
                NULL);
 
-       if (!msg) {
+       if (err < 0) {
                _E("Failed to call dbus method(%s): no reply", METHOD_BLOCK_SHOWDEVICELIST);
-               return ret;
+               return FALSE;
        }
 
        _I("Success. %s", METHOD_BLOCK_SHOWDEVICELIST);
-       g_variant_unref(msg);
        return TRUE;
 }
 
@@ -126,17 +126,18 @@ static bool block_getdevicelist(char *type)
 {
        GVariant *msg;
        GVariantIter *iter;
-       int val;
+       int val, err;
        int ret = FALSE;
 
        _D("----------------------------------------------------------------------------------");
-       msg = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
+       err = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
                STORAGED_PATH_BLOCK_MANAGER,
                STORAGED_INTERFACE_BLOCK_MANAGER,
                METHOD_BLOCK_GETDEVICELIST,
-               g_variant_new("(s)", type));
+               g_variant_new("(s)", type),
+               &msg);
 
-       if (!msg) {
+       if (err < 0) {
                _E("Failed to call dbus method(%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
                return ret;
        }
@@ -168,15 +169,17 @@ static bool block_getdevicelist2(char *type)
        GVariantIter *iter;
        char *val;
        int ret = FALSE;
+       int err;
 
        _D("----------------------------------------------------------------------------------");
-       msg = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
+       err = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
                STORAGED_PATH_BLOCK_MANAGER,
                STORAGED_INTERFACE_BLOCK_MANAGER,
                METHOD_BLOCK_GETDEVICELIST2,
-               g_variant_new("(s)", type));
+               g_variant_new("(s)", type),
+               &msg);
 
-       if (!msg) {
+       if (err < 0) {
                _E("Failed to call dbus method(%s)", METHOD_BLOCK_GETMMCPRIMARY);
                return ret;
        }
@@ -231,15 +234,17 @@ static bool block_getdeviceinfo(int id)
        GVariant *msg;
        int val = -1;
        int ret = FALSE;
+       int err;
 
        _D("----------------------------------------------------------------------------------");
-       msg = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
+       err = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
                STORAGED_PATH_BLOCK_MANAGER,
                STORAGED_INTERFACE_BLOCK_MANAGER,
                METHOD_BLOCK_GETDEVICEINFO,
-               g_variant_new("(i)", id));
+               g_variant_new("(i)", id),
+               &msg);
 
-       if (!msg) {
+       if (err < 0) {
                _E("Failed to call dbus method(%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
                return ret;
        }
@@ -267,15 +272,17 @@ static bool block_getmmcprimary()
        GVariant *msg;
        int val = -1;
        int ret = FALSE;
+       int err;
 
        _D("----------------------------------------------------------------------------------");
-       msg = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
+       err = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
                STORAGED_PATH_BLOCK_MANAGER,
                STORAGED_INTERFACE_BLOCK_MANAGER,
                METHOD_BLOCK_GETMMCPRIMARY,
-               NULL);
+               NULL,
+               &msg);
 
-       if (!msg) {
+       if (err < 0) {
                _E("Failed to call dbus method(%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
                return ret;
        }
index 8873c24..9038dda 100644 (file)
@@ -25,13 +25,14 @@ static bool request_storage_method(const char *method, GVariant *param)
        GVariant *msg;
        unsigned long long val1, val2;
        bool ret = FALSE;
+       int err;
 
-       msg = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
+       err = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
                STORAGED_PATH_STORAGE,
                STORAGED_INTERFACE_STORAGE,
-               method, param);
+               method, param, &msg);
 
-       if (!msg) {
+       if (err < 0) {
                _E("Failed to call dbus method(%s): no reply", method);
                return ret;
        }
index 340ccf1..f703494 100644 (file)
@@ -954,8 +954,8 @@ static void create_external_apps_directory(void)
 {
        int ret;
 
-       ret = dbus_handle_method_async(PKGDIR_BUS_NAME, PKGDIR_PATH,
-                       PKGDIR_INTERFACE, "CreateExternalDirsForAllPkgs", NULL, NULL);
+       ret = dbus_handle_method_async_var(PKGDIR_BUS_NAME, PKGDIR_PATH,
+                       PKGDIR_INTERFACE, "CreateExternalDirsForAllPkgs", NULL);
        if (ret)
                _E("Failed to create external directory.");
 }
@@ -1028,7 +1028,8 @@ static bool pipe_cb(int fd, void *data)
                        POPUP_PATH_NOTI,
                        POPUP_INTERFACE_NOTI,
                        MMC_POPUP_NOTI,
-                       g_variant_new("(s)", MMC_INSERTED));
+                       g_variant_new("(s)", MMC_INSERTED),
+                       NULL);
                if (ret != 0)
                        _E("Failed to popup: %d", ret);
        }
@@ -1045,7 +1046,8 @@ static bool pipe_cb(int fd, void *data)
                                POPUP_PATH_NOTI,
                                POPUP_INTERFACE_NOTI,
                                MMC_POPUP_NOTI,
-                               g_variant_new("(s)", MMC_REMOVED));
+                               g_variant_new("(s)", MMC_REMOVED),
+                               NULL);
                        if (ret != 0)
                                _E("Failed to popup: %d", ret);
                }
@@ -2713,11 +2715,11 @@ static void booting_done(void)
        /* if there is the attached device, try to mount */
        block_init_from_udev_enumerate();
 
-       ret = dbus_handle_method_async_with_reply(DEVICED_BUS_NAME,
+       ret = dbus_handle_method_async_with_reply_var(DEVICED_BUS_NAME,
                DEVICED_PATH_POWEROFF,
                DEVICED_INTERFACE_POWEROFF,
                METHOD_ADD_POWEROFF_WAIT,
-               NULL, NULL,
+               NULL,
                add_poweroff_wait_cb,
                -1, NULL);
        if (ret < 0)
@@ -2747,7 +2749,7 @@ static void block_poweroff(GDBusConnection  *conn,
        terminate_threads();
 
        if (add_poweroff_wait) {
-               ret = dbus_handle_method_sync(DEVICED_BUS_NAME,
+               ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_POWEROFF,
                        DEVICED_INTERFACE_POWEROFF,
                        METHOD_REMOVE_POWEROFF_WAIT,
@@ -3790,7 +3792,7 @@ static void block_exit(void *data)
        pipe_exit();
 
        if (add_poweroff_wait) {
-               ret = dbus_handle_method_sync(DEVICED_BUS_NAME,
+               ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_POWEROFF,
                        DEVICED_INTERFACE_POWEROFF,
                        METHOD_REMOVE_POWEROFF_WAIT,
index 8a20081..02774b0 100644 (file)
@@ -255,19 +255,14 @@ out:
 
 static int remove_notification(void)
 {
-       const char *param[1];
-       char id_str[16];
        int ret;
 
-       snprintf(id_str, sizeof(id_str), "%d", noti_id);
-       param[0] = id_str;
-
-       ret = dbus_handle_method_sync(POPUP_BUS_NAME,
+       ret = dbus_handle_method_sync_var(POPUP_BUS_NAME,
                POPUP_PATH_NOTI,
                POPUP_INTERFACE_NOTI,
                INTERNAL_STORAGE_NOTIOFF,
-               "i",
-               param);
+               g_variant_new("(i)", noti_id),
+               NULL);
        if (ret < 0)
                _E("Failed to remove noti(%d).", noti_id);
 
@@ -278,12 +273,11 @@ static int create_notification(void)
 {
        int ret;
 
-       ret = dbus_handle_method_async_with_reply(POPUP_BUS_NAME,
+       ret = dbus_handle_method_async_with_reply_var(POPUP_BUS_NAME,
                POPUP_PATH_NOTI,
                POPUP_INTERFACE_NOTI,
                INTERNAL_STORAGE_NOTION,
                NULL,
-               NULL,
                _noti_cb,
                -1,
                NULL);