summaryrefslogtreecommitdiff
path: root/legacy-app-handler/main.c
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2012-07-09 12:53:25 +0100
committerJonathan Maw <jonathan.maw@codethink.co.uk>2012-07-17 15:26:01 +0100
commite9866eb5348e1131edbf6ed9427eb05cab3c700e (patch)
tree5d453dbb8587fb5f22c50d956b9703c923fe932a /legacy-app-handler/main.c
parentbbb6eb400cf336bcbae844159f9ba989fd06aee4 (diff)
downloadnode-startup-controller-e9866eb5348e1131edbf6ed9427eb05cab3c700e.tar.gz
Merge into one process, change D-Bus interfaces and write LUC to file
The following changes were made: - Restructure the D-Bus interfaces: -- The old boot manager interface is removed, we are no longer interested in being a remote controller of systemd. -- The LUC Handler has been rewritten and renamed to org.genivi.BootManager1.BootManager. It has the following methods: --- BeginLUCRegistration() initializes the LUC registration sequence at shutdown. --- RegisterWithLUC(a{ias}) registers one or more apps with different LUC types. --- FinishLUCRegistration() finishes the LUC registration sequence and atomically replaces the previous LUC. -- The legacy application handler has been renamed to org.genivi.BootManager1.LegacyAppHandler. This interface is not for external use. It is meant only for the command- line interface to communicate with the boot manager. -- The LastUserContext property has been removed. - The last user context is now stored in a file rather than with GSettings. This was requested after the Gothenburg F2F, but is included because it is easier to make the change now than modify GSettings only to remove it later. - All services run as part of the same process (i.e. boot-manager). - All services run on the system bus. Because of this, the boot manager's command-line interface is handled differently, as the previous implementation, using GApplication, does not work on the system bus. The command-line interface now works by making a D-Bus call to the boot manager service, instead of using GApplication's remote command-line functionality. - The LUC Handler tests have been renamed to the boot manager tests, and are changed in line with the new interface methods. Note: The legacy app handler tests have not yet been modified to work with these changes.
Diffstat (limited to 'legacy-app-handler/main.c')
-rw-r--r--legacy-app-handler/main.c297
1 files changed, 0 insertions, 297 deletions
diff --git a/legacy-app-handler/main.c b/legacy-app-handler/main.c
deleted file mode 100644
index 398ac04..0000000
--- a/legacy-app-handler/main.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/* vi:set et ai sw=2 sts=2 ts=2: */
-/* -
- * Copyright (c) 2012 GENIVI.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#include <glib.h>
-#include <gio/gio.h>
-
-#include <dlt/dlt.h>
-
-#include <legacy-app-handler/la-handler-application.h>
-#include <legacy-app-handler/la-handler-dbus.h>
-#include <legacy-app-handler/la-handler-service.h>
-
-
-
-DLT_DECLARE_CONTEXT (la_handler_context);
-
-
-
-static void
-dlt_cleanup (void)
-{
- DLT_UNREGISTER_CONTEXT (la_handler_context);
- DLT_UNREGISTER_APP ();
-}
-
-
-
-static gboolean
-handle_command_line (int argc,
- char **argv,
- GDBusConnection *connection)
-{
- GOptionContext *context = g_option_context_new (NULL);
- LAHandler *legacy_app_handler;
- gboolean do_register = FALSE;
- gboolean do_deregister = FALSE;
- GError *error = NULL;
- gchar *unit = NULL;
- gchar *log_message = NULL;
- gchar *mode = NULL;
- gint timeout = 0;
-
- GOptionEntry entries[] = {
- {"deregister", 0, 0, G_OPTION_ARG_NONE, &do_deregister, NULL, NULL},
- {"register", 0, 0, G_OPTION_ARG_NONE, &do_register, NULL, NULL},
- {"unit", 0, 0, G_OPTION_ARG_STRING, &unit, NULL, NULL},
- {"timeout", 0, 0, G_OPTION_ARG_INT, &timeout, NULL, NULL},
- {"shutdown-mode", 0, 0, G_OPTION_ARG_STRING, &mode, NULL, NULL},
- {NULL},
- };
-
- /* set up the option context */
- g_option_context_set_help_enabled (context, FALSE);
- g_option_context_add_main_entries (context, entries, NULL);
-
- /* parse the arguments into argument data */
- if (!g_option_context_parse (context, &argc, &argv, &error) || error != NULL)
- {
- /* an error occurred */
- log_message =
- g_strdup_printf ("Error occurred parsing arguments: %s\n", error->message);
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_message));
-
- g_error_free (error);
- g_free (log_message);
-
- return FALSE;
- }
- else if (do_register && !do_deregister)
- {
- if (unit == NULL || *unit == '\0' || timeout < 0)
- {
- /* register was called incorrectly */
- log_message =
- g_strdup_printf ("Invalid arguments for --register. A unit must be specified"
- " and the timeout must be positive.");
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_message));
-
- g_free (log_message);
-
- return FALSE;
- }
-
- /* get a legacy app handler interface */
- legacy_app_handler =
- la_handler_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE,
- "org.genivi.LegacyAppHandler1",
- "/org/genivi/LegacyAppHandler1", NULL, &error);
- if (error != NULL)
- {
- /* failed to connect to the legacy app handler */
- log_message =
- g_strdup_printf ("Error occurred connecting to legacy app handler "
- "interface: %s", error->message);
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_message));
-
- g_free (log_message);
- g_error_free (error);
-
- return FALSE;
- }
-
- /* call the legacy app handler's Register() method */
- la_handler_call_register_sync (legacy_app_handler, unit,
- mode ? mode : "normal", (guint) timeout, NULL,
- &error);
- if (error != NULL)
- {
- /* failed to register the legacy app */
- log_message = g_strdup_printf ("Error occurred registering legacy app: %s",
- error->message);
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_message));
-
- g_object_unref (legacy_app_handler);
- g_free (log_message);
- g_error_free (error);
-
- return FALSE;
- }
-
- g_object_unref (legacy_app_handler);
-
- return TRUE;
-
- }
- else if (do_deregister && !do_register)
- {
- if (unit == NULL || *unit == '\0')
- {
- /* deregister was called incorrectly */
- log_message =
- g_strdup_printf ("Invalid arguments for --deregister. A unit must be "
- "specified.");
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_message));
-
- g_free (log_message);
-
- return FALSE;
- }
-
- /* get a legacy app handler interface */
- legacy_app_handler =
- la_handler_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE,
- "org.genivi.LegacyAppHandler1",
- "/org/genivi/LegacyAppHandler1", NULL, &error);
- if (error != NULL)
- {
- log_message =
- g_strdup_printf ("Error occurred connecting to legacy app handler "
- "interface: %s", error->message);
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_message));
-
- g_free (log_message);
- g_error_free (error);
-
- return FALSE;
- }
-
- /* call the legacy app handler's Deregister() method */
- la_handler_call_deregister_sync (legacy_app_handler, unit, NULL, &error);
- if (error != NULL)
- {
- log_message = g_strdup_printf ("Error occurred deregistering legacy "
- "app: %s", error->message);
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_message));
-
- g_object_unref (legacy_app_handler);
- g_free (log_message);
- g_error_free (error);
-
- return FALSE;
- }
-
- g_object_unref (legacy_app_handler);
-
- return TRUE;
- }
- else if (do_register && do_deregister)
- {
- log_message =
- g_strdup_printf ("Invalid arguments. Please choose either --register or "
- "--deregister.");
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_message));
-
- g_free (log_message);
-
- return FALSE;
- }
- else
- {
- DLT_LOG (la_handler_context, DLT_LOG_ERROR,
- DLT_STRING ("No arguments recognised"));
- return FALSE;
- }
-}
-
-
-
-int
-main (int argc,
- char **argv)
-{
- LAHandlerApplication *application;
- LAHandlerService *service;
- GDBusConnection *connection;
- gboolean is_remote;
- GError *error = NULL;
- gchar *log_text;
- int exit_status;
-
- /* check if this program execution is meant as a remote application.
- * if it is a remote application, then it will be called with command-line arguments. */
- is_remote = (argc > 1) ? TRUE : FALSE;
-
- /* register the application and context in DLT */
- if (!is_remote)
- {
- DLT_REGISTER_APP ("BMGR", "GENIVI Boot Manager");
- DLT_REGISTER_CONTEXT (la_handler_context, "LAH",
- "Context of the legacy application handler that hooks legacy "
- "applications up with the shutdown concept of the Node State "
- "Manager");
- atexit (dlt_cleanup);
- }
-
- /* initialize the GType type system */
- g_type_init ();
-
- /* attempt to connect to D-Bus */
- connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
- if (connection == NULL || error != NULL || !G_IS_DBUS_CONNECTION (connection))
- {
- log_text = g_strdup_printf ("Failed to connect to D-Bus: %s", error->message);
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_text));
-
- /* clean up */
- g_free (log_text);
- g_error_free (error);
-
- return EXIT_FAILURE;
- }
-
- if (is_remote)
- {
- if (!handle_command_line (argc, argv, connection))
- exit_status = EXIT_FAILURE;
- else
- exit_status = EXIT_SUCCESS;
- }
- else
- {
- /* instantiate the LegacyAppHandler service implementation */
- service = la_handler_service_new (connection);
- if (!la_handler_service_start (service, &error))
- {
- log_text = g_strdup_printf ("Failed to start the legacy app handler service: %s",
- error->message);
- DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_text));
-
- /* clean up */
- g_free (log_text);
- g_error_free (error);
- g_object_unref (service);
- g_object_unref (connection);
-
- return EXIT_FAILURE;
- }
-
- /* create and run the main application */
- application =
- la_handler_application_new (service, G_APPLICATION_IS_SERVICE);
-
- exit_status = g_application_run (G_APPLICATION (application), argc, argv);
- g_object_unref (application);
-
- /* release allocated objects */
- g_object_unref (service);
- }
-
- g_object_unref (connection);
-
- return exit_status;
-}