Tekkotsu 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 //! destructor 00031 ~EchoBehavior() { theOne=NULL; } 00032 00033 virtual void DoStart(); 00034 virtual void DoStop(); 00035 virtual void processEvent(const EventBase& e); 00036 00037 static std::string getClassDescription() { 00038 char tmp[20]; 00039 sprintf(tmp,"%d",port); 00040 return std::string("Waits for a connection, echos any data received back to the sender, using port ")+tmp; 00041 } 00042 virtual std::string getDescription() const { return getClassDescription(); } 00043 00044 protected: 00045 //! indicates one of the available data sinks: combinations of client/server and TCP/UDP 00046 enum routeIndex_t { 00047 STCP=0, //!< server TCP 00048 SUDP, //!< server UDP 00049 CTCP, //!< client TCP 00050 CUDP, //!< client UDP 00051 NUM_ROUTE //!< total number of different connections available 00052 }; 00053 static const char * const routeNames[NUM_ROUTE]; //!< a user-readable name for each incoming or outgoing route 00054 00055 class Socket * sockets[NUM_ROUTE]; //!< an array of sockets, one for each incoming or outgoing route 00056 int socks[NUM_ROUTE]; //!< the system socket number for each of #sockets, used to detect when a socket has been closed 00057 bool route[NUM_ROUTE][NUM_ROUTE]; //!< a table of bools indicating how data should be echoed -- if route[from][to] is set, route it 00058 void setupNetwork(); //!< initialize server ports 00059 void teardownNetwork(); //!< close open connections 00060 void processCallback(routeIndex_t src, char * buf, int bytes); //!< called by one of the wireless callbacks to do processing 00061 void intersect(unsigned char& bits, std::string arg); //!< unsets bits of @a bits which aren't represented by @a arg 00062 00063 private: 00064 // Providing declarations for these functions will avoid a compiler warning if 00065 // you have any class members which are pointers. However, as it is, an error 00066 // will result if you inadvertantly cause a call to either (which is probably 00067 // a good thing, unless you really intended to copy/assign a behavior, in 00068 // which case simply provide implementations for the functions) 00069 EchoBehavior(const EchoBehavior&); //!< don't call (copy constructor) 00070 EchoBehavior& operator=(const EchoBehavior&); //!< don't call (assignment operator) 00071 }; 00072 00073 /*! @file 00074 * @brief Defines EchoBehavior, which waits for a connection, echos any data received back to the sender 00075 * @author Ethan Tira-Thompson (ejt) (Creator) 00076 * 00077 * $Author: ejt $ 00078 * $Name: tekkotsu-4_0 $ 00079 * $Revision: 1.4 $ 00080 * $State: Exp $ 00081 * $Date: 2006/09/16 06:28:07 $ 00082 */ 00083 00084 #endif |
Tekkotsu v4.0 |
Generated Thu Nov 22 00:54:52 2007 by Doxygen 1.5.4 |