list.c
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2009, 2010 Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /*
00036  * @file list.c
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         // Scan through the list, looking for a serial number that matches the one we're trying to add
00071         list_for_each_entry(listIterator, &(ipCamList->list), list) {
00072                 if( newItem->serial == listIterator->serial) {
00073                         // This camera is already in the list
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         // Iterate through the list until we have counted off 'index' entries
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 }


wge100_camera
Author(s): Blaise Gassend, Patrick Mihelich, Eric MacIntosh, David Palchak
autogenerated on Fri Jan 3 2014 12:16:00