Homepage Demos Overview Downloads Tutorials Reference
Credits

Socket Class Reference

#include <Socket.h>

Inheritance diagram for Socket:

Inheritance graph
[legend]
List of all members.

Detailed Description

Tekkotsu wireless Socket 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 61 of file Socket.h.

Public Member Functions

 Socket (int sockn)
 constructor
virtual ~Socket ()
 destructor
byte * getWriteBuffer (int bytesreq)
void write (int size)
 writes the specified number of bytes starting at the pointer returned.
int read ()
 Blocking read.
byte * getReadBuffer ()
 getReadBuffer is used with blocking read's
void init ()
 initialize socket member variables. This is different from the constructor since sockets are reused
int setFlushType (FlushType_t fType)
 Chooses between blocking and non-blocking input, output.
void setTextForward ()
 causes this socket to forward output to stdout if it is not connected, call setForward(NULL) to unset
void setForward (Socket *forsock)
 causes this socket to forward output to sock if it is not connected, pass NULL to unset
void setVerbosity (int verbose)
 Picks a level of verbosity for filtering pprintf commands.
int write (const byte *buf, int size)
int read (byte *buf, int size)
 Blocking read.
int printf (const char *fmt,...)
int vprintf (const char *fmt, va_list al)
int pprintf (int vlevel, const char *fmt,...)
 Similar to printf, except it takes an extra first argument.
void flush ()

Public Attributes

int sock
 unique non-negative integer representing socket. Serves as index into socket Objects array

Protected Member Functions

 Socket (const Socket &)
 copy constructor, don't call
Socketoperator= (const Socket &)
 assignment operator, don't call

Protected Attributes

TransportType_t trType
 private ALOKL_TODO
FlushType_t flType
 private ALOKL_TODO
int verbosity
 private ALOKL_TODO
antModuleRef endpoint
 private ALOKL_TODO
ConnectionState state
 private ALOKL_TODO
int sendBufSize
 private ALOKL_TODO
int recvBufSize
 private ALOKL_TODO
int sendSize
 private ALOKL_TODO
int recvSize
 private ALOKL_TODO
int writeSize
 private ALOKL_TODO
int readSize
 private ALOKL_TODO
bool tx
 private ALOKL_TODO
bool rx
 private ALOKL_TODO
antSharedBuffer sendBuffer
 private ALOKL_TODO
antSharedBuffer recvBuffer
 private ALOKL_TODO
byte * sendData
 private ALOKL_TODO
byte * recvData
 private ALOKL_TODO
byte * readData
 private ALOKL_TODO
byte * writeData
 private ALOKL_TODO
int server_port
 private ALOKL_TODO
int(* rcvcbckfn )(char *, int)
 private ALOKL_TODO
bool textForward
 private ALOKL_TODO
char * textForwardBuf
 private ALOKL_TODO
SocketforwardSock
 private ALOKL_TODO
bool daemon
 private ALOKL_TODO

Friends

class Wireless


Constructor & Destructor Documentation

Socket::Socket int  sockn  )  [inline, explicit]
 

constructor

Definition at line 69 of file Socket.h.

virtual Socket::~Socket  )  [inline, virtual]
 

destructor

Definition at line 78 of file Socket.h.

Socket::Socket const Socket  )  [protected]
 

copy constructor, don't call


Member Function Documentation

void Socket::flush  ) 
 

All write commands on the socket will implicity call this. You don't need to call it, unless you're implementing your own write

Reimplemented in DummySocket.

Definition at line 68 of file Socket.cc.

Referenced by Wireless::SendCont(), vprintf(), and write().

byte * Socket::getReadBuffer  ) 
 

getReadBuffer is used with blocking read's

The read(void) and getReadBuffer combo eliminates one buffer copy. You don't need to use getReadBuffer with read(byte*, int)

Blocking read is currently broken - it will be fixed in the next release

Returns:
pointer to the buffer the previous call to blocking read wrote into or NULL if no data was read

Reimplemented in DummySocket.

Definition at line 46 of file Socket.cc.

byte * Socket::getWriteBuffer int  bytesreq  ) 
 

The getWriteBuffer-write(int) combo eliminates one buffer copy. You don't need to use getWriteBuffer with write(byte*, int)

Returns:
pointer to the current position in the current write buffer for this socket or NULL on error
Parameters:
bytesreq maximum number of bytes the caller intends to set before the write method is called

Reimplemented in DummySocket.

Definition at line 13 of file Socket.cc.

Referenced by SegCamBehavior::openPacket(), RawCamBehavior::openPacket(), WorldStateSerializerBehavior::processEvent(), MicrophoneServer::processEvent(), WMMonitorBehavior::report(), DumpFileControl::selectedFile(), and write().

