summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-03-29 11:04:37 +0200
committerThomas Haller <thaller@redhat.com>2018-03-29 11:11:56 +0200
commit18f692f702efc408814a737e3ed49a0809b1b950 (patch)
tree0fdc96ffa622859394616694ebbb9768d4b21574
parentd169cde872c433c1985188f252e1945d4972e154 (diff)
downloadNetworkManager-18f692f702efc408814a737e3ed49a0809b1b950.tar.gz
core: add nm_dbus_utils_g_value_set_object_path_from_hash() helper
-rw-r--r--src/nm-dbus-utils.c32
-rw-r--r--src/nm-dbus-utils.h4
2 files changed, 35 insertions, 1 deletions
diff --git a/src/nm-dbus-utils.c b/src/nm-dbus-utils.c
index eab6cb6125..0335e28a6d 100644
--- a/src/nm-dbus-utils.c
+++ b/src/nm-dbus-utils.c
@@ -147,6 +147,36 @@ nm_dbus_utils_g_value_set_object_path_array (GValue *value,
g_value_take_boxed (value, paths);
}
-/*****************************************************************************/
+void
+nm_dbus_utils_g_value_set_object_path_from_hash (GValue *value,
+ GHashTable *hash /* is has keys of NMDBusObject type. */,
+ gboolean expect_all_exported)
+{
+ NMDBusObject *obj;
+ char **strv;
+ guint i, n;
+ GHashTableIter iter;
+
+ nm_assert (value);
+ nm_assert (hash);
+
+ n = g_hash_table_size (hash);
+ strv = g_new (char *, n + 1);
+ i = 0;
+ g_hash_table_iter_init (&iter, hash);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &obj, NULL)) {
+ const char *path;
+ path = nm_dbus_object_get_path (obj);
+ if (!path) {
+ nm_assert (!expect_all_exported);
+ continue;
+ }
+ strv[i++] = g_strdup (path);
+ }
+ nm_assert (i <= n);
+ strv[i] = NULL;
+ g_value_take_boxed (value, strv);
+}
+/*****************************************************************************/
diff --git a/src/nm-dbus-utils.h b/src/nm-dbus-utils.h
index 4b0ec5c477..e556cdd1b0 100644
--- a/src/nm-dbus-utils.h
+++ b/src/nm-dbus-utils.h
@@ -171,4 +171,8 @@ void nm_dbus_utils_g_value_set_object_path_array (GValue *value,
gboolean (*filter_func) (GObject *object, gpointer user_data),
gpointer user_data);
+void nm_dbus_utils_g_value_set_object_path_from_hash (GValue *value,
+ GHashTable *hash,
+ gboolean expect_all_exported);
+
#endif /* __NM_DBUS_UTILS_H__ */