1 /* vi:set et ai sw=2 sts=2 ts=2: */
3 * Copyright (c) 2012 GENIVI.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
14 #include <systemd/sd-daemon.h>
16 #include <glib-object.h>
19 #include <boot-manager/watchdog-client.h>
23 /* property identifiers */
32 static void watchdog_client_constructed (GObject *object);
33 static void watchdog_client_finalize (GObject *object);
34 static void watchdog_client_get_property (GObject *object,
38 static void watchdog_client_set_property (GObject *object,
42 static gboolean watchdog_client_timeout (gpointer user_data);
46 struct _WatchdogClientClass
48 GObjectClass __parent__;
51 struct _WatchdogClient
61 G_DEFINE_TYPE (WatchdogClient, watchdog_client, G_TYPE_OBJECT);
66 watchdog_client_class_init (WatchdogClientClass *klass)
68 GObjectClass *gobject_class;
70 gobject_class = G_OBJECT_CLASS (klass);
71 gobject_class->constructed = watchdog_client_constructed;
72 gobject_class->finalize = watchdog_client_finalize;
73 gobject_class->get_property = watchdog_client_get_property;
74 gobject_class->set_property = watchdog_client_set_property;
76 g_object_class_install_property (gobject_class,
78 g_param_spec_uint ("timeout",
83 G_PARAM_CONSTRUCT_ONLY |
84 G_PARAM_STATIC_STRINGS));
90 watchdog_client_init (WatchdogClient *client)
97 watchdog_client_constructed (GObject *object)
99 WatchdogClient *client = WATCHDOG_CLIENT (object);
101 /* trigger a systemd watchdog timestap update now */
102 watchdog_client_timeout (client);
104 /* schedule a regular timeout to update the systemd watchdog timestamp */
105 client->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
107 watchdog_client_timeout,
108 g_object_ref (client),
109 (GDestroyNotify) g_object_unref);
115 watchdog_client_finalize (GObject *object)
117 WatchdogClient *client = WATCHDOG_CLIENT (object);
119 /* drop the watchdog timeout */
120 if (client->timeout_id > 0)
121 g_source_remove (client->timeout_id);
123 (*G_OBJECT_CLASS (watchdog_client_parent_class)->finalize) (object);
129 watchdog_client_get_property (GObject *object,
134 WatchdogClient *client = WATCHDOG_CLIENT (object);
139 g_value_set_uint (value, client->timeout);
142 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
150 watchdog_client_set_property (GObject *object,
155 WatchdogClient *client = WATCHDOG_CLIENT (object);
160 client->timeout = g_value_get_uint (value);
163 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
171 watchdog_client_timeout (gpointer user_data)
173 sd_notify (0, "WATCHDOG=1");
180 watchdog_client_new (guint timeout)
182 return g_object_new (TYPE_WATCHDOG_CLIENT, "timeout", timeout, NULL);