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 <legacy-app-handler/la-handler-application.h>
24 #include <legacy-app-handler/la-handler-service.h>
28 DLT_DECLARE_CONTEXT (la_handler_context);
35 DLT_UNREGISTER_CONTEXT (la_handler_context);
36 DLT_UNREGISTER_APP ();
45 LAHandlerApplication *application;
46 LAHandlerService *service;
47 GDBusConnection *connection;
53 /* check if this program execution is meant as a remote application.
54 * if it is a remote application, then it will be called with command-line arguments. */
55 is_remote = (argc > 1) ? TRUE : FALSE;
57 /* register the application and context in DLT */
60 DLT_REGISTER_APP ("BMGR", "GENIVI Boot Manager");
61 DLT_REGISTER_CONTEXT (la_handler_context, "LAH",
62 "Context of the legacy application handler that hooks legacy "
63 "applications up with the shutdown concept of the Node State "
68 /* initialize the GType type system */
71 /* attempt to connect to D-Bus */
72 connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
73 if (connection == NULL || error != NULL || !G_IS_DBUS_CONNECTION (connection))
75 log_text = g_strdup_printf ("Failed to connect to D-Bus: %s", error->message);
76 DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_text));
85 /* instantiate the LegacyAppHandler service implementation */
86 service = la_handler_service_new (connection);
87 if (!la_handler_service_start (service, &error))
89 log_text = g_strdup_printf ("Failed to start the legacy app handler service: %s",
91 DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_text));
96 g_object_unref (service);
97 g_object_unref (connection);
102 /* create and run the main application */
105 /* an application with the flag G_APPLICATION_IS_SERVICE tries to be the primary
106 * instance of the application, and fails if another instance already exists.
107 * setting G_APPLICATION_IS_LAUNCHER indicates that it shouldn't try to be the
108 * primary instance */
110 la_handler_application_new (service, G_APPLICATION_HANDLES_COMMAND_LINE |
111 G_APPLICATION_IS_LAUNCHER);
115 /* this application is meant to be the primary instance, so
116 * G_APPLICATION_IS_LAUNCHER is not set */
118 la_handler_application_new (service, G_APPLICATION_IS_SERVICE);
121 /* run the application */
122 exit_status = g_application_run (G_APPLICATION (application), argc, argv);
123 g_object_unref (application);
125 /* release allocated objects */
126 g_object_unref (service);
127 g_object_unref (connection);