Add a stand-alone legacy-app-handler helper, work on tests
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Mon, 23 Jul 2012 16:41:17 +0000 (17:41 +0100)
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Tue, 24 Jul 2012 13:21:54 +0000 (14:21 +0100)
The new legacy-app-helper binary translates the shutdown mode strings
into NSMShutdownType enum values and passes them on to the legacy app
handler D-Bus service. Thus, this commit also updates the
org.genivi.BootManager1.LegacyAppHandler interface to use an int for the
shutdown mode.

This commit furthermore drops the old command-line handling code in
the boot manager and reworks the legacy-app-handler tests a little
bit.

25 files changed:
Makefile.am
boot-manager/Makefile.am
boot-manager/boot-manager-command-line.c [deleted file]
boot-manager/boot-manager-command-line.h [deleted file]
boot-manager/la-handler-service.c
boot-manager/main.c
common/Makefile.am
common/la-handler-dbus.xml [moved from boot-manager/la-handler-dbus.xml with 77% similarity]
configure.ac
legacy-app-handler/Makefile.am [new file with mode: 0644]
legacy-app-handler/main.c [new file with mode: 0644]
nsm-dummy/Makefile.am
nsm-dummy/dbus/com.contiautomotive.NodeStateManager.Consumer.service.in
nsm-dummy/dbus/com.contiautomotive.NodeStateManager.LifecycleControl.service.in
nsm-dummy/systemd/nsm-dummy.service.in
tests/legacy-app-handler/Makefile.am
tests/legacy-app-handler/legacy-app-handler-test [new file with mode: 0755]
tests/legacy-app-handler/legacy-app-handler-test.conf [moved from tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test.conf with 100% similarity]
tests/legacy-app-handler/legacy-app-handler-test1.service.in [new file with mode: 0644]
tests/legacy-app-handler/legacy-app-handler-test2.service.in [new file with mode: 0644]
tests/legacy-app-handler/legacy-app-handler-test3.service.in [new file with mode: 0644]
tests/legacy-app-handler/org-genivi-LegacyAppHandler1-test-service.py [deleted file]
tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test1.service.in [deleted file]
tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test2.service.in [deleted file]
tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test3.service.in [deleted file]

index 8719672..a84f9b2 100644 (file)
@@ -3,6 +3,7 @@
 SUBDIRS =                                                              \
        common                                                          \
        boot-manager                                                    \
+       legacy-app-handler                                              \
        nsm-dummy                                                       \
        tests
 
index 05c52be..3548916 100644 (file)
@@ -11,20 +11,16 @@ boot_manager_PROGRAMS =                                                     \
 
 boot_manager_built_headers =                                           \
        boot-manager-dbus.h                                             \
-       la-handler-dbus.h                                               \
        systemd-manager-dbus.h
 
 boot_manager_built_sources =                                           \
        boot-manager-dbus.c                                             \
-       la-handler-dbus.c                                               \
        systemd-manager-dbus.c                                          \
        $(boot_manager_built_headers)
 
 boot_manager_SOURCES =                                                 \
        boot-manager-application.c                                      \
        boot-manager-application.h                                      \
-       boot-manager-command-line.c                                     \
-       boot-manager-command-line.h                                     \
        boot-manager-service.c                                          \
        boot-manager-service.h                                          \
        glib-extensions.c                                               \
@@ -95,7 +91,6 @@ CLEANFILES =                                                          \
 
 EXTRA_DIST =                                                           \
        boot-manager-dbus.xml                                           \
-       la-handler-dbus.xml                                             \
        systemd-manager-dbus.xml                                        \
        $(dbus_service_in_files)                                        \
        $(systemd_service_in_files)
@@ -114,14 +109,6 @@ boot-manager-dbus.h: boot-manager-dbus.xml Makefile
            --annotate org.genivi.BootManager1.BootManager org.gtk.GDBus.C.Name \
              Boot_Manager $<
 
-la-handler-dbus.h: la-handler-dbus.xml Makefile
-       $(AM_V_GEN) $(GDBUS_CODEGEN)                                    \
-           --interface-prefix org.genivi                               \
-           --c-namespace ""                                            \
-           --generate-c-code la-handler-dbus                           \
-           --annotate org.genivi.BootManager1.LegacyAppHandler org.gtk.GDBus.C.Name    \
-             LA_Handler $<
-
 systemd-manager-dbus.h: systemd-manager-dbus.xml Makefile
        $(AM_V_GEN) $(GDBUS_CODEGEN)                                    \
            --interface-prefix org.freedesktop.systemd1                 \
