shared: add nm_dbus_utils_get_paths_for_clist() util

This commit is contained in:
Thomas Haller
2018-03-30 20:10:34 +02:00
parent 67e06924e1
commit 76df7a3088
2 changed files with 47 additions and 0 deletions

View File

@@ -152,4 +152,44 @@ nm_dbus_utils_g_value_set_object_path_from_hash (GValue *value,
g_value_take_boxed (value, strv);
}
const char **
nm_dbus_utils_get_paths_for_clist (const CList *lst_head,
gssize lst_len,
guint member_offset,
gboolean expect_all_exported)
{
const CList *iter;
const char **strv;
const char *path;
gsize i, n;
nm_assert (lst_head);
if (lst_len < 0)
n = c_list_length (lst_head);
else {
n = lst_len;
nm_assert (n == c_list_length (lst_head));
}
i = 0;
strv = g_new (const char *, n + 1);
c_list_for_each (iter, lst_head) {
NMDBusObject *obj = (NMDBusObject *) (((const char *) iter) - member_offset);
path = nm_dbus_object_get_path (obj);
if (!path) {
nm_assert (expect_all_exported);
continue;
}
nm_assert (i < n);
strv[i++] = path;
}
nm_assert (i <= n);
strv[i] = NULL;
return strv;
}
/*****************************************************************************/

View File

@@ -164,6 +164,13 @@ GVariant *nm_dbus_utils_get_property (GObject *obj,
/*****************************************************************************/
struct CList;
const char **nm_dbus_utils_get_paths_for_clist (const struct CList *lst_head,
gssize lst_len,
guint member_offset,
gboolean expect_all_exported);
void nm_dbus_utils_g_value_set_object_path (GValue *value, gpointer object);
void nm_dbus_utils_g_value_set_object_path_from_hash (GValue *value,