TwiceAsNice  2019-02-18
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Basda::ChatLineMockCore Class Reference

#include <ChatLineMock.h>

Inheritance diagram for Basda::ChatLineMockCore:
Inheritance graph
Collaboration diagram for Basda::ChatLineMockCore:
Collaboration graph

Classes

struct  Reply
 

Public Member Functions

 ChatLineMockCore ()
 
virtual ~ChatLineMockCore ()
 
virtual int open (const char *_device)
 open device with name tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More...
 
virtual int close ()
 closedevice More...
 
virtual int tryReadlines (const int _max=-1)
 check if you can savly read a line. More...
 
virtual int nprintf (int _max, const char *_rsp_fmtstr, const char *_cmd_fmtstr,...)
 send line _cmd with params (like printf) and recv lines until a line _rsp is received or _max lines received. More...
 
virtual int chat (const char *_rsp, int _max, const char *_cmd=NULL)
 send line _cmd and recv lines until a line _rsp is received or _max lines received. More...
 
virtual int chat (const char *_rsp, const char *_cmd=NULL)
 send line _cmd and recv lines until a line _rsp is received. More...
 
virtual void setResponse (unsigned int _cmdID, std::string _response, std::string _event="", Nice::Time _time=Nice::Time(), bool _repeat=false)
 This method allows to set the command response. More...
 
virtual std::vector< std::string > getBuffer ()
 All command responses are stored in the serial buffer (m_srbuffer). More...
 
std::string operator[] (int _num)
 This operation allows to have access to the elements within the serial buffer (m_srbuffer) More...
 
virtual unsigned int size ()
 
 ChatLineMockCore ()
 
virtual ~ChatLineMockCore ()
 
virtual int open (const char *_device)
 open device with name tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More...
 
virtual int close ()
 closedevice More...
 
virtual int tryReadlines (const int _max=-1)
 check if you can savly read a line. More...
 
virtual int nprintf (int _max, const char *_rsp_fmtstr, const char *_cmd_fmtstr,...)
 send line _cmd with params (like printf) and recv lines until a line _rsp is received or _max lines received. More...
 
virtual int chat (const char *_rsp, int _max, const char *_cmd=NULL)
 send line _cmd and recv lines until a line _rsp is received or _max lines received. More...
 
virtual int chat (const char *_rsp, const char *_cmd=NULL)
 send line _cmd and recv lines until a line _rsp is received. More...
 
virtual void setResponse (unsigned int _cmdID, std::string _response, std::string _event="", Nice::Time _time=Nice::Time(), bool _repeat=false)
 This method allows to set the command response. More...
 
virtual std::vector< std::string > getBuffer ()
 All command responses are stored in the serial buffer (m_srbuffer). More...
 
std::string operator[] (int _num)
 This operation allows to have access to the elements within the serial buffer (m_srbuffer) More...
 
virtual unsigned int size ()
 
- Public Member Functions inherited from Nice::ChatLine
 ChatLine ()
 constructor More...
 
 ChatLine (const char *_device)
 constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More...
 
 ChatLine (int _fd)
 constructor with file descriptor More...
 
virtual ~ChatLine ()
 destructor More...
 
virtual int sendline (const std::string &_line)
 send line _line More...
 
virtual int recvline (std::string &_line)
 recv line _line More...
 
int dumpdata ()
 dump data in buffers More...
 
int chat (int _num, const char *_cmd=NULL)
 send line _cmd and wait for _num lines. More...
 
int mprintf (int _num, const char *_cmd=NULL,...)
 send line _cmd with params (like printf) and wait for _num lines. More...
 
int printf (const char *_rsp_fmtstr, const char *_cmd_fmtstr=NULL,...)
 send line _cmd with params (like printf) and recv lines until a line _rsp is received. More...
 
std::string operator[] (int _num)
 return recvd line number _num More...
 
std::size_t size ()
 return number of recvd lines More...
 
Nice::SeqString srbuffer ()
 
void setLineEnd (const char *_end)
 set the end of a rcvd- and sentline. More...
 
void setLineEndSend (const char *_end)
 the string _end is sent after every raw line. More...
 
void setLineEndRecv (const char *_end)
 characters from the string _end are used to detect the end of the line. More...
 
void setMinLine (int _min_line)
 
 ChatLine ()
 constructor More...
 
 ChatLine (const char *_device)
 constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More...
 
 ChatLine (int _fd)
 constructor with file descriptor More...
 
virtual ~ChatLine ()
 destructor More...
 
virtual int sendline (const std::string &_line)
 send line _line More...
 
virtual int recvline (std::string &_line)
 recv line _line More...
 
