dbus: replace old dbus api with GVariant support api 26/221826/6
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Wed, 8 Jan 2020 01:12:50 +0000 (10:12 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 20 Jan 2020 04:31:27 +0000 (04:31 +0000)
Change-Id: Ie6b5e00497fe5c02bce2d40a68f6e97cbfab53c6
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
include/display-internal.h
src/battery.c
src/display.c
src/haptic.c
src/ir.c
src/led.c
src/power.c
src/temperature.c

index 84612f9..fb1920b 100644 (file)
@@ -118,7 +118,7 @@ typedef void (*dbus_pending_cb)(void *data, GVariant *result, GError *err);
  * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
  * @see device_display_change_state_by_reason()
  */
-int device_display_change_state_by_reason(display_state_e type, char *reason, int timeout, dbus_pending_cb cb);
+int device_display_change_state_by_reason(display_state_e type, const char *reason, int timeout, dbus_pending_cb cb);
 #ifdef __cplusplus
 }
 #endif
index a5c6954..d3b9a2d 100644 (file)
@@ -74,9 +74,9 @@ int device_battery_get_percent(int *percent)
        if (!ret)
                return DEVICE_ERROR_NOT_SUPPORTED;
 
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY,
-                       METHOD_GET_PERCENT, NULL, NULL);
+                       METHOD_GET_PERCENT, NULL);
        /* regard not suppoted as disconnected */
        if (ret == -ENOTSUP)
                ret = 0;
@@ -164,9 +164,9 @@ static int device_battery_get_info(struct battery_info *info)
        if (!info)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       ret = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_with_reply_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY,
-                       METHOD_GET_INFO, NULL, NULL, &output);
+                       METHOD_GET_INFO, NULL, &output);
        /* regard not suppoted as disconnected */
        if (ret == -ENOTSUP)
                ret = 0; //LCOV_EXCL_LINE System Error
index fc46032..3e23386 100644 (file)
@@ -73,9 +73,9 @@ int device_display_get_numbers(int *device_number)
 
        /* if it is a first request */
        if (display_cnt < 0) {
-               ret = dbus_method_sync(DEVICED_BUS_NAME,
+               ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                                DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                               METHOD_GET_DISPLAY_COUNT, NULL, NULL);
+                               METHOD_GET_DISPLAY_COUNT, NULL);
                if (ret < 0)
                        return errno_to_device_error(ret);
                display_cnt = ret;
@@ -89,8 +89,6 @@ int device_display_get_numbers(int *device_number)
 
 int device_display_get_max_brightness(int display_index, int *max_brightness)
 {
-       char *arr[1];
-       char str_val[32];
        int ret;
 
        ret = is_display_supported();
@@ -112,12 +110,10 @@ int device_display_get_max_brightness(int display_index, int *max_brightness)
        if (!display_arr && alloc_display() < 0)
                return DEVICE_ERROR_OPERATION_FAILED;
 
-       snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
-       arr[0] = str_val;
        if (display_arr[display_index].normal_max < 0) {
-               ret = dbus_method_sync(DEVICED_BUS_NAME,
+               ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                                DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                               METHOD_GET_MAX_BRIGHTNESS, "i", arr);
+                               METHOD_GET_MAX_BRIGHTNESS, g_variant_new("(i)", (int)DISPLAY_STATE_NORMAL));
                if (ret < 0)
                        return errno_to_device_error(ret);
                display_arr[display_index].normal_max = ret;
@@ -129,8 +125,6 @@ int device_display_get_max_brightness(int display_index, int *max_brightness)
 
 int device_display_get_brightness(int display_index, int *brightness)
 {
-       char *arr[1];
-       char str_val[32];
        int ret;
 
        ret = is_display_supported();
@@ -149,12 +143,9 @@ int device_display_get_brightness(int display_index, int *brightness)
        if (display_index < 0 || display_index >= display_cnt)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
-       arr[0] = str_val;
-
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_GET_BRIGHTNESS, "i", arr);
+                       METHOD_GET_BRIGHTNESS, g_variant_new("(i)", (int)DISPLAY_STATE_NORMAL));
        if (ret < 0)
                return errno_to_device_error(ret);
 
