aaab227b34da7e25e55d53788055ad121c8244fc
[profile/ivi/node-startup-controller.git] / boot-manager / boot-manager-application.c
1 /* vi:set et ai sw=2 sts=2 ts=2: */
2 /* -
3  * Copyright (c) 2012 GENIVI.
4  *
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/.
8  */
9
10 #ifdef HAVE_CONFIG_H
11 #include <config.h>
12 #endif
13
14 #include <glib-object.h>
15 #include <gio/gio.h>
16
17 #include <common/watchdog-client.h>
18
19 #include <boot-manager/boot-manager-dbus.h>
20 #include <boot-manager/boot-manager-application.h>
21 #include <boot-manager/boot-manager-service.h>
22
23
24
25 /* property identifiers */
26 enum
27 {
28   PROP_0,
29   PROP_BOOT_MANAGER_SERVICE,
30 };
31
32
33
34 static void boot_manager_application_finalize     (GObject      *object);
35 static void boot_manager_application_get_property (GObject      *object,
36                                                    guint         prop_id,
37                                                    GValue       *value,
38                                                    GParamSpec   *pspec);
39 static void boot_manager_application_set_property (GObject      *object,
40                                                    guint         prop_id,
41                                                    const GValue *value,
42                                                    GParamSpec   *pspec);
43 static void boot_manager_application_startup      (GApplication *application);
44
45
46
47 struct _BootManagerApplicationClass
48 {
49   GApplicationClass __parent__;
50 };
51
52 struct _BootManagerApplication
53 {
54   GApplication       __parent__;
55
56   /* systemd watchdog client that repeatedly asks systemd to update
57    * the watchdog timestamp */
58   WatchdogClient    *watchdog_client;
59
60   /* service object that implements the boot manager D-Bus interface */
61   BootManagerService *service;
62 };
63
64
65
66 G_DEFINE_TYPE (BootManagerApplication, boot_manager_application, G_TYPE_APPLICATION);
67
68
69
70 static void
71 boot_manager_application_class_init (BootManagerApplicationClass *klass)
72 {
73   GApplicationClass *gapplication_class;
74   GObjectClass *gobject_class;
75
76   gobject_class = G_OBJECT_CLASS (klass);
77   gobject_class->finalize = boot_manager_application_finalize;
78   gobject_class->get_property = boot_manager_application_get_property;
79   gobject_class->set_property = boot_manager_application_set_property;
80
81   gapplication_class = G_APPLICATION_CLASS (klass);
82   gapplication_class->startup = boot_manager_application_startup;
83
84   g_object_class_install_property (gobject_class,
85                                    PROP_BOOT_MANAGER_SERVICE,
86                                    g_param_spec_object ("boot-manager-service",
87                                                         "boot-manager-service",
88                                                         "boot-manager-service",
89                                                         BOOT_MANAGER_TYPE_SERVICE,
90                                                         G_PARAM_READWRITE |
91                                                         G_PARAM_CONSTRUCT_ONLY));
92 }
93
94
95
96 static void
97 boot_manager_application_init (BootManagerApplication *application)
98 {
99   /* update systemd's watchdog timestamp every 120 seconds */
100   application->watchdog_client = watchdog_client_new (120);
101 }
102
103
104
105 static void
106 boot_manager_application_finalize (GObject *object)
107 {
108   BootManagerApplication *application = BOOT_MANAGER_APPLICATION (object);
109
110   /* release the watchdog client */
111   g_object_unref (application->watchdog_client);
112
113   /* release the boot manager service implementation */
114   if (application->service != NULL)
115     g_object_unref (application->service);
116
117   (*G_OBJECT_CLASS (boot_manager_application_parent_class)->finalize) (object);
118 }
119
120
121
122 static void
123 boot_manager_application_get_property (GObject    *object,
124                                        guint       prop_id,
125                                        GValue     *value,
126                                        GParamSpec *pspec)
127 {
128   BootManagerApplication *application = BOOT_MANAGER_APPLICATION (object);
129
130   switch (prop_id)
131     {
132     case PROP_BOOT_MANAGER_SERVICE:
133       g_value_set_object (value, application->service);
134       break;
135     default:
136       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137       break;
138     }
139 }
140
141
142
143 static void
144 boot_manager_application_set_property (GObject      *object,
145                                        guint         prop_id,
146                                        const GValue *value,
147                                        GParamSpec   *pspec)
148 {
149   BootManagerApplication *application = BOOT_MANAGER_APPLICATION (object);
150
151   switch (prop_id)
152     {
153     case PROP_BOOT_MANAGER_SERVICE:
154       application->service = g_value_dup_object (value);
155       break;
156     default:
157       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
158       break;
159     }
160 }
161
162
163
164 static void
165 boot_manager_application_startup (GApplication *app)
166 {
167   BootManagerApplication *application = BOOT_MANAGER_APPLICATION (app);
168 }
169
170
171
172 BootManagerApplication *
173 boot_manager_application_new (BootManagerService *service)
174 {
175   return g_object_new (BOOT_MANAGER_TYPE_APPLICATION,
176                        "application-id", "org.genivi.BootManager1",
177                        "flags", G_APPLICATION_IS_SERVICE,
178                        "boot-manager-service", service,
179                        NULL);
180 }