int dumpdata ()
 dump data in buffers More...
 
int chat (int _num, const char *_cmd=NULL)
 send line _cmd and wait for _num lines. More...
 
int mprintf (int _num, const char *_cmd=NULL,...)
 send line _cmd with params (like printf) and wait for _num lines. More...
 
int printf (const char *_rsp_fmtstr, const char *_cmd_fmtstr=NULL,...)
 send line _cmd with params (like printf) and recv lines until a line _rsp is received. More...
 
std::string operator[] (int _num)
 return recvd line number _num More...
 
std::size_t size ()
 return number of recvd lines More...
 
Nice::SeqString srbuffer ()
 
void setLineEnd (const char *_end)
 set the end of a rcvd- and sentline. More...
 
void setLineEndSend (const char *_end)
 the string _end is sent after every raw line. More...
 
void setLineEndRecv (const char *_end)
 characters from the string _end are used to detect the end of the line. More...
 
void setMinLine (int _min_line)
 
- Public Member Functions inherited from Nice::ChatCore
 ChatCore ()
 constructor More...
 
 ChatCore (const char *_device)
 constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More...
 
 ChatCore (int _fd)
 constructor with file descriptor More...
 
virtual ~ChatCore ()
 destructor More...
 
virtual int open ()
 
virtual int open (int _fd)
 open device with file descriptor More...
 
virtual bool isConnected () const
 check if its connected More...
 
virtual int wait (Nice::Time _time)
 wait _time sec for data, returns earlier as soon as data has arrived. More...
 
virtual int openListenSocket (int _port)
 open a listen socket. More...
 
virtual int tryAccept (ChatCore &_newConnection)
 try accepting for X secs. X is set by member setTimeout More...
 
void setTimeout (Nice::Time _t)
 set read timeout in seconds, -1 = wait forever. More...
 
Nice::Time timeout ()
 
void setVerbose (int _v)
 set verbosity parameters More...
 
void setName (std::string _name)
 
std::string name ()
 
 ChatCore ()
 constructor More...
 
 ChatCore (const char *_device)
 constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More...
 
 ChatCore (int _fd)
 constructor with file descriptor More...
 
virtual ~ChatCore ()
 destructor More...
 
virtual int open ()
 
virtual int open (int _fd)
 open device with file descriptor More...
 
virtual bool isConnected () const
 check if its connected More...
 
virtual int wait (Nice::Time _time)
 wait _time sec for data, returns earlier as soon as data has arrived. More...
 
virtual int openListenSocket (int _port)
 open a listen socket. More...
 
virtual int tryAccept (ChatCore &_newConnection)
 try accepting for X secs. X is set by member setTimeout More...
 
void setTimeout (Nice::Time _t)
 set read timeout in seconds, -1 = wait forever. More...
 
Nice::Time timeout ()
 
void setVerbose (int _v)
 set verbosity parameters More...
 
void setName (std::string _name)
 
std::string name ()
 

Protected Member Functions

virtual int getResponse (const unsigned int _cmdID, const int _max=-1, const char *_cmd="")
 This command is used by the chat method to response for the correct command request. More...
 
virtual void sendAllEvents ()
 
virtual void sendCommandRequest (const unsigned int _cmdID, const char *_cmd)
 
virtual Nice::Time checkNextEvent ()
 
virtual int getResponse (const unsigned int _cmdID, const int _max=-1, const char *_cmd="")
 This command is used by the chat method to response for the correct command request. More...
 
virtual void sendAllEvents ()
 
virtual void sendCommandRequest (const unsigned int _cmdID, const char *_cmd)
 
virtual Nice::Time checkNextEvent ()
 
- Protected Member Functions inherited from Nice::ChatLine
virtual void setStdSettings ()
 
virtual void timeoutAktion (const std::string &)
 
virtual int getc (char *_ch)
 
virtual void setStdSettings ()
 
virtual void timeoutAktion (const std::string &)
 
virtual int getc (char *_ch)
 
- Protected Member Functions inherited from Nice::ChatCore
int openTCP (std::string &_host, uint16_t _port)
 
int openTTY (std::string &_device, int _baud, int _numbits, std::string _parity)
 
int openTCP (std::string &_host, uint16_t _port)
 
int openTTY (std::string &_device, int _baud, int _numbits, std::string _parity)
 

Protected Attributes

std::string m_endl
 
std::multimap< Nice::Date, std::vector< std::string > > m_eventStack
 
std::multimap< unsigned int, Replym_responseStack
 
std::queue< std::string > m_streamBuffer
 
bool m_sendVersionString
 
