summaryrefslogtreecommitdiff
path: root/libnm/nm-object.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-01-04 07:58:58 +0100
committerThomas Haller <thaller@redhat.com>2020-01-08 13:44:05 +0100
commit85f03e393d15c3c500e50fc7e5fc8a8749235060 (patch)
tree5a41f57cfb6ace82da3fa467dc39ed767f4c71bd /libnm/nm-object.c
parent5080dfa46fc6496be110d743ce233d2ca6b9977f (diff)
downloadNetworkManager-85f03e393d15c3c500e50fc7e5fc8a8749235060.tar.gz
client: add nm_client_get_object_by_path() and nm_object_get_client() APIth/nm-client-get-object-by-path
When iterating the GMainContext of the NMClient instance, D-Bus events get processed. That means, every time you iterate the context (or "return to the main loop"), the content of the cache might change completely. It makes sense to keep a reference to an NMObject instance, do something, and afterwards check whether the instance can still be found in the cache. Add an API for that. nm_object_get_client() allows to know whether the object is still cached. Likewise, while NMClient abstracts D-Bus, it should still provide a way to look up an NMObject by D-Bus path. Add nm_client_get_object_by_path() for that.
Diffstat (limited to 'libnm/nm-object.c')
-rw-r--r--libnm/nm-object.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/libnm/nm-object.c b/libnm/nm-object.c
index 89dc8bb3c8..d8c4fb41d2 100644
--- a/libnm/nm-object.c
+++ b/libnm/nm-object.c
@@ -78,13 +78,40 @@ _nm_object_get_client (gpointer self)
*
* Returns: the object's path. This is the internal string used by the
* object, and must not be modified.
+ *
+ * Note that the D-Bus path of an NMObject never changes, even
+ * if the instance gets removed from the cache. To find out
+ * whether the object is still alive/cached, check nm_object_get_client().
**/
const char *
nm_object_get_path (NMObject *object)
{
g_return_val_if_fail (NM_IS_OBJECT (object), NULL);
- return NM_OBJECT_GET_PRIVATE (object)->dbobj->dbus_path->str;
+ return _nm_object_get_path (object);
+}
+
+/**
+ * nm_object_get_client:
+ * @object: a #NMObject
+ *
+ * Returns the #NMClient instance in which object is cached.
+ * Also, if the object got removed from the client cached,
+ * this returns %NULL. So it can be used to check whether the
+ * object is still alive.
+ *
+ * Returns: (transfer none): the #NMClient cache in which the
+ * object can be found, or %NULL if the object is no longer
+ * cached.
+ *
+ * Since: 1.24
+ **/
+NMClient *
+nm_object_get_client (NMObject *object)
+{
+ g_return_val_if_fail (NM_IS_OBJECT (object), NULL);
+
+ return _nm_object_get_client (object);
}
/*****************************************************************************/