Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdlib.h>
00040 #include "wge100_camera/list.h"
00041 #include "wge100_camera/host_netutil.h"
00042
00050 int wge100CamListInit( IpCamList *ipCamList ) {
00051 INIT_LIST_HEAD(&ipCamList->list);
00052 return 0;
00053 }
00054
00055
00065 int wge100CamListAdd( IpCamList *ipCamList, IpCamList *newItem) {
00066 IpCamList *listIterator;
00067
00068 int isInList = 0;
00069
00070
00071 list_for_each_entry(listIterator, &(ipCamList->list), list) {
00072 if( newItem->serial == listIterator->serial) {
00073
00074 isInList = 1;
00075 break;
00076 }
00077 }
00078
00079 if(isInList == 1) {
00080 wge100_debug("Serial number %d already exists in list, dropping.\n", newItem->serial);
00081 return CAMLIST_ADD_DUP;
00082 } else {
00083 wge100_debug("Serial number %d is new, adding to list.\n", newItem->serial);
00084 list_add_tail( &(newItem->list), &(ipCamList->list) );
00085 return CAMLIST_ADD_OK;
00086 }
00087
00088 }
00089
00096 int wge100CamListFind( IpCamList *ipCamList, uint32_t serial ) {
00097 int count;
00098
00099 IpCamList *listIterator;
00100 count = 0;
00101
00102 list_for_each_entry(listIterator, &(ipCamList->list), list) {
00103 if(listIterator->serial == serial) {
00104 return count;
00105 }
00106 count++;
00107 }
00108
00109 return -1;
00110 }
00111
00123 IpCamList *wge100CamListGetEntry( const IpCamList *ipCamList, int index ) {
00124 IpCamList *listIterator;
00125
00126
00127 list_for_each_entry(listIterator, &(ipCamList->list), list) {
00128 if(index-- == 0) {
00129 break;
00130 }
00131 }
00132
00133 return listIterator;
00134 }
00135
00146 int wge100CamListDelEntry( IpCamList *ipCamList, int index ) {
00147 int count;
00148
00149 IpCamList *tmpListItem;
00150 struct list_head *pos, *q;
00151 count = 0;
00152
00153 list_for_each_safe(pos, q,&(ipCamList->list)) {
00154 if(count++ == index) {
00155 tmpListItem = list_entry(pos, IpCamList, list);
00156 list_del(pos);
00157 free(tmpListItem);
00158 return 0;
00159 }
00160 }
00161 return -1;
00162 }
00163
00171 int wge100CamListNumEntries( const IpCamList *ipCamList ) {
00172 int count;
00173
00174 IpCamList *listIterator;
00175 count = 0;
00176
00177 list_for_each_entry(listIterator, &(ipCamList->list), list) {
00178 count++;
00179 }
00180
00181 return count;
00182 }
00183
00191 void wge100CamListDelAll( IpCamList *ipCamList ) {
00192 int count;
00193
00194 IpCamList *tmpListItem;
00195 struct list_head *pos, *q;
00196 count = 0;
00197
00198 list_for_each_safe(pos, q,&(ipCamList->list)) {
00199 tmpListItem = list_entry(pos, IpCamList, list);
00200 list_del(pos);
00201 free(tmpListItem);
00202 }
00203 }