@@ -164,9 +155,6 @@ int device_display_get_brightness(int display_index, int *brightness)
 
 int device_display_set_brightness(int display_index, int brightness)
 {
-       char *arr[2];
-       char str_state[32];
-       char str_val[32];
        int ret, max;
 
        ret = is_display_supported();
@@ -188,15 +176,9 @@ int device_display_set_brightness(int display_index, int brightness)
        if (brightness < 0 || brightness > display_arr[display_index].normal_max)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       snprintf(str_state, sizeof(str_state), "%d", DISPLAY_STATE_NORMAL);
-       arr[0] = str_state;
-
-       snprintf(str_val, sizeof(str_val), "%d", brightness);
-       arr[1] = str_val;
-
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_SET_BRIGHTNESS, "ii", arr);
+                       METHOD_SET_BRIGHTNESS, g_variant_new("(ii)", (int)DISPLAY_STATE_NORMAL, brightness));
        if (ret < 0)
                return errno_to_device_error(ret);
 
@@ -262,7 +244,7 @@ static void change_cb(void *data, GVariant *result, GError *err)
 
 int device_display_change_state(display_state_e state)
 {
-       char *str, *arr[1];
+       char *str;
        int ret;
        static int privilege = -1;
 
@@ -280,11 +262,9 @@ int device_display_change_state(display_state_e state)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
        if (privilege < 0) {
-               arr[0] = "privilege check";
-
-               ret = dbus_method_sync(DEVICED_BUS_NAME,
+               ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                                DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                               METHOD_CHANGE_STATE, "s", arr);
+                               METHOD_CHANGE_STATE, g_variant_new("(s)", "privilege check"));
 //LCOV_EXCL_START System Error
                if (ret < 0)
                        return ret;
@@ -297,18 +277,14 @@ int device_display_change_state(display_state_e state)
        if (!str)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       arr[0] = str;
-
-       return dbus_method_async_with_reply(DEVICED_BUS_NAME,
+       return dbus_method_async_with_reply_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_CHANGE_STATE, "s", arr, change_cb, -1, NULL);
+                       METHOD_CHANGE_STATE, g_variant_new("(s)", str), change_cb, -1, NULL);
 }
 
 //LCOV_EXCL_START Not used function
 int device_display_get_max_brightness_state(int display_index, display_state_e state, int *brightness)
 {
-       char *arr[1];
-       char str_val[32];
        int ret;
 
        ret = is_display_supported();
@@ -333,15 +309,9 @@ int device_display_get_max_brightness_state(int display_index, display_state_e s
        if (!display_arr && alloc_display() < 0)
                return DEVICE_ERROR_OPERATION_FAILED;
 
-       if (state == DISPLAY_STATE_NORMAL)
-               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
-       else if (state == DISPLAY_STATE_SCREEN_DIM)
-               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_SCREEN_DIM);
-       arr[0] = str_val;
-
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                                DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                               METHOD_GET_MAX_BRIGHTNESS, "i", arr);
+                               METHOD_GET_MAX_BRIGHTNESS, g_variant_new("(i)", (int)state));
        if (ret < 0)
                return errno_to_device_error(ret);
 
@@ -360,8 +330,6 @@ int device_display_get_max_brightness_state(int display_index, display_state_e s
 //LCOV_EXCL_START Not used function
 int device_display_get_brightness_state(int display_index, display_state_e state, int *brightness)
 {
-       char *arr[1];
-       char str_val[32];
        int ret;
 
        ret = is_display_supported();
@@ -383,15 +351,9 @@ int device_display_get_brightness_state(int display_index, display_state_e state
        if (display_index < 0 || display_index >= display_cnt)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       if (state == DISPLAY_STATE_NORMAL)
-               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
-       else if (state == DISPLAY_STATE_SCREEN_DIM)
-               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_SCREEN_DIM);
-       arr[0] = str_val;
-
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_GET_BRIGHTNESS, "i", arr);
+                       METHOD_GET_BRIGHTNESS, g_variant_new("(i)", (int)state));
        if (ret < 0)
                return errno_to_device_error(ret);
 
