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/.
23 #include <boot-manager/boot-manager-application.h>
24 #include <boot-manager/boot-manager-command-line.h>
25 #include <boot-manager/boot-manager-dbus.h>
26 #include <boot-manager/boot-manager-service.h>
27 #include <boot-manager/la-handler-service.h>
28 #include <boot-manager/systemd-manager-dbus.h>
29 #include <boot-manager/target-startup-monitor.h>
33 DLT_DECLARE_CONTEXT (boot_manager_context);
34 DLT_DECLARE_CONTEXT (la_handler_context);
41 DLT_UNREGISTER_CONTEXT (boot_manager_context);
42 DLT_UNREGISTER_CONTEXT (la_handler_context);
43 DLT_UNREGISTER_APP ();
52 BootManagerApplication *application;
53 TargetStartupMonitor *target_startup_monitor;
54 BootManagerService *boot_manager_service;
55 LAHandlerService *la_handler_service;
56 GDBusConnection *connection;
57 SystemdManager *systemd_manager;
58 JobManager *job_manager;
62 /* register the application and context in DLT */
63 DLT_REGISTER_APP ("BMGR", "GENIVI Boot Manager");
64 DLT_REGISTER_CONTEXT (boot_manager_context, "MGR",
65 "Context of the boot manager itself");
66 DLT_REGISTER_CONTEXT (la_handler_context, "LAH",
67 "Context of the legacy application handler that hooks legacy "
68 "applications up with the shutdown concept of the Node State "
71 /* have DLT unregistered at exit */
72 atexit (unregister_dlt);
74 /* initialize the GType type system */
77 /* attempt to connect to D-Bus */
78 connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
79 if (connection == NULL)
81 g_warning ("Failed to connect to the system bus: %s", error->message);
89 /* Parse and react to the command-line arguments instead of starting the application
90 * if any arguments are given */
93 exit_status = boot_manager_handle_command_line (argc, argv, connection);
95 g_object_unref (connection);
100 /* attempt to connect to the systemd manager */
102 systemd_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
103 G_DBUS_PROXY_FLAGS_NONE,
104 "org.freedesktop.systemd1",
105 "/org/freedesktop/systemd1",
107 if (systemd_manager == NULL)
109 g_warning ("Failed to connect to the systemd manager: %s", error->message);
112 g_error_free (error);
113 g_object_unref (connection);
118 /* subscribe to the systemd manager */
119 if (!systemd_manager_call_subscribe_sync (systemd_manager, NULL, &error))
121 g_warning ("Failed to subscribe to the systemd manager: %s", error->message);
124 g_error_free (error);
125 g_object_unref (connection);
130 /* instantiate the boot manager service implementation */
131 boot_manager_service = boot_manager_service_new (connection);
133 /* instantiate the job manager */
134 job_manager = job_manager_new (connection, systemd_manager);
136 /* start up the target startup monitor */
137 target_startup_monitor = target_startup_monitor_new (systemd_manager);
139 /* instantiate the legacy app handler */
140 la_handler_service = la_handler_service_new (connection, job_manager);
142 /* create and run the main application */
143 application = boot_manager_application_new (connection, job_manager,
144 la_handler_service, boot_manager_service);
145 exit_status = g_application_run (G_APPLICATION (application), 0, NULL);
146 g_object_unref (application);
148 /* release allocated objects */
149 g_object_unref (target_startup_monitor);
150 g_object_unref (systemd_manager);
151 g_object_unref (job_manager);
152 g_object_unref (boot_manager_service);
153 g_object_unref (connection);