Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Wireless Class Reference

Tekkotsu wireless class. More...

#include <Wireless.h>


Detailed Description

Tekkotsu wireless class.

For more information on using wireless, please read the following tutorials:

The networking interface needs more documentation. It also needs a cleanup. In the mean time, take a look at the TekkotsuMon objects in Tekkotsu/Behaviors/Mon. They all listen for new connections. Unfortunately, at the momement there are no examples of outgoing connections, but it should give you a pretty good idea how to start moving.

Definition at line 35 of file Wireless.h.

List of all members.

Public Member Functions

 Wireless ()
 constructor - only one wireless object is required per Aperios process.
 ~Wireless ()
 destructor
int listen (int sock, int port)
 The socket waits for incoming connections.
int connect (int sock, const char *ipaddr, int port)
 The socket tries to connect to a specific.
void setReceiver (int sock, int(*rcvcbckfn)(char *, int))
 sets receiver callback for a socket
void setReceiver (int sock, SocketListener *listener)
 sets receiver callback for a socket, this version requiring the SocketListener interface (more powerful, as this lets us tell connections apart)
void setDaemon (int sock, bool val=true)
 sets the socket to be a daemon (recycles on close)
bool getDaemon (int sock)
 sets the socket to be a daemon (recycles on close)
void close (int sock)
 closes and destroys non server, daemon sockets
void pollSetup ()
 on non-aperios, set up structures to be checked in pollTest()
bool pollTest (struct timeval *tv)
 on non-aperios, check to see any network communication has occurred
void pollProcess ()
 on non-aperios, process callbacks and state changes as signaled in pollTest()
void wakeup (Socket *del=NULL)
 writes del on interruptCtl, breaking out of a pending pollTest() and thus giving an opportunity to change the contents of the FD sets being used;
void setCallbackLock (Resource &l)
 sets callbackLock
