00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 // 00003 // Copyright (c) 1997 by the University of Southern California 00004 // All rights reserved. 00005 // 00006 // Permission to use, copy, modify, and distribute this software and its 00007 // documentation in source and binary forms for non-commercial purposes 00008 // and without fee is hereby granted, provided that the above copyright 00009 // notice appear in all copies and that both the copyright notice and 00010 // this permission notice appear in supporting documentation. and that 00011 // any documentation, advertising materials, and other materials related 00012 // to such distribution and use acknowledge that the software was 00013 // developed by the University of Southern California, Information 00014 // Sciences Institute. The name of the University may not be used to 00015 // endorse or promote products derived from this software without 00016 // specific prior written permission. 00017 // 00018 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about 00019 // the suitability of this software for any purpose. THIS SOFTWARE IS 00020 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, 00021 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 00022 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00023 // 00024 // Other copyrights might apply to parts of this software and are so 00025 // noted when applicable. 00026 // 00027 // ADU and ADU processor 00028 // 00029 // $Header: /nfs/jade/vint/CVSROOT/ns-2/common/ns-process.h,v 1.5 2001/11/08 18:12:18 haldar Exp $ 00030 00031 #ifndef ns_process_h 00032 #define ns_process_h 00033 00034 #include <assert.h> 00035 #include <string.h> 00036 #include "config.h" 00037 00038 // Application-level data unit types 00039 enum AppDataType { 00040 // Illegal type 00041 ADU_ILLEGAL, 00042 00043 // Old packet data ADU 00044 PACKET_DATA, 00045 00046 // HTTP ADUs 00047 HTTP_DATA, 00048 HTTP_INVALIDATION, // Heartbeat that may contain invalidation 00049 HTTP_UPDATE, // Pushed page updates (version 1) 00050 HTTP_PROFORMA, // Pro forma sent when a direct request is sent 00051 HTTP_JOIN, 00052 HTTP_LEAVE, 00053 HTTP_PUSH, // Selectively pushed pages 00054 HTTP_NORMAL, // Normal req/resp packets 00055 00056 // TcpApp ADU 00057 TCPAPP_STRING, 00058 00059 // Multimedia ADU 00060 MEDIA_DATA, 00061 MEDIA_REQUEST, 00062 00063 // pub/sub ADU 00064 PUBSUB, 00065 00066 //Diffusion ADU 00067 DIFFUSION_DATA, 00068 00069 // Last ADU 00070 ADU_LAST 00071 00072 }; 00073 00074 // Interface for generic application-level data unit. It should know its 00075 // size and how to make itself persistent. 00076 class AppData { 00077 private: 00078 AppDataType type_; // ADU type 00079 public: 00080 AppData(AppDataType type) { type_ = type; } 00081 AppData(AppData& d) { type_ = d.type_; } 00082 virtual ~AppData() {} 00083 00084 AppDataType type() const { return type_; } 00085 00086 // The following two methods MUST be rewrited for EVERY derived classes 00087 virtual int size() const { return sizeof(AppData); } 00088 virtual AppData* copy() = 0; 00089 }; 00090 00091 // Models any entity that is capable of process an ADU. 00092 // The basic functionality of this entity is to (1) process data, 00093 // (2) pass data to another entity, (3) request data from another entity. 00094 class Process : public TclObject { 00095 public: 00096 Process() : target_(0) {} 00097 inline Process*& target() { return target_; } 00098 00099 // Process incoming data 00100 virtual void process_data(int size, AppData* data); 00101 00102 // Request data from the previous application in the chain 00103 virtual AppData* get_data(int& size, AppData* req_data = 0); 00104 00105 // Send data to the next application in the chain 00106 virtual void send_data(int size, AppData* data = 0) { 00107 if (target_) 00108 target_->process_data(size, data); 00109 } 00110 00111 protected: 00112 virtual int command(int argc, const char*const* argv); 00113 Process* target_; 00114 }; 00115 00116 #endif // ns_process_h
1.3.3