+ ShutdownConsumer *consumer;
+ GError *error = NULL;
+ gchar *log_text;
+ gchar *object_path;
+
+ 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 */
+ if (g_hash_table_lookup (service->units_to_consumers, unit))
+ {
+ /* there already is a shutdown consumer for the unit, so ignore this request */
+ la_handler_complete_register (interface, invocation);
+ return TRUE;
+ }
+
+ /* create a new ShutdownConsumer and implement its LifecycleRequest method */
+ consumer = shutdown_consumer_skeleton_new ();
+ g_signal_connect (consumer, "handle-lifecycle-request",
+ G_CALLBACK (la_handler_service_handle_consumer_lifecycle_request),
+ service);
+
+ /* associate the shutdown consumer with the unit name */
+ g_hash_table_insert (service->units_to_consumers, g_strdup (unit),
+ g_object_ref (consumer));
+ g_hash_table_insert (service->consumers_to_units, g_object_ref (consumer),
+ g_strdup (unit));
+
+ /* export the shutdown consumer on the bus */
+ object_path = g_strdup_printf ("%s/%u", service->prefix, service->index);
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (consumer),
+ service->connection, object_path, &error);
+ if (error != NULL)
+ {
+ 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);
+ }
+
+ /* temporarily store a reference to the LAHandlerService in the invocation object */
+ g_object_set_data_full (G_OBJECT (invocation), "la-handler-service",
+ g_object_ref (service), (GDestroyNotify) g_object_unref);
+
+ /* 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,
+ la_handler_service_handle_register_finish,
+ invocation);
+
+ g_free (object_path);
+
+ /* increment the counter for our shutdown consumer object paths */
+ service->index++;