Link LUCHandler and LUCStarter. Parse prioritised LUC types
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Mon, 18 Jun 2012 10:04:44 +0000 (11:04 +0100)
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Tue, 19 Jun 2012 13:40:53 +0000 (14:40 +0100)
Makefile.am
boot-manager/Makefile.am
boot-manager/boot-manager-application.c
boot-manager/boot-manager-application.h
boot-manager/luc-starter.c
boot-manager/luc-starter.h
boot-manager/main.c

index 8a574ab..95c7abb 100644 (file)
@@ -1,9 +1,9 @@
 # vi:set ts=8 sw=8 noet ai nocindent:
 
 SUBDIRS =                                                              \
+       luc-handler                                                     \
        boot-manager                                                    \
        legacy-app-handler                                              \
-       luc-handler                                                     \
        tests
 
 .PHONY: ChangeLog
index b65be32..2e619e1 100644 (file)
@@ -18,6 +18,8 @@ boot_manager_built_sources =                                          \
 boot_manager_SOURCES =                                                 \
        ../common/watchdog-client.c                                     \
        ../common/watchdog-client.h                                     \
+       ../luc-handler/luc-handler-dbus.c                               \
+       ../luc-handler/luc-handler-dbus.h                               \
        boot-manager-application.c                                      \
        boot-manager-application.h                                      \
        boot-manager-service.c                                          \
index c5f3c3b..f64d6f1 100644 (file)
@@ -20,6 +20,7 @@
 #include <boot-manager/boot-manager-application.h>
 #include <boot-manager/boot-manager-service.h>
 #include <boot-manager/luc-starter.h>
+#include <luc-handler/luc-handler-dbus.h>
 
 
 
@@ -28,6 +29,7 @@ enum
 {
   PROP_0,
   PROP_BOOT_MANAGER,
+  PROP_LUC_HANDLER,
   PROP_LUC_STARTER,
 };
 
@@ -64,6 +66,7 @@ struct _BootManagerApplication
   BootManagerService *boot_manager;
 
   /* LUC starter to restore the LUC */
+  LUCHandler         *luc_handler;
   LUCStarter         *luc_starter;
 };
 
