• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/diffusion3/lib/main/filter.hh

00001 // 
00002 // filter.hh     : Filter definitions
00003 // authors       : Fabio Silva
00004 //
00005 // Copyright (C) 2000-2003 by the University of Southern California
00006 // $Id: filter.hh,v 1.9 2005/09/13 04:53:49 tomh Exp $
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License,
00010 // version 2, as published by the Free Software Foundation.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License along
00018 // with this program; if not, write to the Free Software Foundation, Inc.,
00019 // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00020 //
00021 // Linking this file statically or dynamically with other modules is making
00022 // a combined work based on this file.  Thus, the terms and conditions of
00023 // the GNU General Public License cover the whole combination.
00024 //
00025 // In addition, as a special exception, the copyright holders of this file
00026 // give you permission to combine this file with free software programs or
00027 // libraries that are released under the GNU LGPL and with code included in
00028 // the standard release of ns-2 under the Apache 2.0 license or under
00029 // otherwise-compatible licenses with advertising requirements (or modified
00030 // versions of such code, with unchanged license).  You may copy and
00031 // distribute such a system following the terms of the GNU GPL for this
00032 // file and the licenses of the other code concerned, provided that you
00033 // include the source code of that other code when and as the GNU GPL
00034 // requires distribution of source code.
00035 //
00036 // Note that people who make modified versions of this file are not
00037 // obligated to grant this special exception for their modified versions;
00038 // it is their choice whether to do so.  The GNU General Public License
00039 // gives permission to release a modified version without this exception;
00040 // this exception also makes it possible to release a modified version
00041 // which carries forward this exception.
00042 
00043 #ifndef _FILTER_HH_
00044 #define _FILTER_HH_
00045 
00046 #ifdef HAVE_CONFIG_H
00047 #include "config.h"
00048 #endif // HAVE_CONFIG_H
00049 
00050 #include <sys/time.h>
00051 #include <unistd.h>
00052 #include <list>
00053 
00054 #include "message.hh"
00055 
00056 using namespace std;
00057 
00058 // Filter priority definitions
00059 #define FILTER_ZERO_PRIORITY 0
00060 #define FILTER_MIN_PRIORITY 1
00061 #define FILTER_MAX_PRIORITY 254
00062 #define FILTER_KEEP_PRIORITY 255
00063 #define FILTER_INVALID_PRIORITY 256
00064 
00065 // The following definitions should help people pick a priority when
00066 // writing filters.
00067 
00068 // If a filter is a pre-processing filter (e.g. logging) which should
00069 // receive messages before they get to a routing protocol, it should
00070 // have a priority between FILTER_MAX_PRIORITY and
00071 // PRE_PROCESSING_COMPLETED_PRIORITY.
00072 
00073 #define PRE_PROCESSING_COMPLETED_PRIORITY 200
00074 
00075 // Filters implementing routing protocols, should have a priority
00076 // between PRE_PROCESSING_COMPLETED_PRIORITY and
00077 // ROUTING_COMPLETED_PRIORITY.
00078 
00079 #define ROUTING_COMPLETED_PRIORITY 50
00080 
00081 // If a filter is a post-processing filter, it should use a priority
00082 // between ROUTING_COMPLETED_PRIORITY and FILTER_MIN_PRIORITY.
00083 
00084 class FilterEntry;
00085 class FilterCallback;
00086 
00087 typedef list<FilterEntry *> FilterList;
00088 typedef long handle;
00089 
00090 class FilterEntry {
00091 public:
00092   NRAttrVec *filter_attrs_;
00093   int16_t handle_;
00094   u_int16_t priority_;
00095   u_int16_t agent_;
00096   FilterCallback *cb_;
00097   struct timeval tmv_;
00098   bool valid_;
00099    
00100   FilterEntry(int16_t handle, u_int16_t priority, u_int16_t agent) :
00101     handle_(handle), priority_(priority), agent_(agent)
00102   {
00103     valid_ = true;
00104     cb_ = NULL;
00105     GetTime(&tmv_);
00106   }
00107 
00108   ~FilterEntry()
00109   {
00110     if (filter_attrs_){
00111       ClearAttrs(filter_attrs_);
00112       delete filter_attrs_;
00113     }
00114   }
00115 };
00116 
00117 class FilterCallback {
00118 public:
00119   virtual ~FilterCallback () {}
00120   virtual void recv(Message *msg, handle h) = 0;
00121 };
00122 
00123 #endif // !_FILTER_HH_

Generated on Tue Aug 10 2010 16:16:06 for ns-2.33 by  doxygen 1.7.1