diff --git a/boot-manager/boot-manager-command-line.c b/boot-manager/boot-manager-command-line.c
deleted file mode 100644 (file)
index e83f5ff..0000000
+++ /dev/null
@@ -1,176 +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 <boot-manager/boot-manager-command-line.h>
-#include <boot-manager/la-handler-dbus.h>
-
-
-DLT_IMPORT_CONTEXT (la_handler_context);
-
-
-
-gint
-boot_manager_handle_command_line (int              argc,
-                                  char           **argv,
-                                  GDBusConnection *connection)
-{
-  GOptionContext *context = g_option_context_new (NULL);
-  LAHandler      *legacy_app_handler = NULL;
-  gboolean        do_register = FALSE;
-  gboolean        do_deregister = FALSE;
-  GError         *error = NULL;
-  gchar          *unit = NULL;
-  gchar          *log_message = NULL;
-  gchar          *mode = NULL;
-  gint            timeout = 0;
-  int             exit_status;
-
-  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));
-
-      exit_status = EXIT_FAILURE;
-      goto finish;
-    }
-
-  /* validate the argument data */
-  if (unit == NULL || *unit == '\0')
-    {
-      DLT_LOG (la_handler_context, DLT_LOG_ERROR,
-               DLT_STRING ("Invalid arguments: unit must be defined"));
-      exit_status = EXIT_FAILURE;
-      goto finish;
-    }
-
-  if (!(do_register ^ do_deregister))
-    {
-      DLT_LOG (la_handler_context, DLT_LOG_ERROR,
-               DLT_STRING ("Invalid arguments: Please select either --register or "
-                           "--deregister"));
-      exit_status = EXIT_FAILURE;
-      goto finish;
-    }
-
-  if (do_register && timeout < 0)
-    {
-      DLT_LOG (la_handler_context, DLT_LOG_ERROR,
-               DLT_STRING ("Invalid arguments: Timeout must be non-negative"));
-      exit_status = EXIT_FAILURE;
-      goto finish;
-    }
-
-  /* get a legacy app handler interface */
-  legacy_app_handler =
-    la_handler_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE,
-                               "org.genivi.BootManager1",
-                               "/org/genivi/BootManager1/LegacyAppHandler", 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);
-
-      exit_status = EXIT_FAILURE;
-      goto finish;
-    }
-
-  if (do_register)
-    {
-      /* 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));
-
-          exit_status = EXIT_FAILURE;
-        }
-      else
-        {
-          exit_status = EXIT_SUCCESS;
-        }
-      goto finish;
-    }
-  else if (do_deregister)
-    {
-      /* call the legacy app handler's Deregister() method */
-      la_handler_call_deregister_sync (legacy_app_handler, unit, NULL, &error);
-      if (error != NULL)
-        {
-          /* failed to deregister the legacy app */
-          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));
-
-          exit_status = EXIT_FAILURE;
-        }
-      else
-        {
-          exit_status = EXIT_SUCCESS;
-        }
-      goto finish;
-    }
-  else
-    {
-      DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING ("unexpected input"));
-      exit_status = EXIT_FAILURE;
-      goto finish;
-    }
-
-  finish:
-  g_option_context_free (context);
-  if (legacy_app_handler != NULL)
-    g_object_unref (legacy_app_handler);
-  if (error != NULL)
-    g_error_free (error);
-  g_free (unit);
-  g_free (log_message);
-  g_free (mode);
-  return exit_status;
-}
diff --git a/boot-manager/boot-manager-command-line.h b/boot-manager/boot-manager-command-line.h
deleted file mode 100644 (file)
index 45e0611..0000000
+++ /dev/null
@@ -1,15 +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/.
- */
-
-#include <glib.h>
-#include <gio/gio.h>
-
-gint boot_manager_handle_command_line (int              argc,
-                                       char           **argv,
-                                       GDBusConnection *connection);
index d857331..cbe985b 100644 (file)
 
 #include <dlt/dlt.h>
 
+#include <common/la-handler-dbus.h>
 #include <common/nsm-consumer-dbus.h>
+#include <common/nsm-enum-types.h>
 #include <common/shutdown-consumer-dbus.h>
 
 #include <boot-manager/job-manager.h>
-#include <boot-manager/la-handler-dbus.h>
 #include <boot-manager/la-handler-service.h>
 
 
