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/.
18 #include <glib-object.h>
23 #include <common/watchdog-client.h>
25 #include <legacy-app-handler/la-handler-dbus.h>
26 #include <legacy-app-handler/la-handler-application.h>
27 #include <legacy-app-handler/la-handler-service.h>
31 DLT_IMPORT_CONTEXT (la_handler_context);
35 /* property identifiers */
39 PROP_LA_HANDLER_SERVICE,
44 static void la_handler_application_finalize (GObject *object);
45 static void la_handler_application_get_property (GObject *object,
49 static void la_handler_application_set_property (GObject *object,
53 static void la_handler_application_startup (GApplication *application);
57 struct _LAHandlerApplicationClass
59 GApplicationClass __parent__;
62 struct _LAHandlerApplication
64 GApplication __parent__;
66 /* systemd watchdog client that repeatedly asks systemd to update
67 * the watchdog timestamp */
68 WatchdogClient *watchdog_client;
70 /* service object that implements the Legacy App Handler D-Bus interface */
71 LAHandlerService *service;
76 G_DEFINE_TYPE (LAHandlerApplication, la_handler_application, G_TYPE_APPLICATION);
81 la_handler_application_class_init (LAHandlerApplicationClass *klass)
83 GApplicationClass *gapplication_class;
84 GObjectClass *gobject_class;
86 gobject_class = G_OBJECT_CLASS (klass);
87 gobject_class->finalize = la_handler_application_finalize;
88 gobject_class->get_property = la_handler_application_get_property;
89 gobject_class->set_property = la_handler_application_set_property;
91 gapplication_class = G_APPLICATION_CLASS (klass);
92 gapplication_class->startup = la_handler_application_startup;
94 g_object_class_install_property (gobject_class,
95 PROP_LA_HANDLER_SERVICE,
96 g_param_spec_object ("la-handler-service",
99 LA_HANDLER_TYPE_SERVICE,
101 G_PARAM_CONSTRUCT_ONLY |
102 G_PARAM_STATIC_STRINGS));
108 la_handler_application_init (LAHandlerApplication *application)
115 la_handler_application_finalize (GObject *object)
117 LAHandlerApplication *application = LA_HANDLER_APPLICATION (object);
119 /* release the watchdog client */
120 if (application->watchdog_client != NULL)
121 g_object_unref (application->watchdog_client);
123 /* release the Legacy App Handler service implementation */
124 if (application->service != NULL)
125 g_object_unref (application->service);
127 (*G_OBJECT_CLASS (la_handler_application_parent_class)->finalize) (object);
133 la_handler_application_get_property (GObject *object,
138 LAHandlerApplication *application = LA_HANDLER_APPLICATION (object);
142 case PROP_LA_HANDLER_SERVICE:
143 g_value_set_object (value, application->service);
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
154 la_handler_application_set_property (GObject *object,
159 LAHandlerApplication *application = LA_HANDLER_APPLICATION (object);
163 case PROP_LA_HANDLER_SERVICE:
164 application->service = g_value_dup_object (value);
167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
175 la_handler_application_startup (GApplication *app)
177 LAHandlerApplication *application = LA_HANDLER_APPLICATION (app);
179 /* chain up to the parent class */
180 (*G_APPLICATION_CLASS (la_handler_application_parent_class)->startup) (app);
182 /* update systemd's watchdog timestamp every 120 seconds */
183 application->watchdog_client = watchdog_client_new (120);
185 /* the Legacy Application Handler should keep running until it is shut down by the Node
187 g_application_hold (app);
192 LAHandlerApplication *
193 la_handler_application_new (LAHandlerService *service,
194 GApplicationFlags flags)
196 return g_object_new (LA_HANDLER_TYPE_APPLICATION,
197 "application-id", "org.genivi.LegacyAppHandler1",
199 "la-handler-service", service,