@@ -404,9 +366,6 @@ int device_display_get_brightness_state(int display_index, display_state_e state
 //LCOV_EXCL_START Not used function
 int device_display_set_brightness_state(int display_index, display_state_e state, int brightness)
 {
-       char *arr[2];
-       char str_state[32];
-       char str_val[32];
        int ret, max;
 
        ret = is_display_supported();
@@ -431,54 +390,33 @@ int device_display_set_brightness_state(int display_index, display_state_e state
                        device_display_get_max_brightness_state(display_index, DISPLAY_STATE_NORMAL, &max);
                if (brightness < 0 || brightness > display_arr[display_index].normal_max)
                        return DEVICE_ERROR_INVALID_PARAMETER;
-
-               snprintf(str_val, sizeof(str_val), "%d", DISPLAY_STATE_NORMAL);
-               arr[0] = str_val;
-               snprintf(str_val, sizeof(str_val), "%d", brightness);
-               arr[1] = str_val;
                break;
        case DISPLAY_STATE_SCREEN_DIM:
                if (display_arr[display_index].dim_max < 0)
                        device_display_get_max_brightness_state(display_index, DISPLAY_STATE_SCREEN_DIM, &max);
                if (brightness < 0 || brightness > display_arr[display_index].dim_max)
                        return DEVICE_ERROR_INVALID_PARAMETER;
-
-               snprintf(str_state, sizeof(str_state), "%d", DISPLAY_STATE_SCREEN_DIM);
-               arr[0] = str_state;
-               snprintf(str_val, sizeof(str_val), "%d", brightness);
-               arr[1] = str_val;
                break;
-
        default:
                break;
        }
 
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_SET_BRIGHTNESS, "ii", arr);
+                       METHOD_SET_BRIGHTNESS, g_variant_new("(ii)", (int)state, brightness));
        if (ret < 0)
                return errno_to_device_error(ret);
 
        return DEVICE_ERROR_NONE;
 }
 
-int device_display_change_state_by_reason(display_state_e type, char *reason, int timeout, dbus_pending_cb cb)
+int device_display_change_state_by_reason(display_state_e type, const char *reason, int timeout, dbus_pending_cb cb)
 {
-       char *arr[3];
-       char _type[32];
-       char _timeout[32];
        int ret;
 
-       snprintf(_type, sizeof(_type), "%d", type);
-       snprintf(_timeout, sizeof(_timeout), "%d", timeout);
-
-       arr[0] = _type;
-       arr[1] = reason;
-       arr[2] = _timeout;
-
-       ret = dbus_method_async_with_reply(DEVICED_BUS_NAME,
+       ret = dbus_method_async_with_reply_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_CHANGE_STATE_BY_REASON, "isi", arr, cb, -1, NULL);
+                       METHOD_CHANGE_STATE_BY_REASON, g_variant_new("(isi)", (int)type, reason, timeout), cb, -1, NULL);
 
        return errno_to_device_error(ret);
 }
index a0ce513..62d7a45 100644 (file)
@@ -81,9 +81,9 @@ int device_haptic_get_count(int *device_number)
                return DEVICE_ERROR_NOT_SUPPORTED;
 
        /* request to deviced to get haptic count */
