David Kiliani | 3fedd14 | 2008-11-01 00:39:12 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file me_dlist.h |
| 3 | * |
| 4 | * @brief Provides the device list class. |
| 5 | * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de) |
| 6 | * @author Guenter Gebhardt |
| 7 | */ |
| 8 | |
| 9 | #ifndef _ME_DLIST_H_ |
| 10 | #define _ME_DLIST_H_ |
| 11 | |
| 12 | #include <linux/list.h> |
| 13 | |
| 14 | #include "medevice.h" |
| 15 | |
| 16 | #ifdef __KERNEL__ |
| 17 | |
| 18 | /** |
| 19 | * @brief The device list container. |
| 20 | */ |
| 21 | typedef struct me_dlist { |
| 22 | struct list_head head; /**< The head of the internal list. */ |
| 23 | unsigned int n; /**< The number of devices in the list. */ |
| 24 | } me_dlist_t; |
| 25 | |
| 26 | /** |
| 27 | * @brief Queries the number of devices currently inside the list. |
| 28 | * |
| 29 | * @param dlist The device list to query. |
| 30 | * @param[out] number The number of devices. |
| 31 | * |
| 32 | * @return ME-iDS error code. |
| 33 | */ |
| 34 | int me_dlist_query_number_devices(struct me_dlist *dlist, int *number); |
| 35 | |
| 36 | /** |
| 37 | * @brief Returns the number of devices currently inside the list. |
| 38 | * |
| 39 | * @param dlist The device list to query. |
| 40 | * |
| 41 | * @return The number of devices in the list. |
| 42 | */ |
| 43 | unsigned int me_dlist_get_number_devices(struct me_dlist *dlist); |
| 44 | |
| 45 | /** |
| 46 | * @brief Get a device by index. |
| 47 | * |
| 48 | * @param dlist The device list to query. |
| 49 | * @param index The index of the device to get in the list. |
| 50 | * |
| 51 | * @return The device at index if available.\n |
| 52 | * NULL if the index is out of range. |
| 53 | */ |
| 54 | me_device_t *me_dlist_get_device(struct me_dlist *dlist, unsigned int index); |
| 55 | |
| 56 | /** |
| 57 | * @brief Adds a device to the tail of the list. |
| 58 | * |
| 59 | * @param dlist The device list to add a device to. |
| 60 | * @param device The device to add to the list. |
| 61 | */ |
| 62 | void me_dlist_add_device_tail(struct me_dlist *dlist, me_device_t * device); |
| 63 | |
| 64 | /** |
| 65 | * @brief Removes a device from the tail of the list. |
| 66 | * |
| 67 | * @param dlist The device list. |
| 68 | * |
| 69 | * @return Pointer to the removed subdeivce.\n |
| 70 | * NULL in cases where the list was empty. |
| 71 | */ |
| 72 | me_device_t *me_dlist_del_device_tail(struct me_dlist *dlist); |
| 73 | |
| 74 | /** |
| 75 | * @brief Initializes a device list structure. |
| 76 | * |
| 77 | * @param lock The device list structure to initialize. |
| 78 | * @return 0 on success. |
| 79 | */ |
| 80 | int me_dlist_init(me_dlist_t * dlist); |
| 81 | |
| 82 | /** |
| 83 | * @brief Deinitializes a device list structure and destructs every device in it. |
| 84 | * |
| 85 | * @param dlist The device list structure to deinitialize. |
| 86 | * @return 0 on success. |
| 87 | */ |
| 88 | void me_dlist_deinit(me_dlist_t * dlist); |
| 89 | |
| 90 | #endif |
| 91 | #endif |