void Socket::init  ) 
 

initialize socket member variables. This is different from the constructor since sockets are reused

Reimplemented in DummySocket.

Definition at line 53 of file Socket.cc.

Referenced by Wireless::connect(), and Wireless::listen().

Socket& Socket::operator= const Socket  )  [protected]
 

assignment operator, don't call

int Socket::pprintf int  vlevel,
const char *  fmt,
  ...
 

Similar to printf, except it takes an extra first argument.

If vlevel is than or equal to the current verbosity level, the string will be printed else it will be ignored

Parameters:
vlevel if (vlevel<=verbosity) print, else ignore
fmt same as the standard printf's format string

Reimplemented in DummySocket.

Definition at line 98 of file Socket.cc.

int Socket::printf const char *  fmt,
  ...
 

It's standard stuff. man 3 printf on most systems should give you more information

Reimplemented in DummySocket.

Definition at line 112 of file Socket.cc.

Referenced by Transition::activate(), ProfilerCheckControl::activate(), HelpControl::activate(), BehaviorReportControl::activate(), BatteryCheckControl::activate(), WalkCalibration::addSample(), JPEGGenerator::calcImage(), SensorObserverControl::checkLogFile(), EventLogger::checkLogFile(), ControlBase::clearMenu(), Controller::closeGUI(), ControlBase::doReadStdIn(), WalkCalibration::doSelect(), ValueEditControl< T >::doSelect(), ControlBase::doSelect(), StateNode::DoStart(), StareAtPawBehavior2::DoStart(), SegCamBehavior::DoStart(), RawCamBehavior::DoStart(), HelloWorldBehavior::DoStart(), FreezeTestBehavior::DoStart(), CrashTestBehavior::DoStart(), Controller::DoStop(), EmergencyStopMC::EmergencyStopMC(), HeadPointerMC::ensureValidJoint(), WalkCalibration::err(), FreeMemReportControl::freeMem(), Kinematics::getInterestPoint(), CameraBehavior::getNextName(), SpiderMachineBehavior::indent(), Kinematics::init(), Controller::init(), CameraBehavior::initIndex(), WalkMC::LoadBuffer(), SegmentedColorGenerator::LoadBuffer(), RLEGenerator::LoadBuffer(), RegionGenerator::LoadBuffer(), RawCameraGenerator::LoadBuffer(), JPEGGenerator::LoadBuffer(), InterleavedYUVGenerator::LoadBuffer(), CDTGenerator::LoadBuffer(), SegmentedColorGenerator::loadColorInfo(), WalkCalibration::loadData(), SegmentedColorGenerator::loadThresholdMap(), Kinematics::lookup(), MotionSequenceMC< MAXMOVE >::newKeyFrame(), CameraBehavior::openNextFile(), ValueEditControl< T >::pause(), Controller::pop(), pprintf(), WalkCalibration::processEvent(), ValueEditControl< T >::processEvent(), StareAtPawBehavior2::processEvent(), StareAtPawBehavior::processEvent(), SpiderMachineBehavior::processEvent(), SensorObserverControl::processEvent(), RegionGenerator::processEvent(), PostureEditor::processEvent(), KinematicSampleBehavior2::processEvent(), KinematicSampleBehavior::processEvent(), FreeMemReportControl::processEvent(), EventLogger::processEvent(), EStopControllerBehavior::processEvent(), CameraBehavior::processEvent(), BallDetectionGenerator::processEvent(), Controller::push(), LoadCalibration::readData(), LoadCalibration::readMaxs(), WaypointWalkControl::refresh(), WalkCalibration::refresh(), ValueEditControl< T >::refresh(), ControlBase::refresh(), WMMonitorBehavior::registerData(), WMMonitorBehavior::report(), WalkCalibration::report(), HelpControl::report(), FreeMemReportControl::report(), BatteryCheckControl::report(), SpiderMachineBehavior::runCommand(), EStopControllerBehavior::runCommand(), JPEGGenerator::SaveBuffer(), WalkCalibration::saveData(), RawCameraGenerator::SaveFileStream(), LoadWalkControl::selectedFile(), DumpFileControl::selectedFile(), ExploreMachine::setup(), WalkCalibration::setupMoving(), SpiderMachineBehavior::spider(), BatteryMonitorBehavior::startWarning(), BatteryMonitorBehavior::stopWarning(), SaveWalkControl::takeInput(), ControlBase::takeInput(), Controller::takeLine(), and EmergencyStopMC::trigger().

int Socket::read byte *  buf,
int  size
 

Blocking read.

You might want to consider the read(void) and getReadBuffer combo if you call this often

Blocking read is currently broken - it will be fixed in the next release

