AURobotServers
4
|
#include <usmlsource.h>
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 |
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)
USmlSource::USmlSource | ( | ) |
Constructor
References data, dataCnt, dataNext, errorBuffer, errorBufferCnt, gotFirstTag, ifName, limitedMaxDataLength, MAX_CLIENT_RX_BUFFER, and tagStartAtStartOfLineOnly.
|
virtual |
Constructor
|
inline |
Allow tagStartAt start of line only
References isSourceAvailable(), and tagStartAtStartOfLineOnly.
Referenced by UResRule::loadFile().
|
protected |
Discard all data in buffer – assumed garbage, e.g server reply error
References data, dataCnt, and dataNext.
Referenced by getToEndTag(), setRxDataBufferCnt(), and skipToEndTag().
|
protectedvirtual |
Should additional messaves be printed to console
Reimplemented in UClientPortSml, USmlFile, and USmlString.
Referenced by getNBytes(), getToEndTag(), isVerbose(), setRxDataBufferCnt(), skipNBytes(), and skipToEndTag().
|
inline |
|
inlinevirtual |
Get current line number from the source
Reimplemented in USmlFile, and USmlString.
Referenced by UMisRule::unpackInitPostBlock(), and UMisRule::unpackRule().
|
protectedvirtual |
Get more data, if more data is available
Reimplemented in UClientPortSml, USmlFile, and USmlString.
Referenced by getNBytes(), getNextTag(), setRxDataBufferCnt(), and skipNBytes().
|
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().
|
virtual |
Read the next available tag into the provided buffer.
tag,The | found tag is loaded into the 'tag' buffer. |
beforeTagBuffer | is (if != NULL) filled with the data before the next tag. |
beforeTagCnt | is 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. |
failEndTag | The 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().
|
inline |
|
inline |
Get size of rx data buffer
References limitedMaxDataLength.
Referenced by UResIf::interfaceTick(), and UClientHandler::threadRunLoop().
|
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.
tag | the start tag from where to start (start tag is not included) |
buffer | is where to store the data, the buffer string is zero terminated. |
bufferSize | number of bytes available in buffer |
msTimeout | maximum waittime between data bursts (if from socket) |
lastTag | may be a pointer to a tag, if the end tag (or the last) is of interest |
References clearRxBuffer(), doVerboseMessages(), getNextTag(), USmlTagIn::getTagName(), USmlTagIn::getTagStart(), UTime::getTimePassed(), USmlTagIn::isAStartTag(), USmlTagIn::isTagAnEnd(), and UTime::Now().
Referenced by UMisRule::unpackRule().
|
inline |
|
virtual |
Is tha data source (still) open.
Reimplemented in UClientPortSml, USmlFile, and USmlString.
Referenced by allowTagAtStartOfLineOnly(), getNextTag(), and UMisRule::unpackRule().
|
inline |
Should print to console be verbose.
References buf, doVerboseMessages(), outputData(), setErrorBuffer(), and syntaxError().
Referenced by USmlTag::cnnVerbose(), USmlTag::getGmk(), USmlTag::getLineSegment(), USmlTag::getManSeq(), USmlTag::getObstacle(), USmlTag::getObstacleGroup(), USmlTag::getPolygon(), USmlTag::getPoseTime(), USmlTag::getProbPoly(), syntaxError(), UMisLoadedRule::unpack(), and UResRule::unpackMissionRule().
|
inlinevirtual |
gives the possibility to log all received data.
data | is the string received - NULL teminated, but data may hold binary 0 too! |
dataCnt | is length of data |
Reimplemented in ULaserSim.
Referenced by getNextTag().
|
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
buf | pointer to character array area (set to NULL if buffer is not valid) |
bufCnt | size of buffer area |
References buf, errorBuffer, and errorBufferCnt.
Referenced by isVerbose(), and UResRule::loadFile().
|
inlinevirtual |
Set current line number from the source
newLineNumber | may be used to set a new series of line numbers |
Reimplemented in USmlFile, and USmlString.
|
inline |
Get size of rx data buffer
References clearRxBuffer(), doVerboseMessages(), getMoreData(), limitedMaxDataLength, MAX_CLIENT_RX_BUFFER, and mini().
Referenced by UResIf::interfaceTick().
|
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().
|
virtual |
Got an unusable message - just skip to other end.
tag | should point to the start tag, of which the content is unwanted. |
timeout | is 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().
|
virtual |
A syntax error has occured with the provided message
message | is 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().
|
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().
|
protected |
Valid data in data buffer - relative to buffer start
Referenced by clearRxBuffer(), getNBytes(), getNextTag(), ULaserSim::isPortOpen(), skipNBytes(), UClientHandler::threadRunLoop(), and USmlSource().
|
private |
Pointer to next unused data
Referenced by clearRxBuffer(), getNBytes(), getNextTag(), skipNBytes(), and USmlSource().
|
protected |
buffer for syntax error - must be set by caller
Referenced by getErrorBuffer(), getNextTag(), isErrorText(), setErrorBuffer(), syntaxError(), and USmlSource().
|
protected |
size of buffer for syntax error
Referenced by setErrorBuffer(), syntaxError(), USmlFile::USmlFile(), and USmlSource().
|
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().
|
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().
|
protected |
ignore tag start if not at start of line (may be preceded by whitespace only)
Referenced by allowTagAtStartOfLineOnly(), getNextTag(), and USmlSource().