#include "common.h"
#include <systemd/sd-daemon.h>
#include <stdlib.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <string.h>
#define SEC_TO_USEC (1000*1000)
+#define DEVICED_PATH_DISPLAY "/Org/Tizen/System/DeviceD/Display"
+#define DEVICED_INTERFACE_DISPLAY "org.tizen.system.deviced.display"
+#define WAKEUP_SIGNAL "wakeup"
+#define SUSPEND_SIGNAL "sleep"
+
static unsigned int saved_timeout=0;
+static GDBusConnection *conn;
+static unsigned int sig_wakeup_id;
+static unsigned int sig_suspend_id;
/* Now, systemd support to enable/disable runtime watchdog */
/* https://github.com/systemd/systemd/commit/2787d83c2 */
return ret;
}
+static void _aw_signal_handler(GDBusConnection *connection, const gchar *sender,
+ const gchar *path, const gchar *interface, const gchar *signal,
+ GVariant *parameters, gpointer user_data) {
+
+ if (!strcmp(signal, WAKEUP_SIGNAL))
+ systemd_change_watchdog_timeout(saved_timeout);
+ else if (!strcmp(signal, SUSPEND_SIGNAL))
+ systemd_change_watchdog_timeout(0);
+}
+
int _aw_register(unsigned int timeout)
{
int ret;
+ GError *err = NULL;
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+
+ if (conn == NULL)
+ return -1;
+
+ sig_wakeup_id = g_dbus_connection_signal_subscribe(conn, NULL,
+ DEVICED_INTERFACE_DISPLAY, WAKEUP_SIGNAL, DEVICED_PATH_DISPLAY,
+ NULL, G_DBUS_SIGNAL_FLAGS_NONE, _aw_signal_handler, NULL, NULL);
+
+ sig_suspend_id = g_dbus_connection_signal_subscribe(conn, NULL,
+ DEVICED_INTERFACE_DISPLAY, SUSPEND_SIGNAL, DEVICED_PATH_DISPLAY,
+ NULL, G_DBUS_SIGNAL_FLAGS_NONE, _aw_signal_handler, NULL, NULL);
ret = systemd_change_watchdog_timeout(timeout);
if(ret <=0)