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;
63 /* register the application and context in DLT */
64 DLT_REGISTER_APP ("BMGR", "GENIVI Boot Manager");
65 DLT_REGISTER_CONTEXT (boot_manager_context, "MGR",
66 "Context of the boot manager itself");
67 DLT_REGISTER_CONTEXT (la_handler_context, "LAH",
68 "Context of the legacy application handler that hooks legacy "
69 "applications up with the shutdown concept of the Node State "
72 /* have DLT unregistered at exit */
73 atexit (unregister_dlt);
75 /* initialize the GType type system */
78 /* attempt to connect to D-Bus */
79 connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
80 if (connection == NULL)
82 g_warning ("Failed to connect to the system bus: %s", error->message);
90 /* Parse and react to the command-line arguments instead of starting the application
91 * if any arguments are given */
94 exit_status = boot_manager_handle_command_line (argc, argv, connection);
95 g_object_unref (connection);
99 /* attempt to connect to the systemd manager */
101 systemd_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
102 G_DBUS_PROXY_FLAGS_NONE,
103 "org.freedesktop.systemd1",
104 "/org/freedesktop/systemd1",
106 if (systemd_manager == NULL)
108 g_warning ("Failed to connect to the systemd manager: %s", error->message);
111 g_error_free (error);
112 g_object_unref (connection);
117 /* subscribe to the systemd manager */
118 if (!systemd_manager_call_subscribe_sync (systemd_manager, NULL, &error))
120 g_warning ("Failed to subscribe to the systemd manager: %s", error->message);
123 g_error_free (error);
124 g_object_unref (connection);
129 /* instantiate the boot manager service implementation */
130 boot_manager_service = boot_manager_service_new (connection);
132 /* instantiate the job manager */
133 job_manager = job_manager_new (connection, systemd_manager);
135 /* start up the target startup monitor */
136 target_startup_monitor = target_startup_monitor_new (systemd_manager);
138 /* instantiate the legacy app handler */
139 la_handler_service = la_handler_service_new (connection, job_manager);
141 /* create the main loop */
142 main_loop = g_main_loop_new (NULL, FALSE);
144 /* create and run the main application */
145 application = boot_manager_application_new (main_loop, connection, job_manager,
146 la_handler_service, boot_manager_service);
148 /* run the main loop */
149 g_main_loop_run (main_loop);
150 g_main_loop_unref (main_loop);
152 /* release allocated objects */
153 g_object_unref (application);
154 g_object_unref (target_startup_monitor);
155 g_object_unref (systemd_manager);
156 g_object_unref (job_manager);
157 g_object_unref (boot_manager_service);
158 g_object_unref (connection);