AURobotServers  4
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
USmlSource Class Reference

#include <usmlsource.h>

Inheritance diagram for USmlSource:
Inheritance graph

Public Member Functions

void allowTagAtStartOfLineOnly ()
 
const char * getErrorBuffer ()
 
virtual int getLineNumber ()
 
virtual int getNBytes (char *buffer, int n, int msTimeout=100)
 
virtual bool getNextTag (USmlTag *tag, int msTimeout=100, USmlTagIn *failEndTag=NULL, char *beforeTagBuffer=NULL, int *beforeTagCnt=NULL)
 
char * getRxDataBuffer ()
 
int getRxDataBufferCnt ()
 
virtual const char * getSourceName ()
 
bool getToEndTag (USmlTagIn *tag, char *buffer, const int bufferSize, int msTimeout=100, USmlTagIn *lastTag=NULL)
 
bool isErrorText ()
 
virtual bool isSourceAvailable ()
 
bool isVerbose ()
 
virtual bool logSourceData (const char *, int)
 
virtual bool outputData (const char *message)
 
void setErrorBuffer (char *buf, const int bufCnt)
 
virtual void setLineNumber (int)
 
int setRxDataBufferCnt (int newMaxLength)
 
virtual bool skipNBytes (int n, int msTimeout=100)
 
virtual bool skipToEndTag (USmlTagIn *tag, int msTimeout=100)
 
virtual void syntaxError (const char *message)
 
 USmlSource ()
 
virtual ~USmlSource ()
 

Public Attributes

const char * ifName
 

Protected Member Functions

void clearRxBuffer ()
 
virtual bool doVerboseMessages ()
 
virtual int getMoreData (char *buffer, int bufferSize, int pollTimeoutMs)
 

Protected Attributes

int dataCnt
 
char * errorBuffer
 
int errorBufferCnt
 
bool gotFirstTag
 
bool tagStartAtStartOfLineOnly
 

Private Attributes

char data [MAX_CLIENT_RX_BUFFER+1]
 
const char * dataNext
 
int limitedMaxDataLength
 

Detailed Description

Interface class for a SML (XML) source

    @author Christian Andersen <chrand@mail.dk>

Class that handles input from (any) source and packs into SML (XML)

Constructor & Destructor Documentation

USmlSource::USmlSource ( )
USmlSource::~USmlSource ( )
virtual

Constructor

Member Function Documentation

void USmlSource::allowTagAtStartOfLineOnly ( )
inline

Allow tagStartAt start of line only

References isSourceAvailable(), and tagStartAtStartOfLineOnly.

Referenced by UResRule::loadFile().

void USmlSource::clearRxBuffer ( )
protected

Discard all data in buffer – assumed garbage, e.g server reply error

References data, dataCnt, and dataNext.

Referenced by getToEndTag(), setRxDataBufferCnt(), and skipToEndTag().

bool USmlSource::doVerboseMessages ( )
protectedvirtual

Should additional messaves be printed to console

Reimplemented in UClientPortSml, USmlFile, and USmlString.

Referenced by getNBytes(), getToEndTag(), isVerbose(), setRxDataBufferCnt(), skipNBytes(), and skipToEndTag().

const char* USmlSource::getErrorBuffer ( )
inline

Get error buffer pointer

References errorBuffer.

Referenced by UMisRule::unpackRule().

virtual int USmlSource::getLineNumber ( )
inlinevirtual

Get current line number from the source

Returns
-1 if line numbers are unavalable

Reimplemented in USmlFile, and USmlString.

Referenced by UMisRule::unpackInitPostBlock(), and UMisRule::unpackRule().

int USmlSource::getMoreData ( char *  buffer,
int  bufferSize,
int  pollTimeoutMs 
)
protectedvirtual

Get more data, if more data is available

Reimplemented in UClientPortSml, USmlFile, and USmlString.

Referenced by getNBytes(), getNextTag(), setRxDataBufferCnt(), and skipNBytes().

int USmlSource::getNBytes ( char *  buffer,
int  n,
int  msTimeout = 100 
)
virtual

Get the next n bytes loaded into the provided buffer. N may be of any length (that can be received within the timeout period). the number of bytes loaded into the buffer. If source is invalid or no data is available zero is returned.

References data, dataCnt, dataNext, doVerboseMessages(), getMoreData(), and mini().

Referenced by UFunctionIf::dataTrap(), and USmlTag::getNBytes().

bool USmlSource::getNextTag ( USmlTag tag,
int  msTimeout = 100,
USmlTagIn failEndTag = NULL,
char *  beforeTagBuffer = NULL,
int *  beforeTagCnt = NULL 
)
virtual

Read the next available tag into the provided buffer.

