From: Jonathan Maw Date: Tue, 19 Jun 2012 10:41:56 +0000 (+0100) Subject: Add Restart() handler X-Git-Tag: boot-manager-0.1.0~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c771c1be3b175ce3b96adea60a6b28c7dc8d32f7;p=profile%2Fivi%2Fnode-startup-controller.git Add Restart() handler Restart() functions almost identically to Start() and Stop(), with the same input and output arguments. --- diff --git a/boot-manager/boot-manager-service.c b/boot-manager/boot-manager-service.c index 11454b7..5fac573 100644 --- a/boot-manager/boot-manager-service.c +++ b/boot-manager/boot-manager-service.c @@ -33,68 +33,80 @@ enum -static void boot_manager_service_finalize (GObject *object); -static void boot_manager_service_constructed (GObject *object); -static void boot_manager_service_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void boot_manager_service_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static gboolean boot_manager_service_handle_start (BootManager *interface, - GDBusMethodInvocation *invocation, - const gchar *unit, - BootManagerService *service); -static void boot_manager_service_handle_start_finish (BootManagerService *service, - const gchar *unit, - const gchar *result, - GError *error, - gpointer user_data); -static void boot_manager_service_start_unit_reply (GObject *object, - GAsyncResult *result, - gpointer user_data); -static gboolean boot_manager_service_handle_stop (BootManager *interface, - GDBusMethodInvocation *invocation, - const gchar *unit, - BootManagerService *service); -static void boot_manager_service_handle_stop_finish (BootManagerService *service, - const gchar *unit, - const gchar *result, - GError *error, - gpointer user_data); -static void boot_manager_service_stop_unit_reply (GObject *object, - GAsyncResult *result, - gpointer user_data); -static gboolean boot_manager_service_handle_kill (BootManager *interface, - GDBusMethodInvocation *invocation, - const gchar *unit, - BootManagerService *service); -static void boot_manager_service_handle_kill_finish (BootManagerService *service, - const gchar *unit, - const gchar *result, - GError *error, - gpointer user_data); -static void boot_manager_service_kill_unit_reply (GObject *object, - GAsyncResult *result, - gpointer user_data); -static void boot_manager_service_job_removed (SystemdManager *manager, - guint id, - const gchar *job_name, - const gchar *result, - BootManagerService *service); -static BootManagerServiceJob *boot_manager_service_job_new (BootManagerService *service, - const gchar *unit, - GCancellable *cancellable, - BootManagerServiceCallback callback, - gpointer user_data); -static void boot_manager_service_job_unref (BootManagerServiceJob *job); -static void boot_manager_service_remember_job (BootManagerService *service, - const gchar *job_name, - BootManagerServiceJob *job); -static void boot_manager_service_forget_job (BootManagerService *service, - const gchar *job_name); +static void boot_manager_service_finalize (GObject *object); +static void boot_manager_service_constructed (GObject *object); +static void boot_manager_service_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void boot_manager_service_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static gboolean boot_manager_service_handle_start (BootManager *interface, + GDBusMethodInvocation *invocation, + const gchar *unit, + BootManagerService *service); +static void boot_manager_service_handle_start_finish (BootManagerService *service, + const gchar *unit, + const gchar *result, + GError *error, + gpointer user_data); +static void boot_manager_service_start_unit_reply (GObject *object, + GAsyncResult *result, + gpointer user_data); +static gboolean boot_manager_service_handle_stop (BootManager *interface, + GDBusMethodInvocation *invocation, + const gchar *unit, + BootManagerService *service); +static void boot_manager_service_handle_stop_finish (BootManagerService *service, + const gchar *unit, + const gchar *result, + GError *error, + gpointer user_data); +static void boot_manager_service_stop_unit_reply (GObject *object, + GAsyncResult *result, + gpointer user_data); +static gboolean boot_manager_service_handle_kill (BootManager *interface, + GDBusMethodInvocation *invocation, + const gchar *unit, + BootManagerService *service); +static void boot_manager_service_handle_kill_finish (BootManagerService *service, + const gchar *unit, + const gchar *result, + GError *error, + gpointer user_data); +static void boot_manager_service_kill_unit_reply (GObject *object, + GAsyncResult *result, + gpointer user_data); +static gboolean boot_manager_service_handle_restart (BootManager *interface, + GDBusMethodInvocation *invocation, + const gchar *unit, + BootManagerService *service); +static void boot_manager_service_handle_restart_finish (BootManagerService *service, + const gchar *unit, + const gchar *result, + GError *error, + gpointer user_data); +static void boot_manager_service_restart_unit_reply (GObject *object, + GAsyncResult *result, + gpointer user_data); +static void boot_manager_service_job_removed (SystemdManager *manager, + guint id, + const gchar *job_name, + const gchar *result, + BootManagerService *service); +static BootManagerServiceJob *boot_manager_service_job_new (BootManagerService *service, + const gchar *unit, + GCancellable *cancellable, + BootManagerServiceCallback callback, + gpointer user_data); +static void boot_manager_service_job_unref (BootManagerServiceJob *job); +static void boot_manager_service_remember_job (BootManagerService *service, + const gchar *job_name, + BootManagerServiceJob *job); +static void boot_manager_service_forget_job (BootManagerService *service, + const gchar *job_name); @@ -185,6 +197,9 @@ boot_manager_service_init (BootManagerService *service) /* implement the Kill() method handler */ g_signal_connect (service->interface, "handle-kill", G_CALLBACK (boot_manager_service_handle_kill), service); + /* implement the Restart() method handler */ + g_signal_connect (service->interface, "handle-restart", + G_CALLBACK (boot_manager_service_handle_restart), service); } @@ -507,6 +522,85 @@ boot_manager_service_kill_unit_reply (GObject *object, +static gboolean +boot_manager_service_handle_restart (BootManager *interface, + GDBusMethodInvocation *invocation, + const gchar *unit, + BootManagerService *service) +{ + g_return_val_if_fail (IS_BOOT_MANAGER (interface), FALSE); + g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), FALSE); + g_return_val_if_fail (unit != NULL, FALSE); + g_return_val_if_fail (BOOT_MANAGER_IS_SERVICE (service), FALSE); + + /* ask systemd to restart the unit for us, send a D-Bus reply in the finish callback */ + boot_manager_service_restart (service, unit, NULL, + boot_manager_service_handle_restart_finish, invocation); + + return TRUE; +} + + + +static void +boot_manager_service_handle_restart_finish (BootManagerService *service, + const gchar *unit, + const gchar *result, + GError *error, + gpointer user_data) +{ + GDBusMethodInvocation *invocation = G_DBUS_METHOD_INVOCATION (user_data); + + g_return_if_fail (BOOT_MANAGER_IS_SERVICE (service)); + g_return_if_fail (unit != NULL); + g_return_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation)); + + /* log any potential errors */ + if (error != NULL) + g_warning ("there was an error: %s", error->message); + + /* report the result back to the boot manager client */ + boot_manager_complete_restart (service->interface, invocation, result); +} + + + +static void +boot_manager_service_restart_unit_reply (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + BootManagerServiceJob *job = user_data; + GError *error = NULL; + gchar *job_name = NULL; + + g_return_if_fail (IS_SYSTEMD_MANAGER (object)); + g_return_if_fail (G_IS_ASYNC_RESULT (result)); + g_return_if_fail (user_data != NULL); + + /* finish the restart unit call */ + if (!systemd_manager_call_restart_unit_finish (job->service->systemd_manager, + &job_name, result, &error)) + { + /* there was an error; let the caller know */ + job->callback (job->service, job->unit, "failed", error, job->user_data); + g_error_free (error); + g_free (job_name); + + /* finish the job immediately */ + boot_manager_service_job_unref (job); + } + else + { + /* remember the job so that we can finish it in the "job-removed" signal + * handler. the service takes ownership of the job so we don't need to + * unref it here */ + boot_manager_service_remember_job (job->service, job_name, job); + } +} + + + static void boot_manager_service_job_removed (SystemdManager *manager, guint id, @@ -719,3 +813,27 @@ boot_manager_service_kill (BootManagerService *service, SIGKILL, cancellable, boot_manager_service_kill_unit_reply, job); } + + + +void +boot_manager_service_restart (BootManagerService *service, + const gchar *unit, + GCancellable *cancellable, + BootManagerServiceCallback callback, + gpointer user_data) +{ + BootManagerServiceJob *job; + + g_return_if_fail (BOOT_MANAGER_IS_SERVICE (service)); + g_return_if_fail (unit != NULL); + g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + g_return_if_fail (callback != NULL); + + /* create a new job object */ + job = boot_manager_service_job_new (service, unit, cancellable, callback, user_data); + + /* ask systemd to restart the unit asynchronously */ + systemd_manager_call_restart_unit (service->systemd_manager, unit, "fail", cancellable, + boot_manager_service_restart_unit_reply, job); +} diff --git a/boot-manager/boot-manager-service.h b/boot-manager/boot-manager-service.h index d174d37..bee0348 100644 --- a/boot-manager/boot-manager-service.h +++ b/boot-manager/boot-manager-service.h @@ -51,6 +51,11 @@ void boot_manager_service_kill (BootManagerService *se GCancellable *cancellable, BootManagerServiceCallback callback, gpointer user_data); +void boot_manager_service_restart (BootManagerService *service, + const gchar *unit, + GCancellable *cancellable, + BootManagerServiceCallback callback, + gpointer user_data); G_END_DECLS