-       ret = dbus_method_sync(VIBRATOR_BUS_NAME,
+       ret = dbus_method_sync_var(VIBRATOR_BUS_NAME,
                        VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC,
-                       METHOD_GET_COUNT, NULL, NULL);
+                       METHOD_GET_COUNT, NULL);
        /**
         * there is no haptic method in no vibration model.
         * so -ENOTSUP means that haptic count is zero.
@@ -101,17 +101,13 @@ int device_haptic_get_count(int *device_number)
 void restart_callback(void)
 {
        dd_list *elem, *elem_next;
-       char str_index[32];
-       char *arr[1];
        struct haptic_handle *temp;
        int ret;
 
        DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) {
-               snprintf(str_index, sizeof(str_index), "%d", temp->index);
-               arr[0] = str_index;
-               ret = dbus_method_sync(VIBRATOR_BUS_NAME,
+               ret = dbus_method_sync_var(VIBRATOR_BUS_NAME,
                                VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC,
-                               METHOD_OPEN_DEVICE, "i", arr);
+                               METHOD_OPEN_DEVICE, g_variant_new("(i)", temp->index));
                if (ret < 0) {
                        _E("Failed to open device");
                        continue;
@@ -127,8 +123,6 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle)
        dd_list *elem, *elem_next;
        struct haptic_handle *handle;
        struct haptic_handle *temp;
-       char str_index[32];
-       char *arr[1];
        int ret, max;
        bool found = false;
 
@@ -146,13 +140,10 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle)
        if (!ret)
                return DEVICE_ERROR_NOT_SUPPORTED;
 
-       snprintf(str_index, sizeof(str_index), "%d", device_index);
-       arr[0] = str_index;
-
        /* request to deviced to open haptic device */
-       ret = dbus_method_sync(VIBRATOR_BUS_NAME,
+       ret = dbus_method_sync_var(VIBRATOR_BUS_NAME,
                        VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC,
-                       METHOD_OPEN_DEVICE, "i", arr);
+                       METHOD_OPEN_DEVICE, g_variant_new("(i)", device_index));
        if (ret < 0)
                return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
 
@@ -190,8 +181,6 @@ int device_haptic_close(haptic_device_h device_handle)
        dd_list *elem, *elem_next;
        struct haptic_handle *handle = (struct haptic_handle *)device_handle;
        struct haptic_handle *temp;
-       char str_handle[32];
-       char *arr[1];
        int ret;
        bool found = false;
 
@@ -212,14 +201,14 @@ int device_haptic_close(haptic_device_h device_handle)
        if (!found)
                return DEVICE_ERROR_OPERATION_FAILED;
        DD_LIST_REMOVE(handle_list, handle);
-       snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)handle->handle);
-       free(handle);
-       arr[0] = str_handle;
 
        /* request to deviced to open haptic device */
-       ret = dbus_method_sync(VIBRATOR_BUS_NAME,
+       ret = dbus_method_sync_var(VIBRATOR_BUS_NAME,
                        VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC,
-                       METHOD_CLOSE_DEVICE, "u", arr);
+                       METHOD_CLOSE_DEVICE, g_variant_new("(u)", (unsigned int)handle->handle));
+
+       free(handle);
+
        if (ret < 0)
                return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
 
@@ -237,11 +226,6 @@ int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedb
        dd_list *elem, *elem_next;
        struct haptic_handle *handle = (struct haptic_handle *)device_handle;
        struct haptic_handle *temp;
-       char str_handle[32];
-       char str_duration[32];
-       char str_feedback[32];
-       char str_priority[32];
-       char *arr[4];
        int ret, priority;
        bool found = false;
 
@@ -269,19 +253,11 @@ int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedb
        if (!found)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)handle->handle);
-       arr[0] = str_handle;
-       snprintf(str_duration, sizeof(str_duration), "%d", duration);
-       arr[1] = str_duration;
-       snprintf(str_feedback, sizeof(str_feedback), "%d", feedback);
-       arr[2] = str_feedback;
-       snprintf(str_priority, sizeof(str_priority), "%d", priority);
-       arr[3] = str_priority;
-
        /* request to deviced to vibrate haptic device */
-       ret = dbus_method_sync(VIBRATOR_BUS_NAME,
+       ret = dbus_method_sync_var(VIBRATOR_BUS_NAME,
                        VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC,
-                       METHOD_VIBRATE_MONOTONE, "uiii", arr);
+                       METHOD_VIBRATE_MONOTONE,
+                       g_variant_new("(uiii)", (unsigned int)handle->handle, duration, feedback, priority));
        if (ret < 0)
                return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
 
@@ -296,8 +272,6 @@ int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_han
        dd_list *elem, *elem_next;
        struct haptic_handle *handle = (struct haptic_handle *)device_handle;
        struct haptic_handle *temp;
-       char str_handle[32];
-       char *arr[1];
        int ret;
        bool found = false;
 