@@ -56,7 +57,7 @@ static void                  la_handler_service_set_property
 static gboolean              la_handler_service_handle_register                          (LAHandler             *interface,
                                                                                           GDBusMethodInvocation *invocation,
                                                                                           const gchar           *unit,
-                                                                                          const gchar           *mode,
+                                                                                          NSMShutdownType        mode,
                                                                                           guint                  timeout,
                                                                                           LAHandlerService      *service);
 static void                  la_handler_service_handle_register_finish                   (GObject               *object,
@@ -286,7 +287,7 @@ static gboolean
 la_handler_service_handle_register (LAHandler             *interface,
                                     GDBusMethodInvocation *invocation,
                                     const gchar           *unit,
-                                    const gchar           *mode,
+                                    NSMShutdownType        mode,
                                     guint                  timeout,
                                     LAHandlerService      *service)
 {
@@ -298,7 +299,6 @@ la_handler_service_handle_register (LAHandler             *interface,
   g_return_val_if_fail (IS_LA_HANDLER (interface), FALSE);
   g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), FALSE);
   g_return_val_if_fail (unit != NULL && *unit != '\0', FALSE);
-  g_return_val_if_fail (mode != NULL && *mode != '\0', FALSE);
   g_return_val_if_fail (LA_HANDLER_IS_SERVICE (service), FALSE);
 
   /* find out if this unit is already registered with a shutdown consumer */
@@ -327,9 +327,8 @@ la_handler_service_handle_register (LAHandler             *interface,
                                     service->connection, object_path, &error);
   if (error != NULL)
     {
-      log_text =
-        g_strdup_printf ("Failed to export shutdown consumer on the bus: %s",
-                         error->message);
+      log_text = g_strdup_printf ("Failed to export shutdown consumer on the bus: %s",
+                                  error->message);
       DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_text));
       g_free (log_text);
       g_error_free (error);