Nice::Mutex m_mutex
 
- Protected Attributes inherited from Nice::ChatLine
Nice::SeqString m_srbuffer
 
char m_lineEndSend [7]
 
char m_lineEndRecv [7]
 
unsigned int m_minLine
 
char m_readBlockBuffer [1025]
 
std::string m_readBuffer
 
std::string m_lineBuffer
 
- Protected Attributes inherited from Nice::ChatCore
std::string m_device_name
 
int m_fd
 
Nice::Time m_timeout
 
int verbose_
 
bool m_persistent
 
std::string m_name
 

Additional Inherited Members

- Public Types inherited from Nice::ChatLine
enum  { CONNECTION_TIMEOUT = -7777 }
 
enum  { CONNECTION_TIMEOUT = -7777 }
 
- Public Types inherited from Nice::ChatCore
enum  ChatVERBOSE {
  ChatVERBOSE = 0x1, ChatCOLOR = 0x2, ChatTIME = 0x4, ChatECHO = 0x8,
  ChatVERBOSE = 0x1, ChatCOLOR = 0x2, ChatTIME = 0x4, ChatECHO = 0x8
}
 
enum  ChatVERBOSE {
  ChatVERBOSE = 0x1, ChatCOLOR = 0x2, ChatTIME = 0x4, ChatECHO = 0x8,
  ChatVERBOSE = 0x1, ChatCOLOR = 0x2, ChatTIME = 0x4, ChatECHO = 0x8
}
 

Constructor & Destructor Documentation

◆ ChatLineMockCore() [1/2]

Basda::ChatLineMockCore::ChatLineMockCore ( )

◆ ~ChatLineMockCore() [1/2]

Basda::ChatLineMockCore::~ChatLineMockCore ( )
virtual

◆ ChatLineMockCore() [2/2]

Basda::ChatLineMockCore::ChatLineMockCore ( )

◆ ~ChatLineMockCore() [2/2]

virtual Basda::ChatLineMockCore::~ChatLineMockCore ( )
virtual

Member Function Documentation

◆ chat() [1/4]

int Basda::ChatLineMockCore::chat ( const char *  _rsp,
int  _max,
const char *  _cmd = NULL 
)
virtual

send line _cmd and recv lines until a line _rsp is received or _max lines received.

For the recv end pattern:

 ?         Matches any single character.
 *         Matches any sequence of zero or more characters.
 [chars]   Matches any single character in chars.
           If chars contains a sequence of  the  form
           a-b then any character between a and b (inclusive) will match.
 \x        Matches the character x.
 {a,b,...} Matches any of the strings a, b, etc.


 Example:
    "*Q"              # wait for a line with Q at the end.
    "{good,bad}"      # wait for a line that is good or bad.

Reimplemented from Nice::ChatLine.

◆ chat() [2/4]

virtual int Basda::ChatLineMockCore::chat ( const char *  _rsp,
int  _max,
const char *  _cmd = NULL 
)
virtual

send line _cmd and recv lines until a line _rsp is received or _max lines received.

For the recv end pattern:

 ?         Matches any single character.
 *         Matches any sequence of zero or more characters.
 [chars]   Matches any single character in chars.
           If chars contains a sequence of  the  form
           a-b then any character between a and b (inclusive) will match.
 \x        Matches the character x.
 {a,b,...} Matches any of the strings a, b, etc.


 Example:
    "*Q"              # wait for a line with Q at the end.
    "{good,bad}"      # wait for a line that is good or bad.

Reimplemented from Nice::ChatLine.

◆ chat() [3/4]

virtual int Basda::ChatLineMockCore::chat ( const char *  _rsp,
const char *  _cmd = NULL 
)
virtual

send line _cmd and recv lines until a line _rsp is received.

For the recv end pattern:

 ?         Matches any single character.
 *         Matches any sequence of zero or more characters.
 [chars]   Matches any single character in chars.
           If chars contains a sequence of  the  form
           a-b then any character between a and b (inclusive) will match.
 \x        Matches the character x.
 {a,b,...} Matches any of the strings a, b, etc.


 Example:
    "*Q"              # wait for a line with Q at the end.
    "{good,bad}"      # wait for a line that is good or bad.

Reimplemented from Nice::ChatLine.

◆ chat() [4/4]

int Basda::ChatLineMockCore::chat ( const char *  _rsp,
const char *  _cmd = NULL 
)
virtual

send line _cmd and recv lines until a line _rsp is received.