Parameters
tag,Thefound tag is loaded into the 'tag' buffer.
beforeTagBufferis (if != NULL) filled with the data before the next tag.
beforeTagCntis on entry the buffer size. The number of bytes filled into the buffer returned into 'beforeTagCnt'. If there is more data before the next tag than the space in 'beforeTagBuffer' then the function returns with 'beforeTagBuffer' equal to the buffer size and the function returnes true. Note the buffer is NOT nul-terminated (to allow binary data), so the user must add a nul at the 'beforeTagCnt' position if the result is used as a string.
failEndTagThe search is also stopped if an end-tag is found matching the 'failEndTag' (makes the function return false). true if tag is valid (and the beforeTagBuffer has no overflow).

References absi(), data, dataCnt, dataNext, errorBuffer, getMoreData(), USmlTagIn::getTagCnt(), USmlTagIn::getTagName(), USmlTagIn::getTagStart(), USmlTagIn::getToEnd(), gotFirstTag, isSourceAvailable(), USmlTagIn::isTagAnEnd(), USmlTagIn::isTagEndFound(), USmlTagIn::isValid(), logSourceData(), MAX_CLIENT_RX_BUFFER, mini(), USmlTag::setCnn(), USmlTagIn::setTag(), USmlTagIn::setValid(), syntaxError(), and tagStartAtStartOfLineOnly.

Referenced by UFunctionIf::dataTrap(), USmlTag::getGmk(), USmlTag::getLineSegment(), USmlTag::getManSeq(), USmlTag::getNextTag(), USmlTag::getObstacle(), USmlTag::getObstacleGroup(), USmlTag::getPolygon(), USmlTag::getPoseTime(), USmlTag::getProbPoly(), getToEndTag(), UResRule::loadFile(), skipToEndTag(), UClientHandler::threadRunLoop(), UMisRule::unpackInitPostBlock(), and UMisRule::unpackRule().

char* USmlSource::getRxDataBuffer ( )
inline

Get receive data buffer

References data.

Referenced by UClientHandler::threadRunLoop().

int USmlSource::getRxDataBufferCnt ( )
inline

Get size of rx data buffer

References limitedMaxDataLength.

Referenced by UResIf::interfaceTick(), and UClientHandler::threadRunLoop().

virtual const char* USmlSource::getSourceName ( )
inlinevirtual

Get source name pointer

Reimplemented in UClientPortSml, and USmlFile.

Referenced by UMisRule::unpackRule().

bool USmlSource::getToEndTag ( USmlTagIn tag,
char *  buffer,
const int  bufferSize,
int  msTimeout = 100,
USmlTagIn lastTag = NULL 
)

Get all data to a buffer until the matching end tag.

Parameters
tagthe start tag from where to start (start tag is not included)
bufferis where to store the data, the buffer string is zero terminated.
bufferSizenumber of bytes available in buffer
msTimeoutmaximum waittime between data bursts (if from socket)
lastTagmay be a pointer to a tag, if the end tag (or the last) is of interest
Returns
true if the end tag is found.

References clearRxBuffer(), doVerboseMessages(), getNextTag(), USmlTagIn::getTagName(), USmlTagIn::getTagStart(), UTime::getTimePassed(), USmlTagIn::isAStartTag(), USmlTagIn::isTagAnEnd(), and UTime::Now().

Referenced by UMisRule::unpackRule().

bool USmlSource::isErrorText ( )
inline

Is there an error text

References errorBuffer.

Referenced by UMisRule::unpackRule().

bool USmlSource::isSourceAvailable ( )
virtual

Is tha data source (still) open.

Returns
true if open

Reimplemented in UClientPortSml, USmlFile, and USmlString.

Referenced by allowTagAtStartOfLineOnly(), getNextTag(), and UMisRule::unpackRule().

bool USmlSource::isVerbose ( )
inline
virtual bool USmlSource::logSourceData ( const char *  ,
int   
)
inlinevirtual

gives the possibility to log all received data.

Parameters
datais the string received - NULL teminated, but data may hold binary 0 too!
dataCntis length of data
Returns
true if data is logged (or should return true)

Reimplemented in ULaserSim.

Referenced by getNextTag().

bool USmlSource::outputData ( const char *  message)
virtual

Output a reply to the source (if possible, e.g. a socket connection)

Reimplemented in UClientPortSml.

Referenced by isVerbose(), and USmlTag::outputData().

void USmlSource::setErrorBuffer ( char *  buf,
const int  bufCnt 
)

Set error buffer Set a (long) character buffer where to save e.g. syntax error for later display

Parameters
bufpointer to character array area (set to NULL if buffer is not valid)
bufCntsize of buffer area

References buf, errorBuffer, and errorBufferCnt.