@@ -341,8 +340,8 @@ la_handler_service_handle_register (LAHandler             *interface,
 
   /* register the shutdown consumer with the NSM Consumer */
   nsm_consumer_call_register_shutdown_client (service->nsm_consumer,
-                                              "org.genivi.BootManager1", object_path, 0,
-                                              timeout, NULL,
+                                              "org.genivi.BootManager1", object_path,
+                                              mode, timeout, NULL,
                                               la_handler_service_handle_register_finish,
                                               invocation);
 
index e822313..312cb41 100644 (file)
@@ -21,7 +21,6 @@
 #include <dlt/dlt.h>
 
 #include <boot-manager/boot-manager-application.h>
-#include <boot-manager/boot-manager-command-line.h>
 #include <boot-manager/boot-manager-dbus.h>
 #include <boot-manager/boot-manager-service.h>
 #include <boot-manager/la-handler-service.h>
@@ -58,7 +57,6 @@ main (int    argc,
   JobManager             *job_manager;
   GMainLoop              *main_loop;
   GError                 *error = NULL;
-  gint                    exit_status;
 
   /* register the application and context in DLT */
   DLT_REGISTER_APP ("BMGR", "GENIVI Boot Manager");
@@ -87,15 +85,6 @@ main (int    argc,
       return EXIT_FAILURE;
     }
 
-  /* Parse and react to the command-line arguments instead of starting the application
-   * if any arguments are given */
-  if (argc > 1)
-    {
-      exit_status = boot_manager_handle_command_line (argc, argv, connection);
-      g_object_unref (connection);
-      return exit_status;
-    }
-
   /* attempt to connect to the systemd manager */
   systemd_manager =
     systemd_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
index e1bec8a..fd60db3 100644 (file)
@@ -3,11 +3,13 @@
 noinst_LTLIBRARIES = libcommon.la
 
 libcommon_la_built_headers =                                           \
+       la-handler-dbus.h                                               \
        nsm-consumer-dbus.h                                             \
        nsm-lifecycle-control-dbus.h                                    \
        shutdown-consumer-dbus.h
 
 libcommon_la_built_sources =                                           \
+       la-handler-dbus.c                                               \
        nsm-consumer-dbus.c                                             \
        nsm-lifecycle-control-dbus.c                                    \
        shutdown-consumer-dbus.c                                        \
@@ -39,6 +41,7 @@ libcommon_la_LIBADD =                                                 \
        $(SYSTEMD_DAEMON_LIBS)
 
 EXTRA_DIST =                                                           \
+       la-handler-dbus.xml                                             \
        nsm-consumer-dbus.xml                                           \
        nsm-lifecycle-control-dbus.xml                                  \
        shutdown-consumer-dbus.xml
@@ -49,26 +52,34 @@ DISTCLEANFILES =                                                    \
 BUILT_SOURCES =                                                                \
        $(libcommon_la_built_headers)
 
+la-handler-dbus.h: la-handler-dbus.xml Makefile
+       $(AM_V_GEN) $(GDBUS_CODEGEN)                                    \
+           --interface-prefix org.genivi                               \
+           --c-namespace ""                                            \
+           --generate-c-code la-handler-dbus                           \
+           --annotate org.genivi.BootManager1.LegacyAppHandler org.gtk.GDBus.C.Name \
+             LA_Handler $<
+
 nsm-consumer-dbus.h: nsm-consumer-dbus.xml Makefile
-       $(AM_V_GEN) $(GDBUS_CODEGEN)                                                    \
-           --interface-prefix com.contiautomotive.NodeStateManager                     \
-           --c-namespace ""                                                            \
-           --generate-c-code nsm-consumer-dbus                                         \
-           --annotate com.contiautomotive.NodeStateManager.Consumer org.gtk.GDBus.C.Name       \
-             NSM_Consumer $<
+       $(AM_V_GEN) $(GDBUS_CODEGEN)                                    \
+           --interface-prefix com.contiautomotive.NodeStateManager     \
+           --c-namespace ""                                            \
+           --generate-c-code nsm-consumer-dbus                         \
+           --annotate com.contiautomotive.NodeStateManager.Consumer    \
+             org.gtk.GDBus.C.Name NSM_Consumer $<
 
 nsm-lifecycle-control-dbus.h: nsm-lifecycle-control-dbus.xml Makefile
-       $(AM_V_GEN) $(GDBUS_CODEGEN)                                                    \
-           --interface-prefix com.contiautomotive.NodeStateManager                     \
-           --c-namespace ""                                                            \
-           --generate-c-code nsm-lifecycle-control-dbus                                \
-           --annotate com.contiautomotive.NodeStateManager.LifecycleControl org.gtk.GDBus.C.Name       \
-             NSM_Lifecycle_Control $<
+       $(AM_V_GEN) $(GDBUS_CODEGEN)                                    \
+           --interface-prefix com.contiautomotive.NodeStateManager     \
+           --c-namespace ""                                            \
+           --generate-c-code nsm-lifecycle-control-dbus                \
+           --annotate com.contiautomotive.NodeStateManager.LifecycleControl \
+             org.gtk.GDBus.C.Name NSM_Lifecycle_Control $<
 
 shutdown-consumer-dbus.h: shutdown-consumer-dbus.xml Makefile
        $(AM_V_GEN) $(GDBUS_CODEGEN)                                    \
            --interface-prefix org.genivi                               \
            --c-namespace ""                                            \
            --generate-c-code shutdown-consumer-dbus                    \
-           --annotate com.contiautomotive.NodeStateManager.LifeCycleConsumer org.gtk.GDBus.C.Name      \
-             Shutdown_Consumer $<
+           --annotate com.contiautomotive.NodeStateManager.LifeCycleConsumer \
+             org.gtk.GDBus.C.Name Shutdown_Consumer $<
similarity index 77%
rename from boot-manager/la-handler-dbus.xml
rename to common/la-handler-dbus.xml
index 6a4cd1a..4f78c17 100644 (file)
     <method name="Register">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg name="unit" type="s" direction="in"/>
-      <arg name="mode" type="s" direction="in"/>
+      <arg name="mode" type="i" direction="in"/>
       <arg name="timeout" type="u" direction="in"/>
     </method>
-
-    <!--
-      Deregister:
-      @unit: An application unit filename.
-
-      Removes the shutdown consumer for an app from the NSM.
-    -->
-    <method name="Deregister">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
-      <arg name="unit" type="s" direction="in"/>
-    </method>
   </interface>
 </node>
index a88b285..250216f 100644 (file)
@@ -138,6 +138,7 @@ Makefile
 common/Makefile
 boot-manager/busconf/Makefile
 boot-manager/Makefile
+legacy-app-handler/Makefile
 nsm-dummy/busconf/Makefile
 nsm-dummy/dbus/Makefile
 nsm-dummy/systemd/Makefile
diff --git a/legacy-app-handler/Makefile.am b/legacy-app-handler/Makefile.am
new file mode 100644 (file)
index 0000000..3fcadd2
--- /dev/null
@@ -0,0 +1,34 @@
+# vi:set ts=8 sw=8 noet ai nocindent:
+
+legacy_app_handlerdir =                                                        \
+       $(libdir)/boot-manager-$(BOOT_MANAGER_VERSION_API)
+
+legacy_app_handler_PROGRAMS =                                          \
+       legacy-app-handler
+
+legacy_app_handler_SOURCES =                                           \
+       main.c
+
+legacy_app_handler_CFLAGS =                                            \
+       -DG_LOG_DOMAIN=\"legacy-app-handler\"                           \
+       -I$(top_srcdir)                                                 \
+       $(DLT_CFLAGS)                                                   \
+       $(GIO_CFLAGS)                                                   \
+       $(GIO_UNIX_CFLAGS)                                              \
+       $(GLIB_CFLAGS)                                                  \
+       $(PLATFORM_CFLAGS)                                              \
+       $(PLATFORM_CPPFLAGS)
+
+legacy_app_handler_LDFLAGS =                                           \
+       -no-undefined                                                   \
+       $(PLATFORM_LDFLAGS)
+
+legacy_app_handler_DEPENDENCIES =                                      \
+       $(top_builddir)/common/libcommon.la
+
+legacy_app_handler_LDADD =                                             \
+       $(DLT_LIBS)                                                     \
+       $(GIO_LIBS)                                                     \
+       $(GIO_UNIX_LIBS)                                                \
+       $(GLIB_LIBS)                                                    \
+       $(top_builddir)/common/libcommon.la
diff --git a/legacy-app-handler/main.c b/legacy-app-handler/main.c
new file mode 100644 (file)
index 0000000..f986a0c
--- /dev/null
@@ -0,0 +1,223 @@
+/* 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 <common/la-handler-dbus.h>
+#include <common/nsm-enum-types.h>
+
+
+
+static gchar *unit = NULL;
+static gint   timeout = 0;
+static gchar *shutdown_mode = NULL;
+
+
+
+static GOptionEntry entries[] =
+{
+  { "unit", 'u', 0, G_OPTION_ARG_STRING, &unit, "Legacy application unit", NULL },
+  { "timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "Shutdown timeout in seconds", NULL },
+  { "shutdown-mode", 'm', 0, G_OPTION_ARG_STRING, &shutdown_mode, "Shutdown mode (none, normal, fast)", NULL },
+  { NULL },
+};
+
+
+
+DLT_DECLARE_CONTEXT (la_handler_context);
+
+
+
+static void
+unregister_dlt (void)
+{
+  DLT_UNREGISTER_CONTEXT (la_handler_context);
+  DLT_UNREGISTER_APP ();
+}
+
+
+
+static gboolean
+translate_shutdown_mode (const gchar     *str,
+                         NSMShutdownType *mode)
+{
+  g_return_val_if_fail (mode != NULL, FALSE);
+
+  /* try parsing the shutdown mode option into the NSMShutdownType enum */
+  if (g_strcmp0 (str, "none") == 0)
+    {
+      *mode = NSM_SHUTDOWN_TYPE_NOT;
+      return TRUE;
+    }
+  else if (g_strcmp0 (str, "normal") == 0)
+    {
+      *mode = NSM_SHUTDOWN_TYPE_NORMAL;
+      return TRUE;
+    }
+  else if (g_strcmp0 (str, "fast") == 0)
+    {
+      *mode = NSM_SHUTDOWN_TYPE_FAST;
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+
+
+int
+main (int    argc,
+      char **argv)
+{
+  GOptionContext *context;
+  NSMShutdownType real_shutdown_mode;
+  LAHandler      *service;
+  GError         *error = NULL;
+  gchar          *msg;
+
+  /* register the application and context with the DLT */
+  DLT_REGISTER_APP ("BMGR", "GENIVI Boot Manager");
+  DLT_REGISTER_CONTEXT (la_handler_context, "LAH", "Legacy Application Handler");
+
+  /* make sure to unregister the DLT at exit */
+  atexit (unregister_dlt);
+
+  /* initialize the GType type system */
+  g_type_init ();
+
+  /* prepare command line option parsing */
+  context = g_option_context_new (NULL);
+  g_option_context_set_help_enabled (context, TRUE);
+  g_option_context_add_main_entries (context, entries, NULL);
+
+  /* try to parse command line options */
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    {
+      /* parsing failed, exit with an error */
+      msg = g_strdup_printf ("Failed to parse command line options: %s\n",
+                             error->message);
+      DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (msg));
+      g_free (msg);
+
+      /* clean up */
+      g_option_context_free (context);
+      g_error_free (error);
+      g_free (unit);
+      g_free (shutdown_mode);
+
+      return EXIT_FAILURE;
+    }
+  g_option_context_free (context);
+
+  /* abort if no unit file was specified */
+  if (unit == NULL || *unit == '\0')
+    {
+      DLT_LOG (la_handler_context, DLT_LOG_ERROR,
+               DLT_STRING ("Failed to register legacy application: no unit specified"));
+
+      /* free command line options */
+      g_free (unit);
+      g_free (shutdown_mode);
+
+      return EXIT_FAILURE;
+    }
+
+  /* validate the shutdown mode */
+  if (!translate_shutdown_mode (shutdown_mode, &real_shutdown_mode))
+    {
+      msg = g_strdup_printf ("Failed to register legacy application: "
+                             "invalid shutdown mode \"%s\"", shutdown_mode);
+      DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (msg));
+      g_free (msg);
+
+      /* free command line options */
+      g_free (unit);
+      g_free (shutdown_mode);
+
+      return EXIT_FAILURE;
+    }
+
+  /* validate the timeout */
+  if (timeout < 0)
+    {
+      DLT_LOG (la_handler_context, DLT_LOG_ERROR,
+               DLT_STRING ("Failed to register legacy application: "
+                           "shutdown timeout must be non-negative"));
+
+      /* free command line options */
+      g_free (unit);
+      g_free (shutdown_mode);
+
+      return EXIT_FAILURE;
+    }
+
+  /* create a proxy to talk to the legacy app handler D-Bus service */
+  service =
+    la_handler_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                       G_DBUS_PROXY_FLAGS_NONE,
+                                       "org.genivi.BootManager1",
+                                       "/org/genivi/BootManager1/LegacyAppHandler",
+                                       NULL, &error);
+
+  /* abort if the proxy could not be created */
+  if (service == NULL)
+    {
+      msg = g_strdup_printf ("Failed to register legacy application: %s", error->message);
+      DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (msg));
+      g_free (msg);
+
+      /* clean up */
+      g_error_free (error);
+
+      /* free command line options */
+      g_free (unit);
+      g_free (shutdown_mode);
+
+      return EXIT_FAILURE;
+    }
+
+  /* forward the register request to the legacy app handler D-Bus service */
+  if (!la_handler_call_register_sync (service, unit, real_shutdown_mode, timeout,
+                                      NULL, &error))
+    {
+      msg = g_strdup_printf ("Failed to register legacy application: %s", error->message);
+      DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (msg));
+      g_free (msg);
+
+      /* clean up */
+      g_error_free (error);
+      g_object_unref (service);
+
+      /* free command line options */
+      g_free (unit);
+      g_free (shutdown_mode);
+
+      return EXIT_FAILURE;
+    }
+
+  /* release the legacy app handler proxy */
+  g_object_unref (service);
+
+  /* free command line options */
+  g_free (unit);
+  g_free (shutdown_mode);
+
+  return EXIT_SUCCESS;
+}
index 2761b56..273e42a 100644 (file)
@@ -6,43 +6,43 @@ SUBDIRS =                                                             \
        systemd
 
 nsm_dummydir =                                                         \