For the recv end pattern:

 ?         Matches any single character.
 *         Matches any sequence of zero or more characters.
 [chars]   Matches any single character in chars.
           If chars contains a sequence of  the  form
           a-b then any character between a and b (inclusive) will match.
 \x        Matches the character x.
 {a,b,...} Matches any of the strings a, b, etc.


 Example:
    "*Q"              # wait for a line with Q at the end.
    "{good,bad}"      # wait for a line that is good or bad.

Reimplemented from Nice::ChatLine.

◆ checkNextEvent() [1/2]

Nice::Time Basda::ChatLineMockCore::checkNextEvent ( )
protectedvirtual

◆ checkNextEvent() [2/2]

virtual Nice::Time Basda::ChatLineMockCore::checkNextEvent ( )
protectedvirtual

◆ close() [1/2]

virtual int Basda::ChatLineMockCore::close ( )
inlinevirtual

closedevice

Reimplemented from Nice::ChatCore.

◆ close() [2/2]

virtual int Basda::ChatLineMockCore::close ( )
inlinevirtual

closedevice

Reimplemented from Nice::ChatCore.

◆ getBuffer() [1/2]

std::vector< std::string > Basda::ChatLineMockCore::getBuffer ( )
virtual

All command responses are stored in the serial buffer (m_srbuffer).

The client is able to read out the buffer via that method.

◆ getBuffer() [2/2]

virtual std::vector<std::string> Basda::ChatLineMockCore::getBuffer ( )
virtual

All command responses are stored in the serial buffer (m_srbuffer).

The client is able to read out the buffer via that method.

◆ getResponse() [1/2]

int Basda::ChatLineMockCore::getResponse ( const unsigned int  _cmdID,
const int  _max = -1,
const char *  _cmd = "" 
)
protectedvirtual

This command is used by the chat method to response for the correct command request.

It checks for event messages first and than for the command requests.

Parameters
_cmdIDThe command ID of the command request.
_maxThis number indicates how many lines the service want to be receive at once. If the number is -1, all lines will be send back.
_cmdThe command string is used for auto generation of the command response.
Returns
how many characters are read. A return value of -7777 indicates a read timeout.

Reimplemented in Basda::ChatLineMockMocon, Basda::ChatLineMockMocon, Basda::ChatLineMockCocon, Basda::ChatLineMockUnimod, Basda::ChatLineMockCocon, and Basda::ChatLineMockUnimod.

◆ getResponse() [2/2]

virtual int Basda::ChatLineMockCore::getResponse ( const unsigned int  _cmdID,
const int  _max = -1,
const char *  _cmd = "" 
)
protectedvirtual

This command is used by the chat method to response for the correct command request.

It checks for event messages first and than for the command requests.

Parameters
_cmdIDThe command ID of the command request.
_maxThis number indicates how many lines the service want to be receive at once. If the number is -1, all lines will be send back.
_cmdThe command string is used for auto generation of the command response.
Returns
how many characters are read. A return value of -7777 indicates a read timeout.

Reimplemented in Basda::ChatLineMockMocon, Basda::ChatLineMockMocon, Basda::ChatLineMockCocon, Basda::ChatLineMockUnimod, Basda::ChatLineMockCocon, and Basda::ChatLineMockUnimod.

◆ nprintf() [1/2]

virtual int Basda::ChatLineMockCore::nprintf ( int  _max,
const char *  _rsp_fmtstr,
const char *  _cmd_fmtstr,
  ... 
)
virtual

send line _cmd with params (like printf) and recv lines until a line _rsp is received or _max lines received.

For the recv end pattern:

 ?         Matches any single character.
 *         Matches any sequence of zero or more characters.
 [chars]   Matches any single character in chars.
           If chars contains a sequence of  the  form
           a-b then any character between a and b (inclusive) will match.
 \x        Matches the character x.
 {a,b,...} Matches any of the strings a, b, etc.


 Example:
    "*Q"              # wait for a line with Q at the end.
    "{good,bad}"      # wait for a line that is good or bad.

Reimplemented from Nice::ChatLine.

◆ nprintf() [2/2]

int Basda::ChatLineMockCore::nprintf ( int  _max,
const char *  _rsp_fmtstr,
const char *  _cmd_fmtstr,
  ... 
)
virtual

send line _cmd with params (like printf) and recv lines until a line _rsp is received or _max lines received.

For the recv end pattern:

 ?         Matches any single character.
 *         Matches any sequence of zero or more characters.
 [chars]   Matches any single character in chars.
           If chars contains a sequence of  the  form
           a-b then any character between a and b (inclusive) will match.
 \x        Matches the character x.
 {a,b,...} Matches any of the strings a, b, etc.


 Example:
    "*Q"              # wait for a line with Q at the end.
    "{good,bad}"      # wait for a line that is good or bad.

