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 <glib-object.h>
17 #include <common/watchdog-client.h>
19 #include <luc-handler/luc-handler-dbus.h>
20 #include <luc-handler/luc-handler-application.h>
21 #include <luc-handler/luc-handler-service.h>
25 /* property identifiers */
29 PROP_LUC_HANDLER_SERVICE,
34 static void luc_handler_application_finalize (GObject *object);
35 static void luc_handler_application_get_property (GObject *object,
39 static void luc_handler_application_set_property (GObject *object,
43 static void luc_handler_application_startup (GApplication *application);
47 struct _LUCHandlerApplicationClass
49 GApplicationClass __parent__;
52 struct _LUCHandlerApplication
54 GApplication __parent__;
56 /* systemd watchdog client that repeatedly asks systemd to update
57 * the watchdog timestamp */
58 WatchdogClient *watchdog_client;
60 /* service object that implements the LUC Handler D-Bus interface */
61 LUCHandlerService *service;
66 G_DEFINE_TYPE (LUCHandlerApplication, luc_handler_application, G_TYPE_APPLICATION);
71 luc_handler_application_class_init (LUCHandlerApplicationClass *klass)
73 GApplicationClass *gapplication_class;
74 GObjectClass *gobject_class;
76 gobject_class = G_OBJECT_CLASS (klass);
77 gobject_class->finalize = luc_handler_application_finalize;
78 gobject_class->get_property = luc_handler_application_get_property;
79 gobject_class->set_property = luc_handler_application_set_property;
81 gapplication_class = G_APPLICATION_CLASS (klass);
82 gapplication_class->startup = luc_handler_application_startup;
84 g_object_class_install_property (gobject_class,
85 PROP_LUC_HANDLER_SERVICE,
86 g_param_spec_object ("luc-handler-service",
87 "luc-handler-service",
88 "luc-handler-service",
89 LUC_HANDLER_TYPE_SERVICE,
91 G_PARAM_CONSTRUCT_ONLY));
97 luc_handler_application_init (LUCHandlerApplication *application)
104 luc_handler_application_finalize (GObject *object)
106 LUCHandlerApplication *application = LUC_HANDLER_APPLICATION (object);
108 /* release the watchdog client */
109 g_object_unref (application->watchdog_client);
111 /* release the LUC Handler service implementation */
112 if (application->service != NULL)
113 g_object_unref (application->service);
115 (*G_OBJECT_CLASS (luc_handler_application_parent_class)->finalize) (object);
121 luc_handler_application_get_property (GObject *object,
126 LUCHandlerApplication *application = LUC_HANDLER_APPLICATION (object);
130 case PROP_LUC_HANDLER_SERVICE:
131 g_value_set_object (value, application->service);
134 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
142 luc_handler_application_set_property (GObject *object,
147 LUCHandlerApplication *application = LUC_HANDLER_APPLICATION (object);
151 case PROP_LUC_HANDLER_SERVICE:
152 application->service = g_value_dup_object (value);
155 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
163 luc_handler_application_startup (GApplication *app)
165 LUCHandlerApplication *application = LUC_HANDLER_APPLICATION (app);
167 /* update systemd's watchdog timestamp every 120 seconds */
168 application->watchdog_client = watchdog_client_new (120);
173 LUCHandlerApplication *
174 luc_handler_application_new (LUCHandlerService *service)
176 return g_object_new (LUC_HANDLER_TYPE_APPLICATION,
177 "application-id", "org.genivi.LUCHandler1",
178 "flags", G_APPLICATION_IS_SERVICE,
179 "luc-handler-service", service,