Referenced by isVerbose(), and UResRule::loadFile().

virtual void USmlSource::setLineNumber ( int  )
inlinevirtual

Set current line number from the source

Parameters
newLineNumbermay be used to set a new series of line numbers

Reimplemented in USmlFile, and USmlString.

int USmlSource::setRxDataBufferCnt ( int  newMaxLength)
inline
bool USmlSource::skipNBytes ( int  n,
int  msTimeout = 100 
)
virtual

Skip N bytes (from a binary message). true if n bytes skipped. false if timeout or source is down.

References data, dataCnt, dataNext, doVerboseMessages(), getMoreData(), MAX_CLIENT_RX_BUFFER, mini(), and Wait().

Referenced by USmlTag::skipNBytes(), and skipToEndTag().

bool USmlSource::skipToEndTag ( USmlTagIn tag,
int  msTimeout = 100 
)
virtual

Got an unusable message - just skip to other end.

Parameters
tagshould point to the start tag, of which the content is unwanted.
timeoutis in miliseconds, when waiting for new data. true when relevant end-tag is removed from the stream or false when a period of 'msTimeout' has passed with no data.

References clearRxBuffer(), doVerboseMessages(), USmlTagIn::getNextAttribute(), getNextTag(), USmlTagIn::getTagName(), UTime::getTimePassed(), USmlTagIn::isAStartTag(), USmlTagIn::isTagA(), USmlTagIn::isTagAnEnd(), MAX_SML_NAME_LENGTH, UTime::Now(), and skipNBytes().

Referenced by USmlTag::getGmk(), USmlTag::getLineSegment(), USmlTag::getManSeq(), USmlTag::getObstacle(), USmlTag::getObstacleGroup(), USmlTag::getPolygon(), USmlTag::getPoseTime(), USmlTag::getProbPoly(), UResRule::loadFile(), USmlTag::skipToEndTag(), UMisRule::unpackInitPostBlock(), UResRule::unpackMissionRule(), and UMisRule::unpackRule().

void USmlSource::syntaxError ( const char *  message)
virtual

A syntax error has occured with the provided message

Parameters
messageis a description of the error type.

Reimplemented in USmlFile, and USmlString.

References errorBuffer, errorBufferCnt, and isVerbose().

Referenced by UMisRule::checkSyntax(), getNextTag(), isVerbose(), USmlString::syntaxError(), USmlFile::syntaxError(), UMisRule::unpackInitPostBlock(), UMisRule::unpackLine(), and UMisRule::unpackRule().

Member Data Documentation

char USmlSource::data[MAX_CLIENT_RX_BUFFER+1]
private

Buffer for new data from socket, plus space for a zero when searching for '<' and '>'

Referenced by clearRxBuffer(), getNBytes(), getNextTag(), getRxDataBuffer(), ULaserSim::isPortOpen(), ULaserSim::logSourceData(), skipNBytes(), UClientHandler::threadRunLoop(), and USmlSource().

int USmlSource::dataCnt
protected

Valid data in data buffer - relative to buffer start

Referenced by clearRxBuffer(), getNBytes(), getNextTag(), ULaserSim::isPortOpen(), skipNBytes(), UClientHandler::threadRunLoop(), and USmlSource().

const char* USmlSource::dataNext
private

Pointer to next unused data

Referenced by clearRxBuffer(), getNBytes(), getNextTag(), skipNBytes(), and USmlSource().

char* USmlSource::errorBuffer
protected

buffer for syntax error - must be set by caller

Referenced by getErrorBuffer(), getNextTag(), isErrorText(), setErrorBuffer(), syntaxError(), and USmlSource().

int USmlSource::errorBufferCnt
protected

size of buffer for syntax error

Referenced by setErrorBuffer(), syntaxError(), USmlFile::USmlFile(), and USmlSource().

bool USmlSource::gotFirstTag
protected

Flag for receptionof the first tag

Referenced by UClientHandler::connectionChange(), getNextTag(), UClientHandler::threadRunLoop(), and USmlSource().

const char* USmlSource::ifName

Pointer to interface name - to be used in data source tracking (mostly for debug and status)

Referenced by USmlTag::getIfName(), UClientHandler::gotNewData(), UResIf::UResIf(), and USmlSource().

int USmlSource::limitedMaxDataLength
private

Used number of bytes (maximum in one read) of the data buffer. This may be set by the user to less than the full buffer. Mostly used for binary fixed length messages.

Referenced by getRxDataBufferCnt(), setRxDataBufferCnt(), and USmlSource().

bool USmlSource::tagStartAtStartOfLineOnly
protected

ignore tag start if not at start of line (may be preceded by whitespace only)

Referenced by allowTagAtStartOfLineOnly(), getNextTag(), and USmlSource().


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