-       $(libdir)/nsm-dummy-$(BOOT_MANAGER_VERSION_API)
+       $(libdir)/boot-manager-$(BOOT_MANAGER_VERSION_API)
 
-nsm_dummy_PROGRAMS =                                                                   \
+nsm_dummy_PROGRAMS =                                                   \
        nsm-dummy
 
-nsm_dummy_SOURCES =                                                                    \
-        nsm-consumer-service.c                                                         \
-        nsm-consumer-service.h                                                         \
-        nsm-dummy-application.c                                                        \
-        nsm-dummy-application.h                                                        \
-        nsm-lifecycle-control-service.c                                                        \
-        nsm-lifecycle-control-service.h                                                        \
+nsm_dummy_SOURCES =                                                    \
+        nsm-consumer-service.c                                         \
+        nsm-consumer-service.h                                         \
+        nsm-dummy-application.c                                                \
+        nsm-dummy-application.h                                                \
+        nsm-lifecycle-control-service.c                                        \
+        nsm-lifecycle-control-service.h                                        \
        main.c
 
-nsm_dummy_CFLAGS =                                                                     \
-       -DG_LOG_DOMAIN=\"nsm-dummy\"                                                    \
-       -I$(top_srcdir)                                                                 \
-       $(DLT_CFLAGS)                                                                   \
-       $(GIO_CFLAGS)                                                                   \
-       $(GIO_UNIX_CFLAGS)                                                              \
-       $(GLIB_CFLAGS)                                                                  \
-       $(PLATFORM_CFLAGS)                                                              \
-       $(PLATFORM_CPPFLAGS)                                                            \
+nsm_dummy_CFLAGS =                                                     \
+       -DG_LOG_DOMAIN=\"nsm-dummy\"                                    \
+       -I$(top_srcdir)                                                 \
+       $(DLT_CFLAGS)                                                   \
+       $(GIO_CFLAGS)                                                   \
+       $(GIO_UNIX_CFLAGS)                                              \
+       $(GLIB_CFLAGS)                                                  \
+       $(PLATFORM_CFLAGS)                                              \
+       $(PLATFORM_CPPFLAGS)                                            \
        $(SYSTEMD_DAEMON_CFLAGS)
 