@@ -318,13 +292,11 @@ int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_han
                return DEVICE_ERROR_INVALID_PARAMETER;
 
        /* TODO : support to stop haptic effect */
-       snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)handle->handle);
-       arr[0] = str_handle;
 
        /* request to deviced to open haptic device */
-       ret = dbus_method_sync(VIBRATOR_BUS_NAME,
+       ret = dbus_method_sync_var(VIBRATOR_BUS_NAME,
                        VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC,
-                       METHOD_STOP_DEVICE, "u", arr);
+                       METHOD_STOP_DEVICE, g_variant_new("(u)", (unsigned int)handle->handle));
        if (ret < 0)
                return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
 
index 3377e78..71b9db7 100644 (file)
--- a/src/ir.c
+++ b/src/ir.c
@@ -46,9 +46,9 @@ int device_ir_is_available(bool *available)
                return DEVICE_ERROR_NOT_SUPPORTED;
        }
 
-       ret = dbus_method_sync(DEVICED_BUS_NAME, DEVICED_PATH_IR,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_IR,
                        DEVICED_INTERFACE_IR, METHOD_IS_AVAILABLE,
-                       NULL, NULL);
+                       NULL);
 
 //LCOV_EXCL_START System Error
        if (ret == -EACCES || ret == -EPERM)
@@ -65,12 +65,10 @@ int device_ir_is_available(bool *available)
 
 int device_ir_transmit(int carrier_frequency, int *pattern, int size)
 {
-       char *arr[1];
-       struct dbus_int pattern_list;
-       int freq_pattern[size + 1];
        int ret;
        int i;
        bool ir_avail;
+       GVariantBuilder *builder;
 
        ret = device_ir_is_available(&ir_avail);
        if (!ir_avail) {
@@ -89,18 +87,17 @@ int device_ir_transmit(int carrier_frequency, int *pattern, int size)
                return DEVICE_ERROR_INVALID_PARAMETER;
        }
 //LCOV_EXCL_STOP
-       freq_pattern[0] = carrier_frequency;
-       for (i = 1; i <= size; i++)
-               freq_pattern[i] = pattern[i-1];
+       builder = g_variant_builder_new(G_VARIANT_TYPE ("ai"));
 
-       pattern_list.list = freq_pattern;
-       pattern_list.size = size + 1;
-       arr[0] = (char *)&pattern_list;
+       g_variant_builder_add(builder, "i", carrier_frequency);
+       for (i = 0; i < size; ++i)
+               g_variant_builder_add(builder, "i", pattern[i]);
 
-       ret = dbus_method_sync(DEVICED_BUS_NAME, DEVICED_PATH_IR,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_IR,
                        DEVICED_INTERFACE_IR, METHOD_TRANSMIT,
-                       "ai", arr);
+                       g_variant_new("(ai)", builder));
 
+       g_variant_builder_unref(builder);
 //LCOV_EXCL_START System Error
        if (ret == -EACCES || ret == -EPERM)
                return DEVICE_ERROR_PERMISSION_DENIED;
index f3b4f5b..3f65144 100644 (file)
--- a/src/led.c
+++ b/src/led.c
@@ -64,9 +64,9 @@ int device_flash_get_max_brightness(int *max_brightness)
        if (!max_brightness)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
-                       METHOD_GET_MAX_BRIGHTNESS, NULL, NULL);
+                       METHOD_GET_MAX_BRIGHTNESS, NULL);
        if (ret < 0)
                return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
 
@@ -84,9 +84,9 @@ int device_flash_get_brightness(int *brightness)
        if (!brightness)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
-                       METHOD_GET_BRIGHTNESS, NULL, NULL);
+                       METHOD_GET_BRIGHTNESS, NULL);
        if (ret < 0)
                return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
 
