power: emit signal before sleep on iot-headless 99/266699/5
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 17 Nov 2021 09:08:32 +0000 (18:08 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 18 Nov 2021 03:32:12 +0000 (12:32 +0900)
path      : /Org/Tizen/System/DeviceD/Power
interface : org.tizen.system.deviced.Power
name      : "sleep"
parameter : "(tt)"
            uint64, current time in milisecond
    uint64, sleep id

Change-Id: I1664898bf3f475125ad8bb3cafbd8a2c45948841
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
plugins/iot-headless/power/power-control.c

index eda7caf..7e20ca5 100644 (file)
@@ -245,7 +245,12 @@ static const dbus_interface_u dbus_interface = {
 static int powerkey_short_pressed_cb(void *data)
 {
        int keycode;
+       int retval;
+       guint64 current_time_ms = 0;
+       struct timespec ts;
+
        static int sleep_enabled = 0; /* initial sleep state: disabled */
+       static guint64 sleep_id = 0;  /* increased by 1 on enabling sleep */
 
        if (!data)
                return 0;
@@ -256,11 +261,16 @@ static int powerkey_short_pressed_cb(void *data)
 
        sleep_enabled ^= 1; /* toggle status */
        if (sleep_enabled) {
+               retval = clock_gettime(CLOCK_REALTIME, &ts);
+               if (retval == 0)
+                       current_time_ms = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
+
+               ++sleep_id;
+               gdbus_signal_emit(NULL, DEVICED_PATH_POWER, DEVICED_INTERFACE_POWER,
+                       "sleep", g_variant_new("(tt)", current_time_ms, sleep_id));
                device_notify(DEVICE_NOTIFIER_REQUEST_ENABLE_AUTOSLEEP, NULL);
-               _D("Sleep enabled");
        } else {
                device_notify(DEVICE_NOTIFIER_REQUEST_DISABLE_AUTOSLEEP, NULL);
-               _D("Sleep disabled");
        }
 
        return 0;