-nsm_dummy_LDFLAGS =                                                                    \
-       -no-undefined                                                                   \
+nsm_dummy_LDFLAGS =                                                    \
+       -no-undefined                                                   \
        $(PLATFORM_LDFLAGS)
 
-nsm_dummy_DEPENDENCIES =                                                               \
+nsm_dummy_DEPENDENCIES =                                               \
        $(top_builddir)/common/libcommon.la
 
-nsm_dummy_LDADD =                                                                      \
-       $(DLT_LIBS)                                                                     \
-       $(GIO_LIBS)                                                                     \
-       $(GIO_UNIX_LIBS)                                                                \
-       $(GLIB_LIBS)                                                                    \
-       $(SYSTEMD_DAEMON_LIBS)                                                          \
+nsm_dummy_LDADD =                                                      \
+       $(DLT_LIBS)                                                     \
+       $(GIO_LIBS)                                                     \
+       $(GIO_UNIX_LIBS)                                                \
+       $(GLIB_LIBS)                                                    \
+       $(SYSTEMD_DAEMON_LIBS)                                          \
        $(top_builddir)/common/libcommon.la
 
index 6aac825..ff6f42d 100644 (file)
@@ -1,4 +1,4 @@
 [D-BUS Service]
 Name=com.contiautomotive.NodeStateManager
 SystemdService = nsm-dummy.service
