From d32a4b9f6a4f58e3fc20ae5c32ba17aba59b14ac Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 3 Sep 2015 17:05:58 -0400 Subject: [PATCH] daemon: Update deployments on "updated" signal Also, renamed the signal from "sysroot-updated" since it originates from RpmostreedSysroot. --- src/daemon/rpmostreed-os.c | 2 +- src/daemon/rpmostreed-sysroot.c | 118 +++++++++++++++++--------------- 2 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/daemon/rpmostreed-os.c b/src/daemon/rpmostreed-os.c index 15b5527c..769e8a93 100644 --- a/src/daemon/rpmostreed-os.c +++ b/src/daemon/rpmostreed-os.c @@ -129,7 +129,7 @@ os_constructed (GObject *object) /* TODO Integrate with PolicyKit via the "g-authorize-method" signal. */ self->signal_id = g_signal_connect (rpmostreed_sysroot_get (), - "sysroot-updated", + "updated", G_CALLBACK (sysroot_changed), self); G_OBJECT_CLASS (rpmostreed_os_parent_class)->constructed (object); } diff --git a/src/daemon/rpmostreed-sysroot.c b/src/daemon/rpmostreed-sysroot.c index 60495092..3310bd62 100644 --- a/src/daemon/rpmostreed-sysroot.c +++ b/src/daemon/rpmostreed-sysroot.c @@ -69,6 +69,10 @@ struct _RpmostreedSysroot { struct _RpmostreedSysrootClass { RPMOSTreeSysrootSkeletonClass parent_class; + + void (*updated) (RpmostreedSysroot *self, + OstreeSysroot *ot_sysroot, + OstreeRepo *ot_repo); }; enum { @@ -470,6 +474,51 @@ sysroot_transform_transaction_to_attrs (GBinding *binding, return TRUE; } +static void +sysroot_populate_deployments (RpmostreedSysroot *self, + OstreeSysroot *ot_sysroot, + OstreeRepo *ot_repo) +{ + OstreeDeployment *booted = NULL; /* owned by sysroot */ + g_autoptr(GPtrArray) deployments = NULL; + + GVariantBuilder builder; + guint i; + + g_debug ("loading deployments"); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ssisstsav)")); + + /* Add deployment interfaces */ + deployments = ostree_sysroot_get_deployments (ot_sysroot); + + if (deployments == NULL) + return; + + for (i=0; ilen; i++) + { + g_variant_builder_add_value (&builder, + rpmostreed_deployment_generate_variant (deployments->pdata[i], + ot_repo)); + } + + booted = ostree_sysroot_get_booted_deployment (ot_sysroot); + if (booted) + { + const gchar *os = ostree_deployment_get_osname (booted); + g_autofree gchar *path = rpmostreed_generate_object_path (BASE_DBUS_PATH, + os, NULL); + rpmostree_sysroot_set_booted (RPMOSTREE_SYSROOT (self), path); + } + else + { + rpmostree_sysroot_set_booted (RPMOSTREE_SYSROOT (self), "/"); + } + + rpmostree_sysroot_set_deployments (RPMOSTREE_SYSROOT (self), + g_variant_builder_end (&builder)); + g_debug ("finished deployments"); +} + /* ---------------------------------------------------------------------------------------------------- */ static void sysroot_dispose (GObject *object) @@ -589,6 +638,14 @@ sysroot_constructed (GObject *object) G_OBJECT_CLASS (rpmostreed_sysroot_parent_class)->constructed (object); } +static void +sysroot_updated (RpmostreedSysroot *self, + OstreeSysroot *ot_sysroot, + OstreeRepo *ot_repo) +{ + sysroot_populate_deployments (self, ot_sysroot, ot_repo); +} + static void rpmostreed_sysroot_class_init (RpmostreedSysrootClass *klass) { @@ -599,67 +656,18 @@ rpmostreed_sysroot_class_init (RpmostreedSysrootClass *klass) gobject_class->finalize = sysroot_finalize; gobject_class->constructed = sysroot_constructed; - signals[UPDATED] = g_signal_new ("sysroot-updated", + klass->updated = sysroot_updated; + + signals[UPDATED] = g_signal_new ("updated", RPMOSTREED_TYPE_SYSROOT, G_SIGNAL_RUN_LAST, - 0, NULL, NULL, - g_cclosure_marshal_generic, + G_STRUCT_OFFSET (RpmostreedSysrootClass, updated), + NULL, NULL, NULL, G_TYPE_NONE, 2, OSTREE_TYPE_SYSROOT, OSTREE_TYPE_REPO); } - -static gboolean -sysroot_populate_deployments (RpmostreedSysroot *self, - OstreeSysroot *ot_sysroot, - OstreeRepo *ot_repo) -{ - OstreeDeployment *booted = NULL; /* owned by sysroot */ - g_autoptr(GPtrArray) deployments = NULL; - - GVariantBuilder builder; - guint i; - gboolean ret = FALSE; - - g_debug ("loading deployments"); - g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ssisstsav)")); - - /* Add deployment interfaces */ - deployments = ostree_sysroot_get_deployments (ot_sysroot); - - if (deployments == NULL) - goto out; - - for (i=0; ilen; i++) - { - g_variant_builder_add_value (&builder, - rpmostreed_deployment_generate_variant (deployments->pdata[i], - ot_repo)); - } - - booted = ostree_sysroot_get_booted_deployment (ot_sysroot); - if (booted) - { - const gchar *os = ostree_deployment_get_osname (booted); - g_autofree gchar *path = rpmostreed_generate_object_path (BASE_DBUS_PATH, - os, NULL); - rpmostree_sysroot_set_booted (RPMOSTREE_SYSROOT (self), path); - } - else - { - rpmostree_sysroot_set_booted (RPMOSTREE_SYSROOT (self), "/"); - } - - rpmostree_sysroot_set_deployments (RPMOSTREE_SYSROOT (self), - g_variant_builder_end (&builder)); - g_debug ("finished deployments"); - -out: - return ret; -} - - static gboolean rpmostreed_sysroot_load_internals (RpmostreedSysroot *self, OstreeSysroot *ot_sysroot, @@ -860,7 +868,7 @@ rpmostreed_sysroot_iface_init (RPMOSTreeSysrootIface *iface) /** * rpmostreed_sysroot_emit_update: * - * Emits an sysroot-updated signal + * Emits an updated signal */ void rpmostreed_sysroot_emit_update (RpmostreedSysroot *self)