TwiceAsNice
2019-02-18
|
Block oriented communication class for serialized data streams, like tcp connections,
More...
#include <Block.h>
Public Member Functions | |
ChatBlock () | |
constructor More... | |
ChatBlock (const char *_device) | |
constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More... | |
ChatBlock (int _fd) | |
constructor with file descriptor More... | |
virtual | ~ChatBlock () |
destructor More... | |
ssize_t | send (const void *buf, size_t count) |
send count block More... | |
ssize_t | recv (void *buf, size_t count) |
recv count block More... | |
ChatBlock () | |
constructor More... | |
ChatBlock (const char *_device) | |
constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More... | |
ChatBlock (int _fd) | |
constructor with file descriptor More... | |
virtual | ~ChatBlock () |
destructor More... | |
ssize_t | send (const void *buf, size_t count) |
send count block More... | |
ssize_t | recv (void *buf, size_t count) |
recv count block More... | |
![]() | |
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 (const char *_device) |
open device with name tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More... | |
virtual int | open (int _fd) |
open device with file descriptor More... | |
virtual int | close () |
closedevice 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 (const char *_device) |
open device with name tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD. More... | |
virtual int | open (int _fd) |
open device with file descriptor More... | |
virtual int | close () |
closedevice 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 | |
void | setStdSettings () |
virtual void | timeoutAktion (const std::string &) |
void | setStdSettings () |
virtual void | timeoutAktion (const std::string &) |
![]() | |
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) |
Additional Inherited Members | |
![]() | |
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 } |
![]() | |
std::string | m_device_name |
int | m_fd |
Nice::Time | m_timeout |
int | verbose_ |
bool | m_persistent |
std::string | m_name |
Block oriented communication class for serialized data streams, like tcp connections,
Connection to a serial driven is done through a tcp connection (tcp://HOSTNAME:PORT) or a tty device (tty:/dev/ttyX:BAUD).
Blockbuilding of the streamd data to lines is done by enddelimiters.
The class can be uses for server and client applications.
Here is small example connecting to a serial device(tty or tcp):
#include"lloglLog.h" #include"ChatBlock.h" if (argc < 2) F_RETURN(-1, "Please give a adress: tcp://HOST:PORT or tty:/dev/TTY:BAUDRATE,DATA"); int main (int argc, char *argv[]) { ChatBlock myDevice; try { myDevice.open(argv[1]); } catch(const Nice::Exception & e) { E_LOG(e); } return 0; }
Here is small example for a tcp server waiting for connections and only accepting one client.
#include"lloglLog.h" #include"ChatBlock.h" int main (int argc, char *argv[]) { ChatBlock myListenDevice; ChatBlock myDevice; int rc; try { while(1) { // open listen port. myListenDevice.openListenSocket(4711); // set timeout to listen forever. myListenDevice.setTimeout(-1); D_LOG("Waiting for connection"); myListenDevice.tryAccept(myDevice); // close listen port. myListenDevice.close(); // connected! myDevice.setVerbose(SRDATA_VERBOSE | SRDATA_COLOR); while(rc > 0); myDevice.close(); } } catch(const Nice::Exception & e) { E_LOG(e); } return 0; }
Connection to a serial driven is done through a tcp connection (tcp://HOSTNAME:PORT) or a tty device (tty:/dev/ttyX:BAUD).
Blockbuilding of the streamd data to lines is done by enddelimiters.
The class can be uses for server and client applications.
Here is small example connecting to a serial device(tty or tcp):
#include"lloglLog.h" #include"ChatBlock.h" if (argc < 2) F_RETURN(-1, "Please give a adress: tcp://HOST:PORT or tty:/dev/TTY:BAUDRATE,DATA"); int main (int argc, char *argv[]) { ChatBlock myDevice; try { myDevice.open(argv[1]); } catch(const Nice::Exception & e) { E_LOG(e); } return 0; }
Here is small example for a tcp server waiting for connections and only accepting one client.
#include"lloglLog.h" #include"ChatBlock.h" int main (int argc, char *argv[]) { ChatBlock myListenDevice; ChatBlock myDevice; int rc; try { while(1) { // open listen port. myListenDevice.openListenSocket(4711); // set timeout to listen forever. myListenDevice.setTimeout(-1); D_LOG("Waiting for connection"); myListenDevice.tryAccept(myDevice); // close listen port. myListenDevice.close(); // connected! myDevice.setVerbose(SRDATA_VERBOSE | SRDATA_COLOR); while(rc > 0); myDevice.close(); } } catch(const Nice::Exception & e) { E_LOG(e); } return 0; }
Nice::ChatBlock::ChatBlock | ( | ) |
constructor
Nice::ChatBlock::ChatBlock | ( | const char * | _device | ) |
constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD.
Nice::ChatBlock::ChatBlock | ( | int | _fd | ) |
constructor with file descriptor
|
virtual |
destructor
Nice::ChatBlock::ChatBlock | ( | ) |
constructor
Nice::ChatBlock::ChatBlock | ( | const char * | _device | ) |
constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD.
Nice::ChatBlock::ChatBlock | ( | int | _fd | ) |
constructor with file descriptor
|
virtual |
destructor
ssize_t Nice::ChatBlock::recv | ( | void * | buf, |
size_t | count | ||
) |
recv count block
ssize_t Nice::ChatBlock::recv | ( | void * | buf, |
size_t | count | ||
) |
recv count block
ssize_t Nice::ChatBlock::send | ( | const void * | buf, |
size_t | count | ||
) |
send count block
ssize_t Nice::ChatBlock::send | ( | const void * | buf, |
size_t | count | ||
) |
send count block
|
protectedvirtual |
Reimplemented from Nice::ChatCore.
|
protectedvirtual |
Reimplemented from Nice::ChatCore.
|
protectedvirtual |
Implements Nice::ChatCore.
|
protectedvirtual |
Implements Nice::ChatCore.