-Exec=@libdir@/nsm-dummy-@BOOT_MANAGER_VERSION_API@/nsm-dummy
+Exec=@libdir@/boot-manager-@BOOT_MANAGER_VERSION_API@/nsm-dummy
index 6aac825..ff6f42d 100644 (file)
@@ -1,4 +1,4 @@
 [D-BUS Service]
 Name=com.contiautomotive.NodeStateManager
 SystemdService = nsm-dummy.service
-Exec=@libdir@/nsm-dummy-@BOOT_MANAGER_VERSION_API@/nsm-dummy
+Exec=@libdir@/boot-manager-@BOOT_MANAGER_VERSION_API@/nsm-dummy
index 206dae5..661db79 100644 (file)
@@ -1,4 +1,4 @@
 [Service]
 Type = dbus
 BusName = com.contiautomotive.NodeStateManager
-ExecStart = @libdir@/nsm-dummy-@BOOT_MANAGER_VERSION_API@/nsm-dummy
+ExecStart = @libdir@/boot-manager-@BOOT_MANAGER_VERSION_API@/nsm-dummy
index 9c75bbd..15b21e0 100644 (file)
@@ -1,21 +1,21 @@
 # vi:set ts=8 sw=8 noet ai nocindent:
 
-testscriptdir = /usr/bin
+testscriptdir = $(libdir)/boot-manager-$(BOOT_MANAGER_VERSION_API)
 
 testscript_DATA =                                                      \
-       org-genivi-LegacyAppHandler1-test-service.py
+       legacy-app-handler-test
 
-testconfdir = /etc/dbus-1/system.d
+testconfdir = $(sysconfdir)/dbus-1/system.d
 
 testconf_DATA =                                                                \
-       org.genivi.LegacyAppHandler1.test.conf
+       legacy-app-handler-test.conf
 
-servicedir = /lib/systemd/system
+servicedir = $(libdir)/systemd/system
 
 service_in_files =                                                     \
-       org.genivi.LegacyAppHandler1.test1.service.in                           \
-       org.genivi.LegacyAppHandler1.test2.service.in                           \
-       org.genivi.LegacyAppHandler1.test3.service.in
+       legacy-app-handler-test1.service.in                             \
+       legacy-app-handler-test2.service.in                             \
+       legacy-app-handler-test3.service.in
 
 service_DATA = $(service_in_files:.service.in=.service)
 
@@ -24,9 +24,7 @@ service_DATA = $(service_in_files:.service.in=.service)
            -e "s,\@BOOT_MANAGER_VERSION_API\@,$(BOOT_MANAGER_VERSION_API),g" < $< > $@
 
 CLEANFILES =                                                           \
-       $(service_DATA)                                                 \
-       $(testconf_DATA)                                                \
-       $(testscript_DATA)
+       $(service_DATA)
 
 EXTRA_DIST =                                                           \
        $(service_in_files)                                             \
