Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

connlist.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright 2005 Daniel Ferullo                                             *
00003  *                                                                           *
00004  * Licensed under the Apache License, Version 2.0 (the "License");           *
00005  * you may not use this file except in compliance with the License.          *
00006  * You may obtain a copy of the License at                                   *
00007  *                                                                           *
00008  *    http://www.apache.org/licenses/LICENSE-2.0                             *
00009  *                                                                           *
00010  * Unless required by applicable law or agreed to in writing, software       *
00011  * distributed under the License is distributed on an "AS IS" BASIS,         *
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
00013  * See the License for the specific language governing permissions and       *
00014  * limitations under the License.                                            *
00015  *                                                                           *
00016  *****************************************************************************/
00017 
00018 /**
00019  * @file connlist.h
00020  * @author Daniel Ferullo (ferullo@cmu.edu)
00021  *
00022  * @brief contains prototypes for connection list functions
00023  *
00024  * These functions are wrappers for the list.h functions.  They provide
00025  * abstraction and thread-safety
00026  */
00027 
00028 #ifndef __CONNLIST_H__
00029 #define __CONNLIST_H__
00030 
00031 #include "helperdef.h"
00032 #include "list.h"
00033 
00034 /** @brief structure for a single connection node */
00035 struct connlist_item {
00036         /** @brief the helper connection strucure */
00037         helper_conn_info_t info;
00038         /** @brief the data observed in the packets */
00039         observed_data_t obs_data;
00040         /** @brief the number of threads accessing this item */
00041         long watchers;
00042 } __attribute__((packed));
00043 
00044 /** @brief typedef for the connlist_item structure */
00045 typedef struct connlist_item connlist_item_t;
00046 
00047 /** @brief structure for the connlist_t type */
00048 struct connlist {
00049         /** @brief the pre-existing list type */
00050         list_t list;
00051         /** @brief the mutex to provide thread safety */
00052         pthread_mutex_t mutex;
00053 } __attribute__((packed));
00054 
00055 /** @brief typedef for the connlist structure */
00056 typedef struct connlist connlist_t;
00057 
00058 /**
00059  * @brief the function to initialize the list
00060  *
00061  * @param list pointer to an allocaed list container
00062  *
00063  * @return SUCCESS, errorcode on failure
00064  */
00065 errorcode connlist_init(connlist_t *list);
00066 
00067 /**
00068  * @brief the function to add an item to the list
00069  *
00070  * This function is thread safe.  forget must be called once for this function
00071  * to remove the item from the list once it has been added.
00072  *
00073  * @param list pointer to the connlist_t list
00074  * @param item pointer to the item to add
00075  *
00076  * @return SUCCESS, errorcode on failure
00077  */
00078 errorcode connlist_add(connlist_t *list, connlist_item_t *item);
00079 
00080 /**
00081  * @brief finds an item in the list
00082  *
00083  * This function is thread safe
00084  *
00085  * @param list pointer to the connlist_t list
00086  * @param func function pointer to use in find matching.  Function must meet
00087  *        requirements specified for function list_find in list.h
00088  * @param arg the one optional argument passed into the func function
00089  * @param found_item pointer to a void* to fill in with the found item.  On
00090  *        error this value is undefined.
00091  *
00092  * @return SUCCESS, errorcode on failure
00093  */
00094 errorcode connlist_find(connlist_t *list, int (*func)(void*,void*), void *arg,
00095                         connlist_item_t **found_item);
00096 
00097 /**
00098  * @brief the function to find a predictied port match (used as a match
00099  * function for the list implementation).
00100  *
00101  * @param this_item the item from the list to check (a connlist_item_t pointer)
00102  * @param find_item the values to match on (an observed_data_t pointer)
00103  *
00104  * @return LIST_FATAL, LIST_FOUND, LIST_NOT_FOUND, as per requirements
00105  */
00106 int connlist_find_pred_port(void *this_item, void *find_item);
00107 
00108 
00109 /**
00110  * @brief the function to find a buddy match (used as a match function for
00111  * the list implementation).
00112  *
00113  * @param this_item the item from the list to check (a connlist_item_t pointer)
00114  * @param find_item the values to match on (a buddy_info_t pointer)
00115  *
00116  * @return LIST_FATAL, LIST_FOUND, LIST_NOT_FOUND, as per requirements
00117  */
00118 int connlist_find_buddy(void *this_item, void *find_item);
00119 
00120 /**
00121  * @brief the function to remove an item from the list
00122  *
00123  * This function is thread safe.
00124  *
00125  * This function will only remove the item if there are no watchers left. It
00126  * must be called exactly once for each time find is called, plus once more
00127  * for the add call.
00128  *
00129  * @param list a pointer to the list to remove from
00130  * @param func the function to use in matching for the forget
00131  * @param item a pointer to the item to remove
00132  *
00133  * @return SUCCESS, errorcode on failure
00134  */
00135 errorcode connlist_forget(connlist_t *list,
00136                           int (*func)(void*,void*), connlist_item_t *item);
00137 
00138 /**
00139  * @brief the matching function for an item in the list
00140  *
00141  * @param this_item a pointer to the current item in the list (will be cast to
00142  *        a connlist_t pointer)
00143  * @param find_item a pointer to the item to find (will be cast to a
00144  *        connlist_item_t pointer)
00145  *
00146  * @return LIST_FATAL, LIST_FOUND, LIST_NOT_FOUND as list.h requires
00147  */
00148 int connlist_item_match(void *this_item, void *find_item);
00149 
00150 /**
00151  * @brief gets the number of items in the list
00152  *
00153  * This function is thread safe
00154  *
00155  * @param list pointer to the connlist
00156  *
00157  * @return the number of elements, negative on error
00158  */
00159 int connlist_count(connlist_t *list);
00160 
00161 #endif /* __CONNLIST_H__ */
00162 

Generated on Wed Mar 30 23:20:47 2005 for NATBLASTER by  doxygen 1.3.9.1