@@ -96,9 +96,6 @@ int device_flash_get_brightness(int *brightness)
 
 int device_flash_set_brightness(int brightness)
 {
-       char *arr[2];
-       char buf_val[32];
-       char buf_noti[32];
        int max, ret;
 
        if (!support_camera_led)
@@ -111,15 +108,10 @@ int device_flash_set_brightness(int brightness)
        if (brightness < 0 || brightness > max)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       snprintf(buf_val, sizeof(buf_val), "%d", brightness);
-       arr[0] = buf_val;
-       snprintf(buf_noti, sizeof(buf_noti), "%d", 0);
-       arr[1] = buf_noti;
-
        /* if camera API preempt a flash device, it will return -EBUSY error. */
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
-                       METHOD_SET_BRIGHTNESS, "ii", arr);
+                       METHOD_SET_BRIGHTNESS, g_variant_new("(ii)", brightness, 0));
        if (ret < 0)
                return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
 
@@ -128,9 +120,6 @@ int device_flash_set_brightness(int brightness)
 
 int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags)
 {
-       char *arr[4];
-       char str_on[32], str_off[32];
-       char str_color[32], str_flags[32];
        int ret;
 
        if (!support_front_led)
@@ -139,18 +128,9 @@ int device_led_play_custom(int on, int off, unsigned int color, unsigned int fla
        if (on < 0 || off < 0)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       snprintf(str_on, sizeof(str_on), "%d", on);
-       arr[0] = str_on;
-       snprintf(str_off, sizeof(str_off), "%d", off);
-       arr[1] = str_off;
-       snprintf(str_color, sizeof(str_color), "%lu", (long unsigned int)color);
-       arr[2] = str_color;
-       snprintf(str_flags, sizeof(str_flags), "%lu", (long unsigned int)flags);
-       arr[3] = str_flags;
-
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
-                       METHOD_PLAY_CUSTOM, "iiuu", arr);
+                       METHOD_PLAY_CUSTOM, g_variant_new("(iiuu)", on, off, (unsigned int)color, (unsigned int)flags));
 //LCOV_EXCL_START System Error
        if (ret < 0)
                return errno_to_device_error(ret);
@@ -165,9 +145,9 @@ int device_led_stop_custom(void)
        if (!support_front_led)
                return DEVICE_ERROR_NOT_SUPPORTED;
 
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
-                       METHOD_STOP_CUSTOM, NULL, NULL);
+                       METHOD_STOP_CUSTOM, NULL);
 //LCOV_EXCL_START System Error
        if (ret < 0)
                return errno_to_device_error(ret);
@@ -188,9 +168,9 @@ int device_multi_led_get_number(int *num_of_leds)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
        if (number_of_devices < 0) {
-               ret = dbus_method_sync(DEVICED_BUS_NAME,
+               ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                                DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
-                               METHOD_GET_LED_NUMBER, NULL, NULL);
+                               METHOD_GET_LED_NUMBER, NULL);
                if (ret < 0)
                        return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
                number_of_devices = ret;
index 532040a..e841271 100644 (file)
@@ -177,7 +177,6 @@ static int notice_power_lock_expired(void)
        int ret;
        pid_t pid;
        char *req_id;
-       char *param[1];
 
        pid = getpid();
 
@@ -187,13 +186,12 @@ static int notice_power_lock_expired(void)
                return -ENOMEM;
        }
 
-       param[0] = req_id;
-       ret = dbus_method_async_with_reply(
+       ret = dbus_method_async_with_reply_var(
                        DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY,
                        DEVICED_INTERFACE_DISPLAY,
                        "LockTimeoutExpired",
-                       "s", param,
+                       g_variant_new("(s)", req_id),
                        notice_lock_expired_done,
                        -1,
                        NULL);
@@ -343,7 +341,6 @@ static void lock_cb(void *data, GVariant *result, GError *err)
 static int lock_state(display_state_e state, unsigned int flag, int timeout_ms)
 {
        char *arr[4];
-       char str_timeout[32];
        int ret;
        static int privilege = -1;
 
@@ -359,15 +356,12 @@ static int lock_state(display_state_e state, unsigned int flag, int timeout_ms)
        else
                arr[2] = STR_NULL;
 
-       snprintf(str_timeout, sizeof(str_timeout), "%d", timeout_ms);
-       arr[3] = str_timeout;
-
        if (privilege < 0) {
                arr[0] = "privilege check";
 
-               ret = dbus_method_sync(DEVICED_BUS_NAME,
+               ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                                DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                               METHOD_LOCK_STATE, "sssi", arr);
+                               METHOD_LOCK_STATE, g_variant_new("(sssi)", arr[0], arr[1], arr[2], timeout_ms));
 //LCOV_EXCL_START System Error
                if (ret < 0)
                        return ret;
@@ -380,9 +374,9 @@ static int lock_state(display_state_e state, unsigned int flag, int timeout_ms)
        if (!arr[0])
                return -EINVAL;
 
-       return dbus_method_async_with_reply(DEVICED_BUS_NAME,
+       return dbus_method_async_with_reply_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_LOCK_STATE, "sssi", arr, lock_cb, -1, NULL);
+                       METHOD_LOCK_STATE, g_variant_new("(sssi)", arr[0], arr[1], arr[2], timeout_ms), lock_cb, -1, NULL);
 }
 
 static void unlock_cb(void *data, GVariant *result, GError *err)
