From bdc7aa66fc88d1ebbe4e8b910845fec053e76f8f Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann Date: Thu, 26 Jul 2012 13:39:11 +0100 Subject: [PATCH] Move deregistration of shutdown consumers into LAHandlerService LAHandlerService is a better place for this functionalit than BootManagerApplication. Apart from this deregistration, anything related to legacy app shutdown consumers is already handled solely by the LAHandlerService anyway, so it makes sense to move the deregistration there as well. --- boot-manager/boot-manager-application.c | 54 +-------------------- boot-manager/la-handler-service.c | 83 ++++++++++++++++++++++++--------- boot-manager/la-handler-service.h | 28 +++++------ 3 files changed, 76 insertions(+), 89 deletions(-) diff --git a/boot-manager/boot-manager-application.c b/boot-manager/boot-manager-application.c index 1b253fa..e8ee9f0 100644 --- a/boot-manager/boot-manager-application.c +++ b/boot-manager/boot-manager-application.c @@ -54,7 +54,6 @@ enum static void boot_manager_application_finalize (GObject *object); static void boot_manager_application_constructed (GObject *object); -static void boot_manager_application_deregister_consumers (BootManagerApplication *application); static void boot_manager_application_get_property (GObject *object, guint prop_id, GValue *value, @@ -332,7 +331,7 @@ boot_manager_application_handle_lifecycle_request (ShutdownConsumer *consu luc_starter_cancel (application->luc_starter); /* deregister the shutdown consumers */ - boot_manager_application_deregister_consumers (application); + la_handler_service_deregister_consumers (application->la_handler); /* let the NSM know that we have handled the lifecycle request */ shutdown_consumer_complete_lifecycle_request (consumer, invocation, @@ -345,57 +344,6 @@ boot_manager_application_handle_lifecycle_request (ShutdownConsumer *consu static void -boot_manager_application_deregister_consumers (BootManagerApplication * application) -{ - NSMConsumer *nsm_consumer = NULL; - const gchar *bus_name; - const gchar *object_path; - GError *error = NULL; - GList *consumers = NULL; - gchar *log_text; - gint error_code; - gint shutdown_mode; - - g_return_if_fail (BOOT_MANAGER_IS_APPLICATION (application)); - - /* get the nsm consumer interface */ - nsm_consumer = la_handler_service_get_nsm_consumer (application->la_handler); - - /* get the list of shutdown consumer and deregister one by one */ - for (consumers = la_handler_service_get_clients (application->la_handler); - consumers != NULL; - consumers = consumers->next) - { - /* call NSM deregister method */ - bus_name = shutdown_client_get_bus_name (consumers->data); - object_path = shutdown_client_get_object_path (consumers->data); - shutdown_mode = shutdown_client_get_shutdown_mode (consumers->data); - nsm_consumer_call_un_register_shutdown_client_sync (nsm_consumer, bus_name, - object_path, shutdown_mode, - &error_code, NULL, &error); - - /* check if deregister method fails */ - if (error != NULL) - { - log_text = g_strdup_printf ("Failed to deregister the consumer: %s", - error->message); - DLT_LOG (boot_manager_context, DLT_LOG_ERROR, DLT_STRING (log_text)); - g_free (log_text); - g_error_free (error); - } - } - - /* release the list of consumers */ - g_object_unref (consumers); - - /* release the nsm consumer interface */ - if (nsm_consumer != NULL) - g_object_unref (nsm_consumer); -} - - - -static void boot_manager_application_get_property (GObject *object, guint prop_id, GValue *value, diff --git a/boot-manager/la-handler-service.c b/boot-manager/la-handler-service.c index eb96858..5c89db1 100644 --- a/boot-manager/la-handler-service.c +++ b/boot-manager/la-handler-service.c @@ -236,28 +236,6 @@ la_handler_service_finalize (GObject *object) -GList* -la_handler_service_get_clients (LAHandlerService *service) -{ - g_return_val_if_fail (LA_HANDLER_IS_SERVICE (service), NULL); - - /* return the client's list from clients_to_units */ - return g_hash_table_get_keys (service->clients_to_units); -} - - - -NSMConsumer* -la_handler_service_get_nsm_consumer (LAHandlerService *service) -{ - g_return_val_if_fail (LA_HANDLER_IS_SERVICE (service), NULL); - - /* return the conection with NSM consumer interface */ - return service->nsm_consumer; -} - - - static void la_handler_service_get_property (GObject *object, guint prop_id, @@ -614,3 +592,64 @@ la_handler_service_start (LAHandlerService *service, "/org/genivi/BootManager1/LegacyAppHandler", error); } + + + +NSMConsumer * +la_handler_service_get_nsm_consumer (LAHandlerService *service) +{ + g_return_val_if_fail (LA_HANDLER_IS_SERVICE (service), NULL); + + return service->nsm_consumer; +} + + + +void +la_handler_service_deregister_consumers (LAHandlerService *service) +{ + GHashTableIter iter; + ShutdownClient *client; + const gchar *bus_name; + const gchar *object_path; + const gchar *unit; + GError *error = NULL; + gchar *log_text; + gint error_code; + gint shutdown_mode; + + g_return_if_fail (LA_HANDLER_IS_SERVICE (service)); + + g_hash_table_iter_init (&iter, service->clients_to_units); + while (g_hash_table_iter_next (&iter, (gpointer *)&client, (gpointer *)&unit)) + { + /* extract data from the current client */ + bus_name = shutdown_client_get_bus_name (client); + object_path = shutdown_client_get_object_path (client); + shutdown_mode = shutdown_client_get_shutdown_mode (client); + + /* unregister the shutdown client */ + nsm_consumer_call_un_register_shutdown_client_sync (service->nsm_consumer, + bus_name, object_path, + shutdown_mode, &error_code, + NULL, &error); + + if (error != NULL) + { + log_text = g_strdup_printf ("Failed to unregister shutdown client %s " + "for unit %s: %s", object_path, unit, + error->message); + DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_text)); + g_free (log_text); + g_error_free (error); + } + else if (error_code != NSM_ERROR_STATUS_OK) + { + log_text = g_strdup_printf ("Failed to unregister shutdown client %s " + "for unit %s: error code %d", object_path, unit, + error_code); + DLT_LOG (la_handler_context, DLT_LOG_ERROR, DLT_STRING (log_text)); + g_free (log_text); + } + } +} diff --git a/boot-manager/la-handler-service.h b/boot-manager/la-handler-service.h index 79f3db2..406000f 100644 --- a/boot-manager/la-handler-service.h +++ b/boot-manager/la-handler-service.h @@ -28,20 +28,20 @@ G_BEGIN_DECLS typedef struct _LAHandlerServiceClass LAHandlerServiceClass; typedef struct _LAHandlerService LAHandlerService; -GType la_handler_service_get_type (void) G_GNUC_CONST; - -GList *la_handler_service_get_clients (LAHandlerService *service); -NSMConsumer *la_handler_service_get_nsm_consumer (LAHandlerService *service); -LAHandlerService *la_handler_service_new (GDBusConnection *connection, - JobManager *job_manager) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -gboolean la_handler_service_start (LAHandlerService *service, - GError **error); -void la_handler_service_register (LAHandlerService *service, - const gchar *unit, - const gchar *mode, - guint timeout, - GAsyncReadyCallback callback, - gpointer user_data); +GType la_handler_service_get_type (void) G_GNUC_CONST; + +LAHandlerService *la_handler_service_new (GDBusConnection *connection, + JobManager *job_manager) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +gboolean la_handler_service_start (LAHandlerService *service, + GError **error); +void la_handler_service_register (LAHandlerService *service, + const gchar *unit, + const gchar *mode, + guint timeout, + GAsyncReadyCallback callback, + gpointer user_data); +NSMConsumer *la_handler_service_get_nsm_consumer (LAHandlerService *service); +void la_handler_service_deregister_consumers (LAHandlerService *service); G_END_DECLS -- 2.7.4