Parameters:
buf buffer to write from
size number of bytes to write
Returns:
number of bytes actually read

Reimplemented in DummySocket.

Definition at line 163 of file Socket.cc.

int Socket::read  ) 
 

Blocking read.

Tries to read upto receive buffer size worth of data from this socket.

Blocking read is currently broken - it will be fixed in the next release

Returns:
number of bytes read or -1 on error

Reimplemented in DummySocket.

Definition at line 40 of file Socket.cc.

Referenced by DumpFileControl::selectedFile().

int Socket::setFlushType FlushType_t  fType  ) 
 

Chooses between blocking and non-blocking input, output.

This function can only be called when a socket is disconnected, since it is a bad idea to mix blocking and non-blocking input, output. The default for a socket is non-blocking

Returns:
0 on success

Reimplemented in DummySocket.

Definition at line 60 of file Socket.cc.

Referenced by MMCombo::DoInit().

void Socket::setForward Socket forsock  )  [inline]
 

causes this socket to forward output to sock if it is not connected, pass NULL to unset

Definition at line 131 of file Socket.h.

Referenced by MMCombo::DoInit().

void Socket::setTextForward  )  [inline]
 

causes this socket to forward output to stdout if it is not connected, call setForward(NULL) to unset

Reimplemented in DummySocket.

Definition at line 128 of file Socket.h.

Referenced by MMCombo::DoInit().

void Socket::setVerbosity int  verbose  )  [inline]
 

Picks a level of verbosity for filtering pprintf commands.

The higher the verbosity, the more the number of messages printed. This is useful for filtering out non-important messages with very little processor cost. Default is 0.

Parameters:
verbose the higher the value of verbose, the more the output

Reimplemented in DummySocket.

Definition at line 140 of file Socket.h.

int Socket::vprintf const char *  fmt,
va_list  al
 

It's standard stuff. man 3 printf on most systems should give you more information

Reimplemented in DummySocket.

Definition at line 122 of file Socket.cc.

Referenced by printf().

int Socket::write const byte *  buf,
int  size
 

You might want to consider the getWriteBuffer-write(int) combo if you call this often

Parameters:
buf buffer to write from
size number of bytes to write
Returns:
the number of bytes actually written or -1 on error

Reimplemented in DummySocket.

Definition at line 145 of file Socket.cc.

void Socket::write int  size  ) 
 

writes the specified number of bytes starting at the pointer returned.

in a (prior) call to getWriteBufer

Parameters:
size number of bytes to be sent from the current write buffer

Reimplemented in DummySocket.

Definition at line 28 of file Socket.cc.

Referenced by SegCamBehavior::closePacket(), RawCamBehavior::closePacket(), StringInputControl::doReadStdIn(), Controller::loadGUI(), WorldStateSerializerBehavior::processEvent(), MicrophoneServer::processEvent(), ControlBase::refresh(), BatteryCheckControl::refresh(), WMMonitorBehavior::report(), DumpFileControl::selectedFile(), and write().


Friends And Related Function Documentation

friend class Wireless [friend]
 

Reimplemented in DummySocket.

Definition at line 62 of file Socket.h.


Member Data Documentation

bool Socket::daemon [protected]
 

private ALOKL_TODO

Definition at line 217 of file Socket.h.

Referenced by Wireless::setDaemon(), and Socket().

antModuleRef Socket::endpoint [protected]
 

private ALOKL_TODO

Definition at line 201 of file Socket.h.

Referenced by Wireless::connect(), Wireless::listen(), and Socket().

FlushType_t Socket::flType [protected]
 

private ALOKL_TODO

Definition at line 192 of file Socket.h.

Referenced by flush(), setFlushType(), and Socket().

Socket* Socket::forwardSock [protected]
 

private ALOKL_TODO

Definition at line 215 of file Socket.h.

Referenced by flush(), getWriteBuffer(), setForward(), setTextForward(), Socket(), vprintf(), and write().

int(* Socket::rcvcbckfn)(char *, int) [protected]
 

private ALOKL_TODO

Referenced by Wireless::receive(), Wireless::ReceiveCont(), Wireless::setReceiver(), and Socket().

byte* Socket::readData [protected]
 

private ALOKL_TODO

Definition at line 209 of file Socket.h.

Referenced by Wireless::socket(), and Socket().

int Socket::readSize [protected]
 

private ALOKL_TODO

Definition at line 204 of file Socket.h.

Referenced by Socket().

antSharedBuffer Socket::recvBuffer [protected]
 

private ALOKL_TODO

Definition at line 207 of file Socket.h.

Referenced by Wireless::close(), Wireless::socket(), and Socket().

int Socket::recvBufSize [protected]
 