@@ -418,9 +412,9 @@ static int unlock_state(display_state_e state, unsigned int flag)
        if (privilege < 0) {
                arr[0] = "privilege check";
 
-               ret = dbus_method_sync(DEVICED_BUS_NAME,
+               ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                                DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                               METHOD_UNLOCK_STATE, "ss", arr);
+                               METHOD_UNLOCK_STATE, g_variant_new("(ss)", arr[0], arr[1]));
 //LCOV_EXCL_START System Error
                if (ret < 0)
                        return ret;
@@ -433,9 +427,9 @@ static int unlock_state(display_state_e state, unsigned int flag)
        if (!arr[0])
                return -EINVAL;
 
-       return dbus_method_async_with_reply(DEVICED_BUS_NAME,
+       return dbus_method_async_with_reply_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
-                       METHOD_UNLOCK_STATE, "ss", arr, unlock_cb, -1, NULL);
+                       METHOD_UNLOCK_STATE, g_variant_new("(ss)", arr[0], arr[1]), unlock_cb, -1, NULL);
 }
 
 int device_power_request_lock(power_lock_e type, int timeout_ms)
@@ -513,25 +507,22 @@ int device_power_wakeup(bool dim)
 //LCOV_EXCL_START Not available to test (Reboot during TCT)
 int device_power_reboot(const char *reason)
 {
-       char *arr[2];
-       char *method, *sig;
+       const char *method;
+       GVariant *param;
        int ret;
 
        if (reason) {
-               arr[0] = TYPE_REBOOT;
-               arr[1] = (char *)reason;
                method = METHOD_POWEROFF_WITH_OPTION;
-               sig = "ss";
+               param = g_variant_new("(ss)", TYPE_REBOOT, reason);
        } else {
-               arr[0] = TYPE_REBOOT;
                method = METHOD_POWEROFF;
-               sig = "s";
+               param = g_variant_new("(s)", TYPE_REBOOT);
        }
 
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_POWEROFF,
                        DEVICED_INTERFACE_POWEROFF,
-                       method, sig, arr);
+                       method, param);
        return errno_to_device_error(ret);
 }
 //LCOV_EXCL_STOP
index 12f5c5b..9064517 100644 (file)
@@ -54,8 +54,6 @@ static int is_temperature_supported(device_thermal_e type)
 
 int device_thermal_get_temperature(device_thermal_e type, int *temp)
 {
-       char *arr[1];
-       char str_val[32];
        int ret;
 
        if (type > DEVICE_THERMAL_BATTERY)
@@ -65,13 +63,10 @@ int device_thermal_get_temperature(device_thermal_e type, int *temp)
        if (!ret)
                return DEVICE_ERROR_NOT_SUPPORTED;
 
-       snprintf(str_val, sizeof(str_val), "%d", type);
-       arr[0] = str_val;
-
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
                        DEVICED_PATH_TEMPERATURE,
                        DEVICED_INTERFACE_TEMPERATURE,
-                       METHOD_GET_TEMPERATURE, "i", arr);
+                       METHOD_GET_TEMPERATURE, g_variant_new("(i)", type));
        if (ret < 0)
                return errno_to_device_error(ret);