4 * @brief Implements the subdevice list class.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
10 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
12 * This file is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "medefines.h"
33 int me_slist_query_number_subdevices(struct me_slist
*slist
, int *number
)
35 PDEBUG_LOCKS("called.\n");
37 return ME_ERRNO_SUCCESS
;
40 unsigned int me_slist_get_number_subdevices(struct me_slist
*slist
)
42 PDEBUG_LOCKS("called.\n");
46 me_subdevice_t
*me_slist_get_subdevice(struct me_slist
* slist
,
50 struct list_head
*pos
;
51 me_subdevice_t
*subdevice
= NULL
;
54 PDEBUG_LOCKS("called.\n");
56 if (index
>= slist
->n
) {
57 PERROR("Index out of range.\n");
61 list_for_each(pos
, &slist
->head
) {
63 subdevice
= list_entry(pos
, me_subdevice_t
, list
);
73 int me_slist_get_subdevice_by_type(struct me_slist
*slist
,
74 unsigned int start_subdevice
,
75 int type
, int subtype
, int *subdevice
)
78 int s_type
, s_subtype
;
79 unsigned int index
= 0;
81 PDEBUG_LOCKS("called.\n");
83 if (start_subdevice
>= slist
->n
) {
84 PERROR("Start index out of range.\n");
85 return ME_ERRNO_NOMORE_SUBDEVICE_TYPE
;
88 list_for_each_entry(pos
, &slist
->head
, list
) {
89 if (index
< start_subdevice
) { // Go forward to start subdevice.
94 pos
->me_subdevice_query_subdevice_type(pos
,
97 if (subtype
== ME_SUBTYPE_ANY
) {
101 if ((s_type
== type
) && (s_subtype
== subtype
))
108 if (index
>= slist
->n
) {
109 return ME_ERRNO_NOMORE_SUBDEVICE_TYPE
;
114 return ME_ERRNO_SUCCESS
;
117 void me_slist_add_subdevice_tail(struct me_slist
*slist
,
118 me_subdevice_t
* subdevice
)
120 PDEBUG_LOCKS("called.\n");
122 list_add_tail(&subdevice
->list
, &slist
->head
);
126 me_subdevice_t
*me_slist_del_subdevice_tail(struct me_slist
*slist
)
129 struct list_head
*last
;
130 me_subdevice_t
*subdevice
;
132 PDEBUG_LOCKS("called.\n");
134 if (list_empty(&slist
->head
))
137 last
= slist
->head
.prev
;
139 subdevice
= list_entry(last
, me_subdevice_t
, list
);
148 int me_slist_init(me_slist_t
* slist
)
150 PDEBUG_LOCKS("called.\n");
152 INIT_LIST_HEAD(&slist
->head
);
157 void me_slist_deinit(me_slist_t
* slist
)
161 me_subdevice_t
*subdevice
;
163 PDEBUG_LOCKS("called.\n");
165 while (!list_empty(&slist
->head
)) {
166 s
= slist
->head
.next
;
168 subdevice
= list_entry(s
, me_subdevice_t
, list
);
169 subdevice
->me_subdevice_destructor(subdevice
);