mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 20:10:17 +01:00
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
This commit is contained in:
parent
b6525ba918
commit
114228f8b2
2 changed files with 30 additions and 2 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue