summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/connman.h2
-rw-r--r--src/element.c34
2 files changed, 36 insertions, 0 deletions
diff --git a/src/connman.h b/src/connman.h
index 84ebf602..9b68083a 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -163,6 +163,8 @@ struct connman_device *__connman_element_get_device(struct connman_element *elem
const char *__connman_element_get_device_path(struct connman_element *element);
const char *__connman_element_get_network_path(struct connman_element *element);
+struct connman_device *__connman_element_find_device(enum connman_device_type type);
+
const char *__connman_element_type2string(enum connman_element_type type);
static inline void __connman_element_lock(struct connman_element *element)
diff --git a/src/element.c b/src/element.c
index bdf222c8..0175019e 100644
--- a/src/element.c
+++ b/src/element.c
@@ -330,6 +330,40 @@ const char *__connman_element_get_network_path(struct connman_element *element)
return __connman_element_get_network_path(element->parent);
}
+struct find_data {
+ enum connman_device_type type;
+ struct connman_device *device;
+};
+
+static gboolean find_device(GNode *node, gpointer user_data)
+{
+ struct connman_element *element = node->data;
+ struct find_data *data = user_data;
+
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ return FALSE;
+
+ if (element->device == NULL)
+ return FALSE;
+
+ if (data->type != connman_device_get_type(element->device))
+ return FALSE;
+
+ data->device = element->device;
+
+ return TRUE;
+}
+
+struct connman_device *__connman_element_find_device(enum connman_device_type type)
+{
+ struct find_data data = { .type = type, .device = NULL };
+
+ g_node_traverse(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, -1, find_device, &data);
+
+ return data.device;
+}
+
static gint compare_priority(gconstpointer a, gconstpointer b)
{
const struct connman_driver *driver1 = a;