power: Add type casting to support architecture-independent API porting. 22/300922/1
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 3 Nov 2023 08:36:13 +0000 (17:36 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 6 Nov 2023 05:15:49 +0000 (14:15 +0900)
At first, in the 32bit architecture, power state enum value is treated as 4 byte.
Thus, when dealing with enum value, the type should be converted to unsigned int or int.
Especially, this is necessary for C# API porting in the 32bit architecture to avoid abnormal operation.
However, when the device_power_change_state uses dbus call, it treats enum value as uint64_t in the g_variant type.
To make correct type conversion in g_variant, uint64_t type conversion is needed also.

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

index 01a9b94..631e11a 100644 (file)
@@ -111,7 +111,7 @@ static void state_signal_callback(GDBusConnection *connection,
 
        g_variant_get(parameters, "(ttti)", &prev_state, &next_state, &id, &reason);
 
-       h->state_wait_callback(prev_state, next_state, id, reason, h->user_data);
+       h->state_wait_callback((unsigned int)prev_state, (unsigned int)next_state, id, reason, h->user_data);
 }
 
 static int __register_state_signal_callback(GDBusConnection *connection,
@@ -222,7 +222,7 @@ static void transient_state_signal_callback(GDBusConnection *connection,
 
        g_variant_get(parameters, "(ttti)", &prev_state, &next_state, &id, &reason);
 
-       h->transient_state_wait_callback(next_state, id, reason, h->user_data);
+       h->transient_state_wait_callback((unsigned int)next_state, id, reason, h->user_data);
 }
 
 static int __register_transient_state_signal_callback(GDBusConnection *connection,
@@ -518,13 +518,13 @@ static void change_state_async_callback(GObject *source_object, GAsyncResult *re
                        retval = -ETIMEDOUT;
 
                _E("Failed to finish async call, %s(%d)", err->message, err->code);
-               h->callback(h->state, retval, h->user_data);
+               h->callback((unsigned int)h->state, retval, h->user_data);
 
                goto cleanup;
        }
 
        g_variant_get(retgv, "(i)", &retval);
-       h->callback(h->state, retval, h->user_data);
+       h->callback((unsigned int)h->state, retval, h->user_data);
 
 cleanup:
        if (err)
@@ -581,7 +581,7 @@ int device_power_change_state(device_power_state_e state, int timeout_sec, devic
                DEVICED_PATH_POWER,
                DEVICED_INTERFACE_POWER,
                "PowerChangeState",
-               g_variant_new("(t)", state),
+               g_variant_new("(t)", (uint64_t)state),
                NULL,
                G_DBUS_CALL_FLAGS_NONE,
                timeout_sec * 1000,