Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
EchoBehavior.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_EchoBehavior_h_ 00003 #define INCLUDED_EchoBehavior_h_ 00004 00005 #include "Behaviors/BehaviorBase.h" 00006 #include "Events/EventRouter.h" 00007 00008 //! Waits for a connection, echos any data received back to the sender 00009 class EchoBehavior : public BehaviorBase { 00010 public: 00011 static EchoBehavior * theOne; //!< the singleton object (only one of these objects can be active at a time or they would conflict over ports) 00012 static unsigned short port; //! the port to listen on for incoming UDP and TCP connections 00013 static int server_callbackT(char *buf, int bytes); //!< called by wireless when there's new data 00014 static int client_callbackT(char *buf, int bytes); //!< called by wireless when there's new data 00015 static int server_callbackU(char *buf, int bytes); //!< called by wireless when there's new data 00016 static int client_callbackU(char *buf, int bytes); //!< called by wireless when there's new data 00017 00018 //! constructor 00019 EchoBehavior() 00020 : BehaviorBase("EchoBehavior") 00021 { 00022 theOne=this; 00023 bzero((char*)route,sizeof(route)); 00024 for(unsigned int i=0; i<NUM_ROUTE; i++) { 00025 sockets[i]=NULL; 00026 socks[i]=-1; 00027 route[i][i]=true; 00028 } 00029 } 00030 ~EchoBehavior() { theOne=NULL; } 00031 00032 virtual void DoStart(); 00033 virtual void DoStop(); 00034 virtual void processEvent(const EventBase& e); 00035 00036 static std::string getClassDescription() { 00037 char tmp[20]; 00038 sprintf(tmp,"%d",port); 00039 return std::string("Waits for a connection, echos any data received back to the sender, using port ")+tmp; 00040 } 00041 virtual std::string getDescription() const { return getClassDescription(); } 00042 00043 protected: 00044 enum routeIndex_t { 00045 STCP=0, //!< server TCP 00046 SUDP, //!< server UDP 00047 CTCP, //!< client TCP 00048 CUDP, //!< client UDP 00049 NUM_ROUTE //!< total number of different connections available 00050 }; 00051 static const char * const routeNames[NUM_ROUTE]; //!< a user-readable name for each incoming or outgoing route 00052 00053 class Socket * sockets[NUM_ROUTE]; //!< an array of sockets, one for each incoming or outgoing route 00054 int socks[NUM_ROUTE]; //!< the system socket number for each of #sockets, used to detect when a socket has been closed 00055 bool route[NUM_ROUTE][NUM_ROUTE]; //!< a table of bools indicating how data should be echoed -- if route[from][to] is set, route it 00056 void setupNetwork(); //!< initialize server ports 00057 void teardownNetwork(); //!< close open connections 00058 void processCallback(routeIndex_t src, char * buf, int bytes); //!< called by one of the wireless callbacks to do processing 00059 void intersect(unsigned char& bits, std::string arg); //!< unsets bits of @a bits which aren't represented by @a arg 00060 00061 private: 00062 // Providing declarations for these functions will avoid a compiler warning if 00063 // you have any class members which are pointers. However, as it is, an error 00064 // will result if you inadvertantly cause a call to either (which is probably 00065 // a good thing, unless you really intended to copy/assign a behavior, in 00066 // which case simply provide implementations for the functions) 00067 EchoBehavior(const EchoBehavior&); //!< don't call (copy constructor) 00068 EchoBehavior& operator=(const EchoBehavior&); //!< don't call (assignment operator) 00069 }; 00070 00071 /*! @file 00072 * @brief Defines EchoBehavior, which waits for a connection, echos any data received back to the sender 00073 * @author Ethan Tira-Thompson (ejt) (Creator) 00074 * 00075 * $Author: ejt $ 00076 * $Name: tekkotsu-2_4_1 $ 00077 * $Revision: 1.3 $ 00078 * $State: Exp $ 00079 * $Date: 2005/08/07 04:11:03 $ 00080 */ 00081 00082 #endif |
Tekkotsu v2.4.1 |
Generated Tue Aug 16 16:32:46 2005 by Doxygen 1.4.4 |