display: Change device_display_change_state() from async to sync 32/304232/1 accepted/tizen_unified accepted/tizen_unified_toolchain accepted/tizen_unified_x accepted/tizen/unified/20240122.175407 accepted/tizen/unified/toolchain/20240311.065107 accepted/tizen/unified/x/20240205.063719
authorYunhee Seo <yuni.seo@samsung.com>
Thu, 21 Dec 2023 07:13:39 +0000 (16:13 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Fri, 12 Jan 2024 10:38:45 +0000 (19:38 +0900)
device_display_change_state() made the state change request asynchronous,
so it was not possible to know whether the request execution succeeded or not.
Due to the difficulty in checking whether requests were fulfilled properly,
the request method is changed as synchronous way.

Change-Id: Id4f957989248fb2c627459367fa575aa306a8d58
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/display.c

index d964953..4c2c0d3 100644 (file)
@@ -252,27 +252,14 @@ static char *get_state_str(display_state_e state)
        return NULL;
 }
 
-static void change_cb(GVariant *result, void *data, GError *err)
-{
-       int val;
-
-       if (!result) {
-//LCOV_EXCL_START System Error
-               _E("no message : %s", err->message);
-               return;
-//LCOV_EXCL_STOP
-       }
-
-       g_variant_get(result, "(i)", &val);
-       _D("%s-%s : %d", DEVICED_INTERFACE_DISPLAY, METHOD_CHANGE_STATE, val);
-}
-
 int device_display_change_state(display_state_e state)
 {
        char *str;
        int ret;
+       int val;
        static int privilege = -1;
        static long num_calls = 0;
+       GVariant *reply = NULL;
 
        ret = is_feature_display_state_supported();
        if (!ret)
@@ -306,13 +293,21 @@ int device_display_change_state(display_state_e state)
        if (!str)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       ret = gdbus_call_async_with_reply(DEVICED_BUS_NAME,
+       ret = gdbus_call_sync_with_reply(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_CHANGE_STATE, g_variant_new("(s)", str), change_cb, -1, NULL);
+                       METHOD_CHANGE_STATE, g_variant_new("(s)", str), &reply);
 
        if (ret < 0)
                ret = errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
 
+       if (reply) {
+               g_variant_get(reply, "(i)", &val);
+               _D("%s-%s : %d", DEVICED_INTERFACE_DISPLAY, METHOD_CHANGE_STATE, val);
+
+               if (val < 0)
+                       return errno_to_device_error(val);
+       }
+
        return ret;
 }