From 114228f8b2c3669b5b136ce62ed1dc74e83a85f6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Jun 2021 14:51:09 +0200 Subject: [PATCH] libnm: add NM_OBJECT_CLIENT property We have nm_object_get_client() property that returns a reference to the NMClient instance. This is actually useful, because if the function returns %NULL, it means that the object was removed from the cache. On the other hand, the user cannot subscribe to notifications when this happens. Well, there are otherwise pointless signals like NM_CLIENT_DEVICE_REMOVED, which we wouldn't need if we had a general mechanism for NMObject instances. Add a GObject property "client", which is just that mechanism. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/902 --- src/libnm-client-impl/nm-object.c | 29 ++++++++++++++++++++++++++++- src/libnm-client-public/nm-object.h | 3 ++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/libnm-client-impl/nm-object.c b/src/libnm-client-impl/nm-object.c index 2e7de8c266..ae48853b4d 100644 --- a/src/libnm-client-impl/nm-object.c +++ b/src/libnm-client-impl/nm-object.c @@ -21,7 +21,7 @@ /*****************************************************************************/ -NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PATH, ); +NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PATH, PROP_CLIENT, ); typedef struct _NMObjectPrivate { NMClient * client; @@ -215,6 +215,8 @@ unregister_client(NMObject *self, NMClient *client, NMLDBusObject *dbobj) nm_assert(priv->client == client); priv->client = NULL; + _nm_client_queue_notify_object(client, self, obj_properties[PROP_CLIENT]); + clear_properties(self, client); } @@ -229,6 +231,9 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) case PROP_PATH: g_value_set_string(value, nm_object_get_path(self)); break; + case PROP_CLIENT: + g_value_set_object(value, nm_object_get_client(self)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -300,6 +305,10 @@ nm_object_class_init(NMObjectClass *klass) * NMObject:path: * * The D-Bus object path. + * + * The D-Bus path of an object instance never changes, even if the object + * gets removed from the cache. To see whether the object is still in the + * cache, check NMObject:client. **/ obj_properties[PROP_PATH] = g_param_spec_string(NM_OBJECT_PATH, "", @@ -307,5 +316,23 @@ nm_object_class_init(NMObjectClass *klass) NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + /** + * NMObject:client: + * + * The NMClient instance as returned by nm_object_get_client(). + * + * When an NMObject gets removed from the NMClient cache, + * the NMObject:path property stays unchanged, but this client + * instance gets reset to %NULL. You can use this property to + * track removal of the object from the cache. + * + * Since: 1.34 + **/ + obj_properties[PROP_CLIENT] = g_param_spec_object(NM_OBJECT_CLIENT, + "", + "", + NM_TYPE_CLIENT, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); } diff --git a/src/libnm-client-public/nm-object.h b/src/libnm-client-public/nm-object.h index 7b4a323294..5f41751390 100644 --- a/src/libnm-client-public/nm-object.h +++ b/src/libnm-client-public/nm-object.h @@ -22,7 +22,8 @@ G_BEGIN_DECLS #define NM_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_OBJECT)) #define NM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_OBJECT, NMObjectClass)) -#define NM_OBJECT_PATH "path" +#define NM_OBJECT_PATH "path" +#define NM_OBJECT_CLIENT "client" /** * NMObject: