TwiceAsNice  2019-02-18
Public Member Functions | Protected Member Functions | List of all members
Nice::ChatBlock Class Reference


Block oriented communication class for serialized data streams, like tcp connections, More...

#include <Block.h>

Inheritance diagram for Nice::ChatBlock:
Inheritance graph
Collaboration diagram for Nice::ChatBlock:
Collaboration graph

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...
 
- 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 (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 &)
 
- 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)
 

Additional Inherited Members

- 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
}
 
- 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
 

Detailed Description


Block oriented communication class for serialized data streams, like tcp connections,

Author
Florian Briegel
Version
11.02.04
Date
2012-08-10 11:04:58 AM serial lines (tty), ...

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;
}
Todo:
Some c++ style parameter for chat call
Author
Florian Briegel
Version
11.02.04
Date
2012-08-10 11:04:58 AM serial lines (tty), ...

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;
}
Todo:
Some c++ style parameter for chat call

Constructor & Destructor Documentation

◆ ChatBlock() [1/6]

Nice::ChatBlock::ChatBlock ( )

constructor

◆ ChatBlock() [2/6]

Nice::ChatBlock::ChatBlock ( const char *  _device)

constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD.

◆ ChatBlock() [3/6]

Nice::ChatBlock::ChatBlock ( int  _fd)

constructor with file descriptor

◆ ~ChatBlock() [1/2]

Nice::ChatBlock::~ChatBlock ( )
virtual

destructor

◆ ChatBlock() [4/6]

Nice::ChatBlock::ChatBlock ( )

constructor

◆ ChatBlock() [5/6]

Nice::ChatBlock::ChatBlock ( const char *  _device)

constructor with devicename tcp://HOSTNAME:PORT or tty:/dev/ttyX:BAUD.

◆ ChatBlock() [6/6]

Nice::ChatBlock::ChatBlock ( int  _fd)

constructor with file descriptor

◆ ~ChatBlock() [2/2]

virtual Nice::ChatBlock::~ChatBlock ( )
virtual

destructor

Member Function Documentation

◆ recv() [1/2]

ssize_t Nice::ChatBlock::recv ( void *  buf,
size_t  count 
)

recv count block

◆ recv() [2/2]

ssize_t Nice::ChatBlock::recv ( void *  buf,
size_t  count 
)

recv count block

◆ send() [1/2]

ssize_t Nice::ChatBlock::send ( const void *  buf,
size_t  count 
)

send count block

◆ send() [2/2]

ssize_t Nice::ChatBlock::send ( const void *  buf,
size_t  count 
)

send count block

◆ setStdSettings() [1/2]

void Nice::ChatBlock::setStdSettings ( )
protectedvirtual

Reimplemented from Nice::ChatCore.

◆ setStdSettings() [2/2]

void Nice::ChatBlock::setStdSettings ( )
protectedvirtual

Reimplemented from Nice::ChatCore.

◆ timeoutAktion() [1/2]

void Nice::ChatBlock::timeoutAktion ( const std::string &  )
protectedvirtual

Implements Nice::ChatCore.

◆ timeoutAktion() [2/2]

virtual void Nice::ChatBlock::timeoutAktion ( const std::string &  )
protectedvirtual

Implements Nice::ChatCore.


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