From ac97288ddb9f339ade7b8e785b6d67ff8cc3565c Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 17 Mar 2016 13:10:16 +0000 Subject: [PATCH] Emit a FwupdClient::changed when the daemon emits this signal --- libfwupd/fwupd-client.c | 48 +++++++++++++++++++++++++++++++++++------ libfwupd/fwupd-client.h | 1 + 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/libfwupd/fwupd-client.c b/libfwupd/fwupd-client.c index 40f029c54..b7aa3cf6c 100644 --- a/libfwupd/fwupd-client.c +++ b/libfwupd/fwupd-client.c @@ -49,6 +49,7 @@ typedef struct { } FwupdClientPrivate; enum { + SIGNAL_CHANGED, SIGNAL_STATUS_CHANGED, SIGNAL_LAST }; @@ -103,14 +104,15 @@ fwupd_client_helper_new (void) G_DEFINE_AUTOPTR_CLEANUP_FUNC(FwupdClientHelper, fwupd_client_helper_free) /** - * fwupd_client_status_changed_cb: + * fwupd_client_properties_changed_cb: **/ static void -fwupd_client_status_changed_cb (GDBusProxy *proxy, GVariant *changed_properties, - GStrv invalidated_properties, gpointer user_data) +fwupd_client_properties_changed_cb (GDBusProxy *proxy, + GVariant *changed_properties, + GStrv invalidated_properties, + FwupdClient *client) { g_autoptr(GVariant) val = NULL; - FwupdClient *client = FWUPD_CLIENT (user_data); FwupdClientPrivate *priv = GET_PRIVATE (client); /* print to the console */ @@ -122,6 +124,20 @@ fwupd_client_status_changed_cb (GDBusProxy *proxy, GVariant *changed_properties, g_signal_emit (client, signals[SIGNAL_STATUS_CHANGED], 0, priv->status); } +/** + * fwupd_client_signal_cb: + */ +static void +fwupd_client_signal_cb (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters, + FwupdClient *client) +{ + g_debug ("Emitting ::changed()"); + g_signal_emit (client, signals[SIGNAL_CHANGED], 0); +} + /** * fwupd_client_startup: **/ @@ -151,7 +167,9 @@ fwupd_client_startup (FwupdClient *client, GCancellable *cancellable, GError **e if (priv->proxy == NULL) return FALSE; g_signal_connect (priv->proxy, "g-properties-changed", - G_CALLBACK (fwupd_client_status_changed_cb), client); + G_CALLBACK (fwupd_client_properties_changed_cb), client); + g_signal_connect (priv->proxy, "g-signal", + G_CALLBACK (fwupd_client_signal_cb), client); return TRUE; } @@ -809,13 +827,29 @@ fwupd_client_class_init (FwupdClientClass *klass) object_class->get_property = fwupd_client_get_property; object_class->set_property = fwupd_client_set_property; + /** + * AsStore::changed: + * @client: the #FwupdClient instance that emitted the signal + * + * The ::changed signal is emitted when the daemon internal has + * changed, for instance when a device has been added or removed. + * + * Since: 0.7.0 + **/ + signals [SIGNAL_CHANGED] = + g_signal_new ("changed", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (FwupdClientClass, changed), + NULL, NULL, g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + /** * AsStore::state-changed: * @client: the #FwupdClient instance that emitted the signal * @status: the #FwupdStatus * - * The ::state-changed signal is emitted when the daemon state has - * changed. + * The ::state-changed signal is emitted when the daemon status has + * changed, e.g. going from %FWUPD_STATUS_IDLE to %FWUPD_STATUS_DEVICE_WRITE. * * Since: 0.7.0 **/ diff --git a/libfwupd/fwupd-client.h b/libfwupd/fwupd-client.h index 7d8b5cd83..8968334a4 100644 --- a/libfwupd/fwupd-client.h +++ b/libfwupd/fwupd-client.h @@ -36,6 +36,7 @@ G_DECLARE_DERIVABLE_TYPE (FwupdClient, fwupd_client, FWUPD, CLIENT, GObject) struct _FwupdClientClass { GObjectClass parent_class; + void (*changed) (FwupdClient *client); void (*status_changed) (FwupdClient *client, FwupdStatus status); /*< private >*/