list.h
Go to the documentation of this file.
1 /*
2  * Driver for the wge100 camera
3  * Copyright (C) 2009, 2010 Willow Garage, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef __EMLIST_H_
21 #define __EMLIST_H_
22 #include "build.h"
23 #include "ipcam_packet.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
37 /*
38  * Simple doubly linked list implementation.
39  *
40  * Some of the internal functions ("__xxx") are useful when
41  * manipulating whole lists rather than single entries, as
42  * sometimes we already know the next/prev entries and we can
43  * generate better code by using them directly rather than
44  * using the generic single-entry routines.
45  */
46 
47 struct list_head {
48  struct list_head *next, *prev;
49 };
50 
51 #define LIST_HEAD_INIT(name) { &(name), &(name) }
52 
53 #define LIST_HEAD(name) \
54  struct list_head name = LIST_HEAD_INIT(name)
55 
56 #define INIT_LIST_HEAD(ptr) do { \
57  (ptr)->next = (ptr); (ptr)->prev = (ptr); \
58 } while (0)
59 
60 /*
61  * Insert a new entry between two known consecutive entries.
62  *
63  * This is only for internal list manipulation where we know
64  * the prev/next entries already!
65  */
66 static inline void __list_add(struct list_head *new_item,
67  struct list_head *prev,
68  struct list_head *next)
69 {
70  next->prev = new_item;
71  new_item->next = next;
72  new_item->prev = prev;
73  prev->next = new_item;
74 }
75 
84 static inline void list_add(struct list_head *new_item, struct list_head *head)
85 {
86  __list_add(new_item, head, head->next);
87 }
88 
97 static inline void list_add_tail(struct list_head *new_item, struct list_head *head)
98 {
99  __list_add(new_item, head->prev, head);
100 }
101 
102 /*
103  * Delete a list entry by making the prev/next entries
104  * point to each other.
105  *
106  * This is only for internal list manipulation where we know
107  * the prev/next entries already!
108  */
109 static inline void __list_del(struct list_head *prev, struct list_head *next)
110 {
111  next->prev = prev;
112  prev->next = next;
113 }
114 
120 static inline void list_del(struct list_head *entry)
121 {
122  __list_del(entry->prev, entry->next);
123  entry->next = (struct list_head *) 0;
124  entry->prev = (struct list_head *) 0;
125 }
126 
131 static inline void list_del_init(struct list_head *entry)
132 {
133  __list_del(entry->prev, entry->next);
134  INIT_LIST_HEAD(entry);
135 }
136 
142 static inline void list_move(struct list_head *list, struct list_head *head)
143 {
144  __list_del(list->prev, list->next);
145  list_add(list, head);
146 }
147 
153 static inline void list_move_tail(struct list_head *list,
154  struct list_head *head)
155 {
156  __list_del(list->prev, list->next);
157  list_add_tail(list, head);
158 }
159 
164 static inline int list_empty(struct list_head *head)
165 {
166  return head->next == head;
167 }
168 
169 static inline void __list_splice(struct list_head *list,
170  struct list_head *head)
171 {
172  struct list_head *first = list->next;
173  struct list_head *last = list->prev;
174  struct list_head *at = head->next;
175 
176  first->prev = head;
177  head->next = first;
178 
179  last->next = at;
180  at->prev = last;
181 }
182 
188 static inline void list_splice(struct list_head *list, struct list_head *head)
189 {
190  if (!list_empty(list))
191  __list_splice(list, head);
192 }
193 
201 static inline void list_splice_init(struct list_head *list,
202  struct list_head *head)
203 {
204  if (!list_empty(list)) {
205  __list_splice(list, head);
206  INIT_LIST_HEAD(list);
207  }
208 }
209 
216 #define list_entry(ptr, type, member) \
217  ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
218 
224 #define list_for_each(pos, head) \
225  for (pos = (head)->next; pos != (head); \
226  pos = pos->next)
227 
232 #define list_for_each_prev(pos, head) \
233  for (pos = (head)->prev; pos != (head); \
234  pos = pos->prev)
235 
242 #define list_for_each_safe(pos, n, head) \
243  for (pos = (head)->next, n = pos->next; pos != (head); \
244  pos = n, n = pos->next)
245 
252 #define list_for_each_entry(pos, head, member) \
253  for (pos = list_entry((head)->next, typeof(*pos), member); \
254  &pos->member != (head); \
255  pos = list_entry(pos->member.next, typeof(*pos), member))
256 
264 #define list_for_each_entry_safe(pos, n, head, member) \
265  for (pos = list_entry((head)->next, typeof(*pos), member), \
266  n = list_entry(pos->member.next, typeof(*pos), member); \
267  &pos->member != (head); \
268  pos = n, n = list_entry(n->member.next, typeof(*n), member))
269 
271 
272 #define WGE100_CAMINFO_LEN 100
273 
274 typedef struct {
275  uint32_t serial;
276 
283  uint32_t hw_version;
284 
291  uint32_t fw_version;
292 
293  char ifName[128]; // FIXME This is so long that we will never hit the limit. (famous last words)
294  uint8_t mac[6];
296  char ip_str[16];
297 
298  IpCamStatus status;
299 
300  struct list_head list;
301 
302  char hwinfo[WGE100_CAMINFO_LEN];
303 
304  char cam_name[CAMERA_NAME_LEN];
305 } IpCamList;
306 
307 int wge100CamListInit( IpCamList *ipCamList );
308 int wge100CamListAdd( IpCamList *ipCamList, IpCamList *newItem);
309 int wge100CamListFind( IpCamList *ipCamList, uint32_t serial);
310 int wge100CamListNumEntries( const IpCamList *ipCamList );
311 IpCamList *wge100CamListGetEntry( const IpCamList *ipCamList, int index );
312 int wge100CamListDelEntry( IpCamList *ipCamList, int index );
313 void wge100CamListDelAll( IpCamList *ipCamList );
314 
315 #define CAMLIST_ADD_OK 0
316 #define CAMLIST_ADD_DUP 1
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 
322 #endif
IpCamList * wge100CamListGetEntry(const IpCamList *ipCamList, int index)
Definition: list.c:123
int wge100CamListAdd(IpCamList *ipCamList, IpCamList *newItem)
Definition: list.c:65
static void __list_splice(struct list_head *list, struct list_head *head)
Definition: list.h:169
struct list_head * next
Definition: list.h:48
static void list_splice_init(struct list_head *list, struct list_head *head)
Definition: list.h:201
IpCamStatus status
Definition: list.h:298
static void list_move(struct list_head *list, struct list_head *head)
Definition: list.h:142
IPAddress ip
Definition: list.h:295
struct list_head * prev
Definition: list.h:48
Definition: list.h:47
int wge100CamListFind(IpCamList *ipCamList, uint32_t serial)
Definition: list.c:96
static void list_del(struct list_head *entry)
Definition: list.h:120
int wge100CamListNumEntries(const IpCamList *ipCamList)
Definition: list.c:171
uint32_t IPAddress
Definition: ipcam_packet.h:74
IpCamStatus
Definition: list.h:270
void wge100CamListDelAll(IpCamList *ipCamList)
Definition: list.c:191
int wge100CamListInit(IpCamList *ipCamList)
Definition: list.c:50
static void list_add_tail(struct list_head *new_item, struct list_head *head)
Definition: list.h:97
static void list_add(struct list_head *new_item, struct list_head *head)
Definition: list.h:84
uint32_t fw_version
Definition: list.h:291
#define WGE100_CAMINFO_LEN
Definition: list.h:272
static int list_empty(struct list_head *head)
Definition: list.h:164
#define CAMERA_NAME_LEN
Definition: ipcam_packet.h:64
static void __list_add(struct list_head *new_item, struct list_head *prev, struct list_head *next)
Definition: list.h:66
static void list_move_tail(struct list_head *list, struct list_head *head)
Definition: list.h:153
uint32_t serial
Definition: list.h:275
static void __list_del(struct list_head *prev, struct list_head *next)
Definition: list.h:109
int wge100CamListDelEntry(IpCamList *ipCamList, int index)
Definition: list.c:146
#define INIT_LIST_HEAD(ptr)
Definition: list.h:56
static void list_del_init(struct list_head *entry)
Definition: list.h:131
uint32_t hw_version
Definition: list.h:283
static void list_splice(struct list_head *list, struct list_head *head)
Definition: list.h:188


wge100_camera
Author(s): Blaise Gassend, Patrick Mihelich, Eric MacIntosh, David Palchak
autogenerated on Mon Jun 10 2019 15:44:15