From: Marcel Holtmann Date: Thu, 16 Jul 2009 01:48:43 +0000 (+0200) Subject: Add function to find first device of a given type X-Git-Tag: 2.0_alpha~3527 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af9fb9a2f08797407c8c2911df4cb27ff2490db3;p=framework%2Fconnectivity%2Fconnman.git Add function to find first device of a given type --- diff --git a/src/connman.h b/src/connman.h index 84ebf60..9b68083 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 bdf222c..0175019 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;