void clearCallbackLock ()
 resets callbackLock to a self-defined lock, which you can request from getCallbackLock() (there's always a callbackLock, the only question is it internally or externally instantiated)
ResourcegetCallbackLock () const
 returns callbackLock

Socketsocket (Socket::TransportType_t ttype)
 Creates a new socket.
Socketsocket (Socket::TransportType_t ttype, int recvsize, int sendsize)

bool isConnected (int sock)
 utility function that you can use if you're curious about the state of the socket.
bool isError (int sock)
 utility function that you can use if you're curious about the state of the socket.
bool isReady (int sock)
 utility function that you can use if you're curious about the state of the socket.
bool hasData (int sock)
 utility function that you can use if you're curious about the state of the socket.

void setReceiver (Socket &sobj, int(*rcvcbckfn)(char *, int))
 helper function for the function with the same name that takes a socket descriptor (int)
void setReceiver (Socket *sobj, int(*rcvcbckfn)(char *, int))
 helper function for the function with the same name that takes a socket descriptor (int)
void setReceiver (Socket &sobj, SocketListener *listener)
 helper function for the function with the same name that takes a socket descriptor (int)
void setReceiver (Socket *sobj, SocketListener *listener)
 helper function for the function with the same name that takes a socket descriptor (int)
void setDaemon (Socket &sobj, bool val=true)
 helper function for the function with the same name that takes a socket descriptor (int)
void setDaemon (Socket *sobj, bool val=true)
 helper function for the function with the same name that takes a socket descriptor (int)
bool getDaemon (Socket &sobj)
 helper function for the function with the same name that takes a socket descriptor (int)
bool getDaemon (Socket *sobj)
 helper function for the function with the same name that takes a socket descriptor (int)
int listen (Socket &sobj, int port)
 helper function for the function with the same name that takes a socket descriptor (int)
int listen (Socket *sobj, int port)
 helper function for the function with the same name that takes a socket descriptor (int)
int connect (Socket &sobj, const char *ipaddr, int port)
 helper function for the function with the same name that takes a socket descriptor (int)
int connect (Socket *sobj, const char *ipaddr, int port)
 helper function for the function with the same name that takes a socket descriptor (int)
void close (Socket &sobj)
 helper function for the function with the same name that takes a socket descriptor (int)
void close (Socket *sobj)
 helper function for the function with the same name that takes a socket descriptor (int)
unsigned int getNumInterfaces ()
 helper function for the function with the same name that takes a socket descriptor (int)
uint32 getIPAddress (unsigned int idx=0)
uint32 getIFAddress (const char *)
 helper function for the function with the same name that takes a socket descriptor (int)

void receive (int sock, int(*rcvcbckfn)(char *, int))
 function for internal and Socket use. You should not call this
void receive (int sock)
 function for internal and Socket use. You should not call this

void send (int sock)
void blockingSend (int sock)

Static Public Attributes

static const int WIRELESS_MAX_SOCKETS = 100
 Maximum number of sockets which can be created.
static const int WIRELESS_DEF_RECV_SIZE = 1024
 Default number of bytes to use for receive buffers (overridden by value passed to socket()).
static const int WIRELESS_DEF_SEND_SIZE = 1024
 Default number of bytes to use for send buffers (overridden by value passed to socket()).

Static Protected Attributes

static const int MAXCONNECTIONS = 5
 the maximum number of connections which can be queued when listening

Private Member Functions

 Wireless (const Wireless &)
 don't call
Wirelessoperator= (const Wireless &)
 don't call

Friends

class Socket



ResourcecallbackLock
 this lock will be aquired during any callbacks which might occur during pollProcess()
int interruptChk
 a socket, connected to interruptCtl, which allows pollTest() to be interrupted if new sockets need to be polled
int interruptCtl
 a socket, connected to interruptChk, which allows pollTest() to be interrupted if new sockets need to be polled
fd_set rfds
 a set of file descriptors which should be polled for readable data; set up by pollSetup(), watched (blocking) by pollTest(), and processed by pollProcess()
fd_set wfds
 a set of file descriptors which should be polled for write-complete; set up by pollSetup(), watched (blocking) by pollTest(), and processed by pollProcess()
fd_set efds
 a set of file descriptors which should be polled for errors; set up by pollSetup(), watched (blocking) by pollTest(), and processed by pollProcess()
int fdsMax
 maximum file descriptor value in the rfds, wfds, efds fd_set's
Socketsockets [WIRELESS_MAX_SOCKETS]
 this lock will be aquired during any callbacks which might occur during pollProcess()
std::list< int > freeSockets
 this lock will be aquired during any callbacks which might occur during pollProcess()
std::list< int > usedSockets
 this lock will be aquired during any callbacks which might occur during pollProcess()
bool usedSocketsInvalidated
 set to true at modifcation of usedSockets, cleared prior to callbacks so we can tell if callback invalidates active iterators
static ResourcegetLock ()
 private ALOKL_TODO

Constructor & Destructor Documentation

Wireless::Wireless (  ) 

constructor - only one wireless object is required per Aperios process.

MMCombo already creates one. The (global) instance is called wireless, and you can access it by including Wireless/Wireless.h (this file) in your code

Definition at line 645 of file Wireless.cc.

Wireless::~Wireless (  ) 

destructor

Definition at line 667 of file Wireless.cc.

Wireless::Wireless ( const Wireless  )  [private]

don't call


Member Function Documentation

void Wireless::blockingSend ( int  sock  ) 

function called by the Socket objects to actually write data to the network. You should not call this.

Definition at line 887 of file Wireless.cc.

Referenced by Socket::flush().

void Wireless::clearCallbackLock (  ) 

resets callbackLock to a self-defined lock, which you can request from getCallbackLock() (there's always a callbackLock, the only question is it internally or externally instantiated)

Definition at line 1188 of file Wireless.cc.

void Wireless::close ( Socket sobj  ) 

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 127 of file Wireless.h.

Referenced by close().

void Wireless::close ( Socket sobj  ) 

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 126 of file Wireless.h.

Referenced by close().

int Wireless::connect ( Socket sobj,
const char *  ipaddr,
int  port 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 124 of file Wireless.h.

Referenced by connect().

int Wireless::connect ( Socket sobj,
const char *  ipaddr,
int  port 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 122 of file Wireless.h.

Referenced by connect().

int Wireless::connect ( int  sock,
const char *  ipaddr,
int  port 
)

The socket tries to connect to a specific.

Definition at line 723 of file Wireless.cc.

Referenced by RemoteRouter::connect(), EchoBehavior::doEvent(), pollProcess(), EchoBehavior::processCallback(), and KoduDiscover::processEvent().

Resource& Wireless::getCallbackLock (  )  const

returns callbackLock

Definition at line 166 of file Wireless.h.

Referenced by pollProcess(), and setCallbackLock().

bool Wireless::getDaemon ( Socket sobj  ) 

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 119 of file Wireless.h.

Referenced by getDaemon().

bool Wireless::getDaemon ( Socket sobj  ) 

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 118 of file Wireless.h.

Referenced by getDaemon().

bool Wireless::getDaemon ( int  sock  ) 

sets the socket to be a daemon (recycles on close)

Definition at line 86 of file Wireless.h.

uint32 Wireless::getIFAddress ( const char *  interface  ) 

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 1192 of file Wireless.cc.

Referenced by KoduDiscover::KoduDiscover().

uint32 Wireless::getIPAddress ( unsigned int  idx = 0  ) 

There's probably better ways to implement this... (run through the interface list? How does ifconfig do it?)

Definition at line 832 of file Wireless.cc.

Referenced by FlashIPAddrBehavior::setupSequence().

Resource & Wireless::getLock (  )  [static, protected]

private ALOKL_TODO

returns the lock to use during all wireless operations (not just callbacks, this is more general)

Definition at line 1178 of file Wireless.cc.

Referenced by blockingSend(), close(), connect(), Socket::flush(), Socket::getWriteBuffer(), Socket::init(), listen(), pollProcess(), pollSetup(), send(), socket(), Socket::vprintf(), Socket::write(), and ~Wireless().

unsigned int Wireless::getNumInterfaces (  ) 

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 128 of file Wireless.h.

bool Wireless::hasData ( int  sock  ) 

utility function that you can use if you're curious about the state of the socket.

You shouldn't need to use it, since asking sockets for write and read buffers does the necessary sanity checks

Definition at line 103 of file Wireless.h.

bool Wireless::isError ( int  sock  ) 

utility function that you can use if you're curious about the state of the socket.

You shouldn't need to use it, since asking sockets for write and read buffers does the necessary sanity checks

Definition at line 98 of file Wireless.h.

bool Wireless::isReady ( int  sock  ) 

utility function that you can use if you're curious about the state of the socket.

You shouldn't need to use it, since asking sockets for write and read buffers does the necessary sanity checks

Definition at line 102 of file Wireless.h.

int Wireless::listen ( Socket sobj,
int  port 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 121 of file Wireless.h.

Referenced by listen().

int Wireless::listen ( Socket sobj,
int  port 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 120 of file Wireless.h.

Referenced by listen().

int Wireless::listen ( int  sock,
int  port 
)
Wireless& Wireless::operator= ( const Wireless  )  [private]

don't call

void Wireless::pollProcess (  ) 

on non-aperios, process callbacks and state changes as signaled in pollTest()

Definition at line 960 of file Wireless.cc.

void Wireless::pollSetup (  ) 

on non-aperios, set up structures to be checked in pollTest()

Definition at line 923 of file Wireless.cc.

bool Wireless::pollTest ( struct timeval *  tv  ) 

on non-aperios, check to see any network communication has occurred

Parameters:
tv how long to wait -- NULL will wait indefinitely until a socket event occurs
Returns:
true if there was a socket event to process, false if timed out

Definition at line 953 of file Wireless.cc.

void Wireless::receive ( int  sock  ) 

function for internal and Socket use. You should not call this

void Wireless::receive ( int  sock,
int(*)(char *, int)  rcvcbckfn 
)

function for internal and Socket use. You should not call this

void Wireless::send ( int  sock  ) 

function called by the Socket objects to actually write data to the network. You should not call this.

Definition at line 852 of file Wireless.cc.

Referenced by blockingSend(), Socket::flush(), and pollProcess().

void Wireless::setCallbackLock ( Resource l  ) 

sets callbackLock

Definition at line 1183 of file Wireless.cc.

void Wireless::setDaemon ( Socket sobj,
bool  val = true 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 117 of file Wireless.h.

Referenced by setDaemon().

void Wireless::setDaemon ( Socket sobj,
bool  val = true 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 116 of file Wireless.h.

Referenced by setDaemon().

void Wireless::setReceiver ( Socket sobj,
SocketListener listener 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 114 of file Wireless.h.

Referenced by setReceiver().

void Wireless::setReceiver ( Socket sobj,
SocketListener listener 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 112 of file Wireless.h.

Referenced by setReceiver().

void Wireless::setReceiver ( Socket sobj,
int(*)(char *, int)  rcvcbckfn 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 110 of file Wireless.h.

Referenced by setReceiver().

void Wireless::setReceiver ( Socket sobj,
int(*)(char *, int)  rcvcbckfn 
)

helper function for the function with the same name that takes a socket descriptor (int)

Definition at line 108 of file Wireless.h.

Referenced by setReceiver().

void Wireless::setReceiver ( int  sock,
SocketListener listener 
)

sets receiver callback for a socket, this version requiring the SocketListener interface (more powerful, as this lets us tell connections apart)

Definition at line 690 of file Wireless.cc.

Socket * Wireless::socket ( Socket::TransportType_t  ttype,
int  recvsize,
int  sendsize 
)
Parameters:
ttype selects between TCP and UDP
recvsize size of input buffer
sendsize size of output buffer

Definition at line 804 of file Wireless.cc.

void Wireless::wakeup ( Socket del = NULL  ) 

writes del on interruptCtl, breaking out of a pending pollTest() and thus giving an opportunity to change the contents of the FD sets being used;

Parameters:
del if non-NULL, will cause the socket to be closed and deleted

Definition at line 1174 of file Wireless.cc.

Referenced by close(), connect(), listen(), and send().


Friends And Related Function Documentation

friend class Socket [friend]

Definition at line 170 of file Wireless.h.

Referenced by socket().


Member Data Documentation

this lock will be aquired during any callbacks which might occur during pollProcess()

Definition at line 180 of file Wireless.h.

Referenced by clearCallbackLock(), getCallbackLock(), and setCallbackLock().

fd_set Wireless::efds [protected]

a set of file descriptors which should be polled for errors; set up by pollSetup(), watched (blocking) by pollTest(), and processed by pollProcess()

Definition at line 185 of file Wireless.h.

Referenced by pollProcess(), pollSetup(), pollTest(), and Wireless().

int Wireless::fdsMax [protected]

maximum file descriptor value in the rfds, wfds, efds fd_set's

Definition at line 186 of file Wireless.h.

Referenced by pollSetup(), pollTest(), and Wireless().

std::list<int> Wireless::freeSockets [protected]

this lock will be aquired during any callbacks which might occur during pollProcess()

Definition at line 189 of file Wireless.h.

Referenced by close(), socket(), Wireless(), and ~Wireless().

int Wireless::interruptChk [protected]

a socket, connected to interruptCtl, which allows pollTest() to be interrupted if new sockets need to be polled

Definition at line 181 of file Wireless.h.

Referenced by pollProcess(), pollSetup(), Wireless(), and ~Wireless().

int Wireless::interruptCtl [protected]

a socket, connected to interruptChk, which allows pollTest() to be interrupted if new sockets need to be polled

Definition at line 182 of file Wireless.h.

Referenced by wakeup(), Wireless(), and ~Wireless().

const int Wireless::MAXCONNECTIONS = 5 [static, protected]

the maximum number of connections which can be queued when listening

Definition at line 171 of file Wireless.h.

Referenced by listen().

fd_set Wireless::rfds [protected]

a set of file descriptors which should be polled for readable data; set up by pollSetup(), watched (blocking) by pollTest(), and processed by pollProcess()

Definition at line 183 of file Wireless.h.

Referenced by pollProcess(), pollSetup(), pollTest(), and Wireless().

this lock will be aquired during any callbacks which might occur during pollProcess()

Definition at line 188 of file Wireless.h.

Referenced by blockingSend(), close(), connect(), getDaemon(), hasData(), isConnected(), isError(), isReady(), listen(), pollProcess(), pollSetup(), send(), setDaemon(), setReceiver(), socket(), Wireless(), and ~Wireless().

std::list<int> Wireless::usedSockets [protected]

this lock will be aquired during any callbacks which might occur during pollProcess()

Definition at line 190 of file Wireless.h.

Referenced by close(), pollProcess(), pollSetup(), socket(), and ~Wireless().

set to true at modifcation of usedSockets, cleared prior to callbacks so we can tell if callback invalidates active iterators

Definition at line 191 of file Wireless.h.

Referenced by close(), pollProcess(), socket(), and ~Wireless().

fd_set Wireless::wfds [protected]

a set of file descriptors which should be polled for write-complete; set up by pollSetup(), watched (blocking) by pollTest(), and processed by pollProcess()

Definition at line 184 of file Wireless.h.

Referenced by pollProcess(), pollSetup(), pollTest(), and Wireless().

const int Wireless::WIRELESS_DEF_RECV_SIZE = 1024 [static]

Default number of bytes to use for receive buffers (overridden by value passed to socket()).

Definition at line 41 of file Wireless.h.

Referenced by socket().

const int Wireless::WIRELESS_DEF_SEND_SIZE = 1024 [static]

Default number of bytes to use for send buffers (overridden by value passed to socket()).

Definition at line 44 of file Wireless.h.

Referenced by socket().

const int Wireless::WIRELESS_MAX_SOCKETS = 100 [static]

Maximum number of sockets which can be created.

Definition at line 38 of file Wireless.h.

Referenced by blockingSend(), close(), connect(), listen(), send(), and Wireless().


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

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