private ALOKL_TODO

Definition at line 204 of file Socket.h.

Referenced by Wireless::socket(), and Socket().

byte * Socket::recvData [protected]
 

private ALOKL_TODO

Definition at line 208 of file Socket.h.

Referenced by Wireless::ReceiveCont(), Wireless::socket(), and Socket().

int Socket::recvSize [protected]
 

private ALOKL_TODO

Definition at line 204 of file Socket.h.

Referenced by Wireless::ReceiveCont(), and Socket().

bool Socket::rx [protected]
 

private ALOKL_TODO

Definition at line 205 of file Socket.h.

Referenced by Wireless::hasData(), Wireless::receive(), and Socket().

antSharedBuffer Socket::sendBuffer [protected]
 

private ALOKL_TODO

Definition at line 207 of file Socket.h.

Referenced by Wireless::close(), Wireless::socket(), and Socket().

int Socket::sendBufSize [protected]
 

private ALOKL_TODO

Definition at line 204 of file Socket.h.

Referenced by getWriteBuffer(), Wireless::socket(), Socket(), and vprintf().

byte* Socket::sendData [protected]
 

private ALOKL_TODO

Definition at line 208 of file Socket.h.

Referenced by flush(), Wireless::socket(), and Socket().

int Socket::sendSize [protected]
 

private ALOKL_TODO

Definition at line 204 of file Socket.h.

Referenced by Wireless::blockingSend(), flush(), init(), Wireless::send(), and Socket().

int Socket::server_port [protected]
 

private ALOKL_TODO

Definition at line 210 of file Socket.h.

Referenced by Wireless::listen(), and Socket().

int Socket::sock
 

unique non-negative integer representing socket. Serves as index into socket Objects array

Definition at line 65 of file Socket.h.

Referenced by Controller::console_callback(), StringInputControl::doReadStdIn(), ControlBase::doReadStdIn(), WMMonitorBehavior::DoStart(), WalkControllerBehavior::DoStart(), SpiderMachineBehavior::DoStart(), SpeakerServer::DoStart(), MicrophoneServer::DoStart(), HeadPointControllerBehavior::DoStart(), EStopControllerBehavior::DoStart(), Controller::DoStart(), Aibo3DControllerBehavior::DoStart(), SegCamBehavior::DoStop(), RawCamBehavior::DoStop(), flush(), SpiderMachineBehavior::processEvent(), SegCamBehavior::processEvent(), RawCamBehavior::processEvent(), MicrophoneServer::processEvent(), WalkCalibration::refresh(), ValueEditControl< T >::refresh(), ControlBase::refresh(), BatteryCheckControl::refresh(), and Socket().

ConnectionState Socket::state [protected]
 

private ALOKL_TODO

Definition at line 202 of file Socket.h.

Referenced by Wireless::BindCont(), Wireless::close(), Wireless::CloseCont(), Wireless::connect(), Wireless::ConnectCont(), flush(), getWriteBuffer(), Wireless::isConnected(), Wireless::listen(), Wireless::ListenCont(), Wireless::ReceiveCont(), Wireless::SendCont(), setFlushType(), Socket(), vprintf(), and write().

bool Socket::textForward [protected]
 

private ALOKL_TODO

Definition at line 213 of file Socket.h.

Referenced by getWriteBuffer(), setForward(), setTextForward(), Socket(), vprintf(), and write().

char* Socket::textForwardBuf [protected]
 

private ALOKL_TODO

Definition at line 214 of file Socket.h.

Referenced by getWriteBuffer(), Socket(), and write().

TransportType_t Socket::trType [protected]
 

private ALOKL_TODO

Definition at line 191 of file Socket.h.

Referenced by Wireless::socket(), and Socket().

bool Socket::tx [protected]
 

private ALOKL_TODO

Definition at line 205 of file Socket.h.

Referenced by Wireless::blockingSend(), flush(), Wireless::isReady(), Wireless::send(), Wireless::SendCont(), and Socket().

int Socket::verbosity [protected]
 

private ALOKL_TODO

Definition at line 194 of file Socket.h.

Referenced by pprintf(), setVerbosity(), and Socket().

byte * Socket::writeData [protected]
 

private ALOKL_TODO

Definition at line 209 of file Socket.h.

Referenced by flush(), getWriteBuffer(), Wireless::socket(), Socket(), and vprintf().

int Socket::writeSize [protected]
 

private ALOKL_TODO

Definition at line 204 of file Socket.h.

Referenced by flush(), getWriteBuffer(), init(), Socket(), vprintf(), and write().


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

Tekkotsu v2.2.2
Generated Tue Jan 4 15:45:32 2005 by Doxygen 1.4.0