Reimplemented from Nice::ChatLine.

◆ open() [1/2]

int Basda::ChatLineMockCore::open ( const char *  _device)
virtual

open device with name tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD.

Reimplemented from Nice::ChatCore.

◆ open() [2/2]

virtual int Basda::ChatLineMockCore::open ( const char *  _device)
virtual

open device with name tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD.

Reimplemented from Nice::ChatCore.

◆ operator[]() [1/2]

std::string Basda::ChatLineMockCore::operator[] ( int  _num)

This operation allows to have access to the elements within the serial buffer (m_srbuffer)

Parameters
_numthe index to access the command response

◆ operator[]() [2/2]

std::string Basda::ChatLineMockCore::operator[] ( int  _num)

This operation allows to have access to the elements within the serial buffer (m_srbuffer)

Parameters
_numthe index to access the command response

◆ sendAllEvents() [1/2]

void Basda::ChatLineMockCore::sendAllEvents ( )
protectedvirtual

◆ sendAllEvents() [2/2]

virtual void Basda::ChatLineMockCore::sendAllEvents ( )
protectedvirtual

◆ sendCommandRequest() [1/2]

virtual void Basda::ChatLineMockCore::sendCommandRequest ( const unsigned int  _cmdID,
const char *  _cmd 
)
protectedvirtual

◆ sendCommandRequest() [2/2]

void Basda::ChatLineMockCore::sendCommandRequest ( const unsigned int  _cmdID,
const char *  _cmd 
)
protectedvirtual

◆ setResponse() [1/2]

void Basda::ChatLineMockCore::setResponse ( unsigned int  _cmdID,
std::string  _response,
std::string  _event = "",
Nice::Time  _time = Nice::Time(),
bool  _repeat = false 
)
virtual

This method allows to set the command response.

Depending on which command is called the response string is send back and the device and service has to deal with it.

Parameters
_cmdIDThis is the command ID. All command responses of this command will be send back when this command is called.
_reponseThe command response which will be send back.
_eventIn case this command throws an event, the command event can be set here. This command event will be thrown after _time.
_timeThe relative time when the command event should be thrown. Note: This is not the absolute time. The countdown of the time will be start when the command is called.
_repeatEvery command response will be send only once to the service. If the command is called twice, the second gets no response unless the parameter _repeat is true. If this command is true, the command response will not be deleted from the command response stack.

◆ setResponse() [2/2]

virtual void Basda::ChatLineMockCore::setResponse ( unsigned int  _cmdID,
std::string  _response,
std::string  _event = "",
Nice::Time  _time = Nice::Time(),
bool  _repeat = false 
)
virtual

This method allows to set the command response.

Depending on which command is called the response string is send back and the device and service has to deal with it.

Parameters
_cmdIDThis is the command ID. All command responses of this command will be send back when this command is called.
_reponseThe command response which will be send back.
_eventIn case this command throws an event, the command event can be set here. This command event will be thrown after _time.
_timeThe relative time when the command event should be thrown. Note: This is not the absolute time. The countdown of the time will be start when the command is called.
_repeatEvery command response will be send only once to the service. If the command is called twice, the second gets no response unless the parameter _repeat is true. If this command is true, the command response will not be deleted from the command response stack.

◆ size() [1/2]

virtual unsigned int Basda::ChatLineMockCore::size ( )
inlinevirtual

◆ size() [2/2]

virtual unsigned int Basda::ChatLineMockCore::size ( )
inlinevirtual

◆ tryReadlines() [1/2]

int Basda::ChatLineMockCore::tryReadlines ( const int  _max = -1)
virtual

check if you can savly read a line.

Reimplemented from Nice::ChatLine.

◆ tryReadlines() [2/2]

virtual int Basda::ChatLineMockCore::tryReadlines ( const int  _max = -1)
virtual

check if you can savly read a line.

Reimplemented from Nice::ChatLine.

Member Data Documentation

◆ m_endl

std::string Basda::ChatLineMockCore::m_endl
protected

◆ m_eventStack

std::multimap< Nice::Date, std::vector< std::string > > Basda::ChatLineMockCore::m_eventStack
protected

◆ m_mutex

Nice::Mutex Basda::ChatLineMockCore::m_mutex
protected

◆ m_responseStack

std::multimap< unsigned int, Reply > Basda::ChatLineMockCore::m_responseStack
protected

◆ m_sendVersionString

bool Basda::ChatLineMockCore::m_sendVersionString
protected

◆ m_streamBuffer

std::queue< std::string > Basda::ChatLineMockCore::m_streamBuffer
protected

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