00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 00003 /* 00004 * ns-process.h 00005 * Copyright (C) 1997 by the University of Southern California 00006 * $Id: ns-process.h,v 1.6 2005/08/25 18:58:02 johnh 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 * 00022 * The copyright of this module includes the following 00023 * linking-with-specific-other-licenses addition: 00024 * 00025 * In addition, as a special exception, the copyright holders of 00026 * this module give you permission to combine (via static or 00027 * dynamic linking) this module with free software programs or 00028 * libraries that are released under the GNU LGPL and with code 00029 * included in the standard release of ns-2 under the Apache 2.0 00030 * license or under otherwise-compatible licenses with advertising 00031 * requirements (or modified versions of such code, with unchanged 00032 * license). You may copy and distribute such a system following the 00033 * terms of the GNU GPL for this module and the licenses of the 00034 * other code concerned, provided that you include the source code of 00035 * that other code when and as the GNU GPL requires distribution of 00036 * source code. 00037 * 00038 * Note that people who make modified versions of this module 00039 * are not obligated to grant this special exception for their 00040 * modified versions; it is their choice whether to do so. The GNU 00041 * General Public License gives permission to release a modified 00042 * version without this exception; this exception also makes it 00043 * possible to release a modified version which carries forward this 00044 * exception. 00045 * 00046 */ 00047 00048 // ADU and ADU processor 00049 // 00050 // $Header: /cvsroot/nsnam/ns-2/common/ns-process.h,v 1.6 2005/08/25 18:58:02 johnh Exp $ 00051 00052 #ifndef ns_process_h 00053 #define ns_process_h 00054 00055 #include <assert.h> 00056 #include <string.h> 00057 #include "config.h" 00058 00059 // Application-level data unit types 00060 enum AppDataType { 00061 // Illegal type 00062 ADU_ILLEGAL, 00063 00064 // Old packet data ADU 00065 PACKET_DATA, 00066 00067 // HTTP ADUs 00068 HTTP_DATA, 00069 HTTP_INVALIDATION, // Heartbeat that may contain invalidation 00070 HTTP_UPDATE, // Pushed page updates (version 1) 00071 HTTP_PROFORMA, // Pro forma sent when a direct request is sent 00072 HTTP_JOIN, 00073 HTTP_LEAVE, 00074 HTTP_PUSH, // Selectively pushed pages 00075 HTTP_NORMAL, // Normal req/resp packets 00076 00077 // TcpApp ADU 00078 TCPAPP_STRING, 00079 00080 // Multimedia ADU 00081 MEDIA_DATA, 00082 MEDIA_REQUEST, 00083 00084 // pub/sub ADU 00085 PUBSUB, 00086 00087 //Diffusion ADU 00088 DIFFUSION_DATA, 00089 00090 // Last ADU 00091 ADU_LAST 00092 00093 }; 00094 00095 // Interface for generic application-level data unit. It should know its 00096 // size and how to make itself persistent. 00097 class AppData { 00098 private: 00099 AppDataType type_; // ADU type 00100 public: 00101 AppData(AppDataType type) { type_ = type; } 00102 AppData(AppData& d) { type_ = d.type_; } 00103 virtual ~AppData() {} 00104 00105 AppDataType type() const { return type_; } 00106 00107 // The following two methods MUST be rewrited for EVERY derived classes 00108 virtual int size() const { return sizeof(AppData); } 00109 virtual AppData* copy() = 0; 00110 }; 00111 00112 // Models any entity that is capable of process an ADU. 00113 // The basic functionality of this entity is to (1) process data, 00114 // (2) pass data to another entity, (3) request data from another entity. 00115 class Process : public TclObject { 00116 public: 00117 Process() : target_(0) {} 00118 inline Process*& target() { return target_; } 00119 00120 // Process incoming data 00121 virtual void process_data(int size, AppData* data); 00122 00123 // Request data from the previous application in the chain 00124 virtual AppData* get_data(int& size, AppData* req_data = 0); 00125 00126 // Send data to the next application in the chain 00127 virtual void send_data(int size, AppData* data = 0) { 00128 if (target_) 00129 target_->process_data(size, data); 00130 } 00131 00132 protected: 00133 virtual int command(int argc, const char*const* argv); 00134 Process* target_; 00135 }; 00136 00137 #endif // ns_process_h