Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

EchoBehavior Class Reference

Waits for a connection, echos any data received back to the sender. More...

#include <EchoBehavior.h>

Inheritance diagram for EchoBehavior:

Detailed Description

Waits for a connection, echos any data received back to the sender.

Definition at line 9 of file EchoBehavior.h.

List of all members.

Public Member Functions

 EchoBehavior ()
 constructor
 ~EchoBehavior ()
 destructor
virtual void doStart ()
 Delegate function for subclasses to be notified when the behavior starts up.
virtual void doStop ()
 Delegate function for subclasses to be notified when the behavior starts up.
virtual void doEvent ()
 Delegate function for event processing, the event itself is pointed to (only for the duration of the doEvent() call!) by event.
virtual std::string getDescription () const
 Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).

Static Public Member Functions

static int server_callbackT (char *buf, int bytes)
 called by wireless when there's new data
static int client_callbackT (char *buf, int bytes)
 called by wireless when there's new data
static int server_callbackU (char *buf, int bytes)
 called by wireless when there's new data
static int client_callbackU (char *buf, int bytes)
 called by wireless when there's new data
static std::string getClassDescription ()
 Gives a short description of what this class of behaviors does... you should override this (but don't have to).

Static Public Attributes

static EchoBehaviortheOne = NULL
 the singleton object (only one of these objects can be active at a time or they would conflict over ports)
static unsigned short port = 11011
 the port to listen on for incoming UDP and TCP connections

Protected Types

enum  routeIndex_t {
  STCP = 0, SUDP, CTCP, CUDP,
  NUM_ROUTE
}
 

indicates one of the available data sinks: combinations of client/server and TCP/UDP

More...

Protected Member Functions

void setupNetwork ()
 initialize server ports
void teardownNetwork ()
 close open connections
void processCallback (routeIndex_t src, char *buf, int bytes)
 called by one of the wireless callbacks to do processing
void intersect (unsigned char &bits, std::string arg)
 unsets bits of bits which aren't represented by arg

Protected Attributes

class Socketsockets [NUM_ROUTE]
 an array of sockets, one for each incoming or outgoing route
int socks [NUM_ROUTE]
 the system socket number for each of sockets, used to detect when a socket has been closed
bool route [NUM_ROUTE][NUM_ROUTE]
 a table of bools indicating how data should be echoed -- if route[from][to] is set, route it

Static Protected Attributes

static const char *const routeNames [NUM_ROUTE]
 a user-readable name for each incoming or outgoing route

Private Member Functions

 EchoBehavior (const EchoBehavior &)
 don't call (copy constructor)
EchoBehavioroperator= (const EchoBehavior &)
 don't call (assignment operator)

Member Enumeration Documentation

enum EchoBehavior::routeIndex_t [protected]

indicates one of the available data sinks: combinations of client/server and TCP/UDP

Enumerator:
STCP 

server TCP

SUDP 

server UDP

CTCP 

client TCP

CUDP 

client UDP

NUM_ROUTE 

total number of different connections available

Definition at line 46 of file EchoBehavior.h.


Constructor & Destructor Documentation

EchoBehavior::EchoBehavior (  ) 

constructor

Definition at line 19 of file EchoBehavior.h.

EchoBehavior::~EchoBehavior (  ) 

destructor

Definition at line 31 of file EchoBehavior.h.

EchoBehavior::EchoBehavior ( const EchoBehavior  )  [private]

don't call (copy constructor)


Member Function Documentation

int EchoBehavior::client_callbackT ( char *  buf,
int  bytes 
) [static]

called by wireless when there's new data

Definition at line 191 of file EchoBehavior.cc.

Referenced by doEvent().

int EchoBehavior::client_callbackU ( char *  buf,
int  bytes 
) [static]

called by wireless when there's new data

Definition at line 201 of file EchoBehavior.cc.

Referenced by doEvent().

void EchoBehavior::doEvent (  )  [virtual]

Delegate function for event processing, the event itself is pointed to (only for the duration of the doEvent() call!) by event.

Default implementation watches for 'private' text message events (those forwarded by a BehaviorSwitchControl from ControllerGUI input) and will publically rebroadcast them. The idea is that your own processEvent gets first dibs, but if the behavior doesn't handle the text message, it will be handed off for others.

Reimplemented from BehaviorBase.

Definition at line 57 of file EchoBehavior.cc.

void EchoBehavior::doStart (  )  [virtual]

Delegate function for subclasses to be notified when the behavior starts up.

Should be overridden by subclasses to subscribe to events, install motion commands, etc.

doStart() is basically a hook to allow subclasses to jump in and do some customization of behavior parameters while the behavior is starting. If you are writing a behavior class and do not expect further derivation, just override doStart() yourself. However, if you do expect further derivation of your class, consider using preStart() or postStart() instead, and leave doStart() for the 'leaf' classes.

Reimplemented from BehaviorBase.

Definition at line 19 of file EchoBehavior.cc.

void EchoBehavior::doStop (  )  [virtual]

Delegate function for subclasses to be notified when the behavior starts up.

May be overridden to cleanup when the behavior is shutting down. However events will automatically be unsubscribed, and by using addMotion(), motions will automatically be removed by stop(), so you may not need any cleanup.

Reimplemented from BehaviorBase.

Definition at line 25 of file EchoBehavior.cc.

static std::string EchoBehavior::getClassDescription (  )  [static]

Gives a short description of what this class of behaviors does... you should override this (but don't have to).

If you do override this, also consider overriding getDescription() to return it

Reimplemented from BehaviorBase.

Definition at line 37 of file EchoBehavior.h.

Referenced by getDescription().

virtual std::string EchoBehavior::getDescription (  )  const [virtual]

Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).

By default simply returns getName(), because any calls from a BehaviorBase function to getClassDescription() are going to call BehaviorBase::getClassDescription(), not ~YourSubClass~getClassDescription(), because static functions can't be virtual in C++ (doh!)

This means that getDescription called on a pointer to a BehaviorBase of unknown subtype would always return an empty string, which is pretty useless. So instead we return the name in this situation. If you want getDescription to return getClassDescription, you'll have to override it in your subclass to do so.

Reimplemented from BehaviorBase.

Definition at line 42 of file EchoBehavior.h.

void EchoBehavior::intersect ( unsigned char &  bits,
std::string  arg 
) [protected]

unsets bits of bits which aren't represented by arg

Definition at line 146 of file EchoBehavior.cc.

Referenced by doEvent().

EchoBehavior& EchoBehavior::operator= ( const EchoBehavior  )  [private]

don't call (assignment operator)

void EchoBehavior::processCallback ( EchoBehavior::routeIndex_t  src,
char *  buf,
int  bytes 
) [protected]

called by one of the wireless callbacks to do processing

Definition at line 162 of file EchoBehavior.cc.

Referenced by client_callbackT(), client_callbackU(), server_callbackT(), and server_callbackU().

int EchoBehavior::server_callbackT ( char *  buf,
int  bytes 
) [static]

called by wireless when there's new data

Definition at line 186 of file EchoBehavior.cc.

Referenced by setupNetwork().

int EchoBehavior::server_callbackU ( char *  buf,
int  bytes 
) [static]

called by wireless when there's new data

Definition at line 196 of file EchoBehavior.cc.

Referenced by setupNetwork().

void EchoBehavior::setupNetwork (  )  [protected]

initialize server ports

Definition at line 31 of file EchoBehavior.cc.

Referenced by doEvent(), and doStart().

void EchoBehavior::teardownNetwork (  )  [protected]

close open connections

Definition at line 44 of file EchoBehavior.cc.

Referenced by doEvent(), and doStop().


Member Data Documentation

unsigned short EchoBehavior::port = 11011 [static]

the port to listen on for incoming UDP and TCP connections

Definition at line 12 of file EchoBehavior.h.

Referenced by doEvent(), getClassDescription(), and setupNetwork().

bool EchoBehavior::route[NUM_ROUTE][NUM_ROUTE] [protected]

a table of bools indicating how data should be echoed -- if route[from][to] is set, route it

Definition at line 57 of file EchoBehavior.h.

Referenced by doEvent(), EchoBehavior(), and processCallback().

const char *const EchoBehavior::routeNames [static, protected]
Initial value:
 
{
  "TCP Server", "UDP Server","TCP Client","UDP Client"
}

a user-readable name for each incoming or outgoing route

Definition at line 53 of file EchoBehavior.h.

Referenced by doEvent().

class Socket* EchoBehavior::sockets[NUM_ROUTE] [protected]

an array of sockets, one for each incoming or outgoing route

Definition at line 55 of file EchoBehavior.h.

Referenced by doEvent(), EchoBehavior(), processCallback(), setupNetwork(), and teardownNetwork().

int EchoBehavior::socks[NUM_ROUTE] [protected]

the system socket number for each of sockets, used to detect when a socket has been closed

Definition at line 56 of file EchoBehavior.h.

Referenced by doEvent(), EchoBehavior(), processCallback(), setupNetwork(), and teardownNetwork().

the singleton object (only one of these objects can be active at a time or they would conflict over ports)

Definition at line 11 of file EchoBehavior.h.

Referenced by client_callbackT(), client_callbackU(), EchoBehavior(), server_callbackT(), server_callbackU(), and ~EchoBehavior().


The documentation for this class was generated from the following files:

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:07 2016 by Doxygen 1.6.3