00001 /* 00002 * Copyright (c) Xerox Corporation 1998. All rights reserved. 00003 * 00004 * This program is free software; you can redistribute it and/or modify it 00005 * under the terms of the GNU General Public License as published by the 00006 * Free Software Foundation; either version 2 of the License, or (at your 00007 * option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License along 00015 * with this program; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00017 * 00018 * Linking this file statically or dynamically with other modules is making 00019 * a combined work based on this file. Thus, the terms and conditions of 00020 * the GNU General Public License cover the whole combination. 00021 * 00022 * In addition, as a special exception, the copyright holders of this file 00023 * give you permission to combine this file with free software programs or 00024 * libraries that are released under the GNU LGPL and with code included in 00025 * the standard release of ns-2 under the Apache 2.0 license or under 00026 * otherwise-compatible licenses with advertising requirements (or modified 00027 * versions of such code, with unchanged license). You may copy and 00028 * distribute such a system following the terms of the GNU GPL for this 00029 * file and the licenses of the other code concerned, provided that you 00030 * include the source code of that other code when and as the GNU GPL 00031 * requires distribution of source code. 00032 * 00033 * Note that people who make modified versions of this file are not 00034 * obligated to grant this special exception for their modified versions; 00035 * it is their choice whether to do so. The GNU General Public License 00036 * gives permission to release a modified version without this exception; 00037 * this exception also makes it possible to release a modified version 00038 * which carries forward this exception. 00039 * 00040 * $Header: /cvsroot/nsnam/ns-2/webcache/inval-agent.h,v 1.12 2005/08/26 05:05:31 tomh Exp $ 00041 * 00042 */ 00043 00044 // 00045 // Definition of Agent/Invalidation 00046 // 00047 00048 #ifndef ns_invalagent_h 00049 #define ns_invalagent_h 00050 00051 #include <string.h> 00052 #include <tclcl.h> 00053 #include "config.h" 00054 #include "packet.h" 00055 #include "agent.h" 00056 #include "tcpapp.h" 00057 00058 struct hdr_inval { 00059 int size_; 00060 int& size() { return size_; } 00061 00062 // Header access methods 00063 static int offset_; // required by PacketHeaderManager 00064 inline static int& offset() { return offset_; } 00065 inline static hdr_inval* access(const Packet* p) { 00066 return (hdr_inval*) p->access(offset_); 00067 } 00068 }; 00069 00070 // XXX If we have an interface declaration, we could define a common 00071 // interface for the two implementations below. But in C++ the only way 00072 // to define an interface is through abstract base class, and use 00073 // multiple inheritance to get different implementations with the same 00074 // interface. 00075 // Because multiple inheritance prohibits conversion from 00076 // base class pointer to derived class pointer, and TclObject::lookup 00077 // must do such a conversion, we cannot declare a common interface here. :( 00078 00079 class HttpApp; 00080 00081 // Implementation 1: multicast, this is a real agent 00082 class HttpInvalAgent : public Agent { 00083 public: 00084 HttpInvalAgent(); 00085 00086 virtual void recv(Packet *, Handler *); 00087 virtual void send(int realsize, AppData* data); 00088 00089 protected: 00090 int inval_hdr_size_; 00091 }; 00092 00093 // Implementation 2: unicast, actually an application on top of TCP 00094 class HttpUInvalAgent : public TcpApp { 00095 public: 00096 HttpUInvalAgent(Agent *a) : TcpApp(a) {} 00097 00098 void send(int realsize, AppData* data) { 00099 TcpApp::send(realsize, data); 00100 } 00101 virtual void process_data(int size, AppData* data); 00102 virtual AppData* get_data(int&, AppData*) { 00103 abort(); 00104 return NULL; 00105 } 00106 protected: 00107 virtual int command(int argc, const char*const* argv); 00108 }; 00109 00110 #endif // ns_invalagent_h