diff options
-rw-r--r-- | libnm/libnm.ver | 2 | ||||
-rw-r--r-- | libnm/nm-client.c | 20 | ||||
-rw-r--r-- | libnm/nm-client.h | 3 | ||||
-rw-r--r-- | libnm/nm-object.c | 29 | ||||
-rw-r--r-- | libnm/nm-object.h | 5 |
5 files changed, 57 insertions, 2 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 1a25f046dd..d8e069f8ae 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1661,6 +1661,8 @@ global: libnm_1_24_0 { global: nm_client_get_instance_flags; + nm_client_get_object_by_path; nm_client_get_permissions_state; nm_client_instance_flags_get_type; + nm_object_get_client; } libnm_1_22_0; diff --git a/libnm/nm-client.c b/libnm/nm-client.c index 02a5b002f5..7e2cacc673 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -3914,6 +3914,26 @@ nm_client_get_nm_running (NMClient *client) } /** + * nm_client_get_object_by_path: + * @client: the #NMClient instance + * @dbus_path: the D-Bus path of the object to look up + * + * Returns: (transfer none): the #NMObject instance that is + * cached under @dbus_path, or %NULL if no such object exists. + * + * Since: 1.24 + */ +NMObject * +nm_client_get_object_by_path (NMClient *client, + const char *dbus_path) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + g_return_val_if_fail (dbus_path, NULL); + + return _dbobjs_get_nmobj_unpack_visible (client, dbus_path, G_TYPE_NONE); +} + +/** * nm_client_get_metered: * @client: a #NMClient * diff --git a/libnm/nm-client.h b/libnm/nm-client.h index e409fbc05b..9c2fdff9f1 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -174,6 +174,9 @@ NMState nm_client_get_state (NMClient *client); gboolean nm_client_get_startup (NMClient *client); gboolean nm_client_get_nm_running (NMClient *client); +NMObject *nm_client_get_object_by_path (NMClient *client, + const char *dbus_path); + NM_AVAILABLE_IN_1_22 NMMetered nm_client_get_metered (NMClient *client); 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); } /*****************************************************************************/ diff --git a/libnm/nm-object.h b/libnm/nm-object.h index 88c34a9eb1..18b44d8aa5 100644 --- a/libnm/nm-object.h +++ b/libnm/nm-object.h @@ -31,7 +31,10 @@ typedef struct _NMObjectClass NMObjectClass; GType nm_object_get_type (void); -const char *nm_object_get_path (NMObject *object); +const char *nm_object_get_path (NMObject *object); + +NM_AVAILABLE_IN_1_24 +NMClient *nm_object_get_client (NMObject *object); G_END_DECLS |