EchoBehavior.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_EchoBehavior_h_
00003 #define INCLUDED_EchoBehavior_h_
00004
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Events/EventRouter.h"
00007
00008
00009 class EchoBehavior : public BehaviorBase {
00010 public:
00011 static EchoBehavior * theOne;
00012 static unsigned short port;
00013 static int server_callbackT(char *buf, int bytes);
00014 static int client_callbackT(char *buf, int bytes);
00015 static int server_callbackU(char *buf, int bytes);
00016 static int client_callbackU(char *buf, int bytes);
00017
00018
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
00031 ~EchoBehavior() { theOne=NULL; }
00032
00033 virtual void doStart();
00034 virtual void doStop();
00035 virtual void doEvent();
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
00046 enum routeIndex_t {
00047 STCP=0,
00048 SUDP,
00049 CTCP,
00050 CUDP,
00051 NUM_ROUTE
00052 };
00053 static const char * const routeNames[NUM_ROUTE];
00054
00055 class Socket * sockets[NUM_ROUTE];
00056 int socks[NUM_ROUTE];
00057 bool route[NUM_ROUTE][NUM_ROUTE];
00058 void setupNetwork();
00059 void teardownNetwork();
00060 void processCallback(routeIndex_t src, char * buf, int bytes);
00061 void intersect(unsigned char& bits, std::string arg);
00062
00063 private:
00064
00065
00066
00067
00068
00069 EchoBehavior(const EchoBehavior&);
00070 EchoBehavior& operator=(const EchoBehavior&);
00071 };
00072
00073
00074
00075
00076
00077
00078 #endif