@@ -98,6 +101,17 @@ boot_manager_application_class_init (BootManagerApplicationClass *klass)
                                                         G_PARAM_CONSTRUCT_ONLY |
                                                         G_PARAM_STATIC_STRINGS));
 
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_LUC_HANDLER,
+                                   g_param_spec_object ("luc-handler",
+                                                        "luc-handler",
+                                                        "luc-handler",
+                                                        TYPE_LUC_HANDLER,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_property (gobject_class,
                                    PROP_LUC_STARTER,
                                    g_param_spec_object ("luc-starter",
@@ -127,6 +141,10 @@ boot_manager_application_finalize (GObject *object)
   /* release the watchdog client */
   g_object_unref (application->watchdog_client);
 
+  /* release the LUC handler/starter */
+  g_object_unref (application->luc_handler);
+  g_object_unref (application->luc_starter);
+
   /* release the boot manager implementation */
   if (application->boot_manager != NULL)
     g_object_unref (application->boot_manager);
@@ -141,8 +159,9 @@ boot_manager_application_constructed (GObject *object)
 {
   BootManagerApplication *application = BOOT_MANAGER_APPLICATION (object);
 
-  /* create the LUC starter */
-  application->luc_starter = luc_starter_new (application->boot_manager);
+  /* instantiate the LUC starter */
+  application->luc_starter = luc_starter_new (application->boot_manager,
+                                              application->luc_handler);
 }
 
 
@@ -160,6 +179,9 @@ boot_manager_application_get_property (GObject    *object,
     case PROP_BOOT_MANAGER:
       g_value_set_object (value, application->boot_manager);
       break;
+    case PROP_LUC_HANDLER:
+      g_value_set_object (value, application->luc_handler);
+      break;
     case PROP_LUC_STARTER:
       g_value_set_object (value, application->luc_starter);
       break;
@@ -184,6 +206,9 @@ boot_manager_application_set_property (GObject      *object,
     case PROP_BOOT_MANAGER:
       application->boot_manager = g_value_dup_object (value);
       break;
+    case PROP_LUC_HANDLER:
+      application->luc_handler = g_value_dup_object (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -207,13 +232,16 @@ boot_manager_application_startup (GApplication *app)
 
 
 BootManagerApplication *
-boot_manager_application_new (BootManagerService *boot_manager)
+boot_manager_application_new (BootManagerService *boot_manager,
+                              LUCHandler         *luc_handler)
 {
   g_return_val_if_fail (BOOT_MANAGER_IS_SERVICE (boot_manager), NULL);
+  g_return_val_if_fail (IS_LUC_HANDLER (luc_handler), NULL);
 
   return g_object_new (BOOT_MANAGER_TYPE_APPLICATION,
                        "application-id", "org.genivi.BootManager1",
                        "flags", G_APPLICATION_IS_SERVICE,
                        "boot-manager", boot_manager,
+                       "luc-handler", luc_handler,
                        NULL);
 }
index 5fd3639..c5fcbf4 100644 (file)
@@ -10,6 +10,7 @@
 #ifndef __BOOT_MANAGER_APPLICATION_H__
 #define __BOOT_MANAGER_APPLICATION_H__
 
+#include <luc-handler/luc-handler-dbus.h>
 #include <boot-manager/boot-manager-service.h>
 
 G_BEGIN_DECLS
@@ -26,7 +27,8 @@ typedef struct _BootManagerApplication      BootManagerApplication;
 
 GType                          boot_manager_application_get_type (void) G_GNUC_CONST;
 
-BootManagerApplication *boot_manager_application_new      (BootManagerService *service) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+BootManagerApplication *boot_manager_application_new      (BootManagerService *service,
+                                                           LUCHandler         *luc_handler) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 
 G_END_DECLS
 
index fd6df9a..0ebb16d 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <boot-manager/boot-manager-service.h>
 #include <boot-manager/luc-starter.h>
+#include <luc-handler/luc-handler-dbus.h>
 
 
 
@@ -24,10 +25,12 @@ enum
 {
   PROP_0,
   PROP_BOOT_MANAGER,
+  PROP_LUC_HANDLER,
 };
 
 
 
+static void luc_starter_constructed  (GObject      *object);
 static void luc_starter_finalize     (GObject      *object);
 static void luc_starter_get_property (GObject      *object,
                                       guint         prop_id,
@@ -50,6 +53,9 @@ struct _LUCStarter
   GObject             __parent__;
 
   BootManagerService *boot_manager;
+  LUCHandler         *luc_handler;
+
+  gchar             **prioritised_types;
 };
 
 
@@ -64,6 +70,7 @@ luc_starter_class_init (LUCStarterClass *klass)
   GObjectClass *gobject_class;
 
   gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->constructed = luc_starter_constructed;
   gobject_class->finalize = luc_starter_finalize;
   gobject_class->get_property = luc_starter_get_property;
   gobject_class->set_property = luc_starter_set_property;
@@ -77,13 +84,34 @@ luc_starter_class_init (LUCStarterClass *klass)
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT_ONLY |
                                                         G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_LUC_HANDLER,
+                                   g_param_spec_object ("luc-handler",
+                                                        "luc-handler",
+                                                        "luc-handler",
+                                                        TYPE_LUC_HANDLER,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS));
+}
+
+
+
+static void
+luc_starter_init (LUCStarter *starter)
+{
 }
 
 
 
 static void
-luc_starter_init (LUCStarter *service)
+luc_starter_constructed (GObject *object)
 {
+  LUCStarter *starter = LUC_STARTER (object);
+
+  /* parse the prioritised LUC types defined at build-time */
+  starter->prioritised_types = g_strsplit (PRIORITISED_LUC_TYPES, ",", -1);
 }
 
 
@@ -91,10 +119,16 @@ luc_starter_init (LUCStarter *service)
 static void
 luc_starter_finalize (GObject *object)
 {
-  LUCStarter *service = LUC_STARTER (object);
+  LUCStarter *starter = LUC_STARTER (object);
+
+  /* free the prioritised types array */
+  g_strfreev (starter->prioritised_types);
 
   /* release the boot manager */
-  g_object_unref (service->boot_manager);
+  g_object_unref (starter->boot_manager);
+
+  /* release the LUC handler */
+  g_object_unref (starter->luc_handler);
 
   (*G_OBJECT_CLASS (luc_starter_parent_class)->finalize) (object);
 }
@@ -107,12 +141,15 @@ luc_starter_get_property (GObject    *object,
                           GValue     *value,
                           GParamSpec *pspec)
 {
-  LUCStarter *service = LUC_STARTER (object);
+  LUCStarter *starter = LUC_STARTER (object);
 
   switch (prop_id)
     {
     case PROP_BOOT_MANAGER:
-      g_value_set_object (value, service->boot_manager);
+      g_value_set_object (value, starter->boot_manager);
+      break;
+    case PROP_LUC_HANDLER:
+      g_value_set_object (value, starter->luc_handler);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -128,12 +165,15 @@ luc_starter_set_property (GObject      *object,
                           const GValue *value,
                           GParamSpec   *pspec)
 {
-  LUCStarter *service = LUC_STARTER (object);
+  LUCStarter *starter = LUC_STARTER (object);
 
   switch (prop_id)
     {
     case PROP_BOOT_MANAGER:
-      service->boot_manager = g_value_dup_object (value);
+      starter->boot_manager = g_value_dup_object (value);
+      break;
+    case PROP_LUC_HANDLER:
+      starter->luc_handler = g_value_dup_object (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -144,10 +184,16 @@ luc_starter_set_property (GObject      *object,
 
 
 LUCStarter *
-luc_starter_new (BootManagerService *boot_manager)
+luc_starter_new (BootManagerService *boot_manager,
+                 LUCHandler         *luc_handler)
 {
   g_return_val_if_fail (BOOT_MANAGER_IS_SERVICE (boot_manager), NULL);
-  return g_object_new (TYPE_LUC_STARTER, "boot-manager", boot_manager, NULL);
+  g_return_val_if_fail (IS_LUC_HANDLER (luc_handler), NULL);
+
+  return g_object_new (TYPE_LUC_STARTER,
+                       "boot-manager", boot_manager,
+                       "luc-handler", luc_handler,
+                       NULL);
 }
 
 
@@ -155,5 +201,10 @@ luc_starter_new (BootManagerService *boot_manager)
 void
 luc_starter_start_groups (LUCStarter *starter)
 {
-  g_debug ("restore LUC if desired");
+  guint n;
+
+  g_debug ("start LUC types in the following order:");
+
+  for (n = 0; starter->prioritised_types[n] != NULL; n++)
+    g_debug ("  %s",  starter->prioritised_types[n]);
 }
index 4b1c8ad..7645dbe 100644 (file)
@@ -11,6 +11,7 @@
 #define __LUC_STARTER_H__
 
 #include <boot-manager/boot-manager-service.h>
+#include <luc-handler/luc-handler-dbus.h>
 
 G_BEGIN_DECLS
 
@@ -26,7 +27,8 @@ typedef struct _LUCStarter      LUCStarter;
 
 GType       luc_starter_get_type     (void) G_GNUC_CONST;
 
-LUCStarter *luc_starter_new          (BootManagerService *boot_manager) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+LUCStarter *luc_starter_new          (BootManagerService *boot_manager,
+                                      LUCHandler         *luc_handler) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 void        luc_starter_start_groups (LUCStarter         *starter);
 
 G_END_DECLS
index b366c64..723d23c 100644 (file)
@@ -32,6 +32,7 @@ main (int    argc,
   BootManagerService     *service;
   GDBusConnection        *connection;
   SystemdManager         *systemd_manager;
+  LUCHandler             *luc_handler;
   GError                 *error = NULL;
   gint                    exit_status = EXIT_SUCCESS;
 
@@ -80,7 +81,26 @@ main (int    argc,
       return EXIT_FAILURE;
     }
 
-  /* instantiate the BootManager service implementation */
+  /* attempt to connect to the LUC handler */
+  luc_handler =
+    luc_handler_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+                                        G_DBUS_PROXY_FLAGS_NONE,
+                                        "org.freedesktop.LUCHandler1",
+                                        "/org/freedesktop/LUCHandler1",
+                                        NULL, &error);
+  if (luc_handler == NULL)
+    {
+      g_warning ("Failed to connect to the LUC handler: %s", error->message);
+
+      /* clean up */
+      g_error_free (error);
+      g_object_unref (systemd_manager);
+      g_object_unref (connection);
+
+      return EXIT_FAILURE;
+    }
+
+  /* instantiate the boot manager service implementation */
   service = boot_manager_service_new (connection, systemd_manager);
   if (!boot_manager_service_start_up (service, &error))
     {
@@ -96,7 +116,7 @@ main (int    argc,
     }
 
   /* create and run the main application */
-  application = boot_manager_application_new (service);
+  application = boot_manager_application_new (service, luc_handler);
   exit_status = g_application_run (G_APPLICATION (application), 0, NULL);
   g_object_unref (application);