diff --git a/tests/legacy-app-handler/legacy-app-handler-test b/tests/legacy-app-handler/legacy-app-handler-test
new file mode 100755 (executable)
index 0000000..875b9d3
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+
+import gobject
+import dbus
+import dbus.service
+import sys
+
+from dbus.mainloop.glib import DBusGMainLoop
+
+
+class TestService(dbus.service.Object):
+
+    def __init__(self, name):
+        bus_name = dbus.service.BusName(
+            'org.genivi.BootManager1.LegacyAppHandler.%s' % name,
+            bus=dbus.SystemBus())
+        object_path = '/org/genivi/BootManager1/LegacyAppHandler/%s' % name
+        dbus.service.Object.__init__(self, bus_name, object_path)
+
+    @dbus.service.method('org.genivi.BootManager1.LegacyAppHandler.Test')
+    def hello(self):
+        return "Hello World!"
+
+
+if __name__ == '__main__':
+    DBusGMainLoop(set_as_default=True)
+    service = TestService(sys.argv[1])
+    loop = gobject.MainLoop()
+    loop.run()
diff --git a/tests/legacy-app-handler/legacy-app-handler-test1.service.in b/tests/legacy-app-handler/legacy-app-handler-test1.service.in
new file mode 100644 (file)
index 0000000..2f95bc8
--- /dev/null
@@ -0,0 +1,4 @@
+[Service]
+ExecStart = @libdir@/boot-manager-@BOOT_MANAGER_VERSION_API@/legacy-app-handler-test Test1
+ExecStartPost = @libdir@/boot-manager-@BOOT_MANAGER_VERSION_API@/legacy-app-handler \
+                --register --unit=legacy-app-handler-test1.service
diff --git a/tests/legacy-app-handler/legacy-app-handler-test2.service.in b/tests/legacy-app-handler/legacy-app-handler-test2.service.in
new file mode 100644 (file)
index 0000000..916e303
--- /dev/null
@@ -0,0 +1,4 @@
+[Service]
+ExecStart = @libdir@/boot-manager-@BOOT_MANAGER_VERSION_API@/legacy-app-handler-test Test2
+ExecStartPost = @libdir@/boot-manager-@BOOT_MANAGER_VERSION_API@/legacy-app-handler \
+                --register --unit=legacy-app-handler-test2.service
diff --git a/tests/legacy-app-handler/legacy-app-handler-test3.service.in b/tests/legacy-app-handler/legacy-app-handler-test3.service.in
new file mode 100644 (file)
index 0000000..27ea68a
--- /dev/null
@@ -0,0 +1,4 @@
+[Service]
+ExecStart = @libdir@/boot-manager-@BOOT_MANAGER_VERSION_API@/legacy-app-handler-test Test3
+ExecStartPost = @libdir@/boot-manager-@BOOT_MANAGER_VERSION_API@/legacy-app-handler \
+                --register --unit=legacy-app-handler-test3.service
diff --git a/tests/legacy-app-handler/org-genivi-LegacyAppHandler1-test-service.py b/tests/legacy-app-handler/org-genivi-LegacyAppHandler1-test-service.py
deleted file mode 100755 (executable)
index 40ac1df..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/python
-import gobject
-import dbus
-import dbus.service
-import sys
-from dbus.mainloop.glib import DBusGMainLoop
-
-class TestService (dbus.service.Object):
-       def __init__(self):
-               bus_name = dbus.service.BusName(sys.argv[1], bus=dbus.SystemBus())
-               dbus.service.Object.__init__(self, bus_name, '/org/genivi/LegacyAppHandler1/test1')
-
-       @dbus.service.method('org.genivi.LegacyAppHandler1.test1')
-       def hello(self):
-               return "Hello World!"
-
-DBusGMainLoop(set_as_default=True)
-myservice = TestService()
-loop = gobject.MainLoop()
-loop.run()
diff --git a/tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test1.service.in b/tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test1.service.in
deleted file mode 100644 (file)
index 515c213..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-[Service]
-ExecStart = /usr/bin/python /usr/bin/org-genivi-LegacyAppHandler1-test-service.py \
-            org.genivi.LegacyAppHandler1.test1
-ExecStartPost = @libdir@/legacy-app-handler-@BOOT_MANAGER_VERSION_API@/legacy-app-handler \
-                --register --unit="org.genivi.LegacyAppHandler1.test1.service"
diff --git a/tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test2.service.in b/tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test2.service.in
deleted file mode 100644 (file)
index 92f8e1c..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-[Service]
-ExecStart = /usr/bin/python /usr/bin/org-genivi-LegacyAppHandler1-test-service.py \
-            org.genivi.LegacyAppHandler1.test2
-ExecStartPost = @libdir@/legacy-app-handler-@BOOT_MANAGER_VERSION_API@/legacy-app-handler \
-                --register --unit="org.genivi.LegacyAppHandler1.test2.service"
diff --git a/tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test3.service.in b/tests/legacy-app-handler/org.genivi.LegacyAppHandler1.test3.service.in
deleted file mode 100644 (file)
index 463b6e5..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-[Service]
-ExecStart = /usr/bin/python /usr/bin/org-genivi-LegacyAppHandler1-test-service.py \
-            org.genivi.LegacyAppHandler1.test3
-ExecStartPost = @libdir@/legacy-app-handler-@BOOT_MANAGER_VERSION_API@/legacy-app-handler \
-                --register --unit="org.genivi.LegacyAppHandler1.test3.service"