TcpLib
Loading...
Searching...
No Matches
tcp::DataReceiver Class Referenceabstract

Superclass for all TcpReceiver that communicate via a SOCKET and deliver their receive result, a type derived from AbstractMessage, to their "owner".
Since a message can be composed (it is a stream, which may be delivered in chunks), a buffer is created here, which contains data as long as the stream is not complete. More...

#include <TcpDataReceiver.h>

Inheritance diagram for tcp::DataReceiver:
Collaboration diagram for tcp::DataReceiver:

Public Member Functions

 DataReceiver (TcpMain *pParent, SOCKET Socket, unsigned int uiDataSize)
 
virtual ~DataReceiver ()
 
void setDataSize (unsigned int uiDataSize)
 
unsigned int getDataSize () const
 
- Public Member Functions inherited from tcp::Receiver
 Receiver (TcpMain *pParent, SOCKET Socket)
 
virtual ~Receiver ()
 
- Public Member Functions inherited from tcp::ReceiverTransmitter
 ReceiverTransmitter (SOCKET Socket)
 
virtual ~ReceiverTransmitter ()
 
virtual void takeABreak () override
 
virtual void finishBreak () override
 
int getPeerName (std::string &rstrIPAdress, unsigned int &ruiPort) const
 
SOCKET Socket () const
 
- Public Member Functions inherited from eut::RepeatingThread
 RepeatingThread ()
 
virtual ~RepeatingThread ()
 
virtual int start ()
 
virtual void cancel ()
 
bool testCancel ()
 
RepeatingThread::STATUS status () const
 
bool isInExclusiveAccess () const
 
void setExclusiveAccess ()
 
void unsetExclusiveAccess ()
 
int getBreakCounter ()
 
void waitForInput ()
 
void signalInput ()
 

Protected Member Functions

 DataReceiver ()
 
 DataReceiver (SOCKET)
 
 DataReceiver (TcpMain *, SOCKET)
 
void initStreamData ()
 
int processReceivedData (char *pszSentBuffer, unsigned int t_uiSentBufferSize)
 
virtual int acceptMessage (AbstractMessage *)=0
 
virtual void generateNewTcpMessage (AbstractMessage *&prTcpAbstractMessage, char *pszTransmitData, unsigned int uiTransmitDataSize) const =0
 
virtual void generateNewTcpMessage (AbstractMessage *&prTcpAbstractMessage, char *pszRawMsg, unsigned int uiRawMsgSize, unsigned int uiMessageID, int iActionCode, const std::string &rstrInfo) const =0
 
- Protected Member Functions inherited from tcp::Receiver
 Receiver ()
 
 Receiver (SOCKET Socket)
 
- Protected Member Functions inherited from tcp::ReceiverTransmitter
 ReceiverTransmitter ()
 
- Protected Member Functions inherited from eut::RepeatingThread
void threadWork ()
 
void setStatus (STATUS eStatus)
 
STATUS getStatus ()
 
void toOrder (ORDER eOrder)
 
ORDER getOrder ()
 
virtual void work ()=0
 

Protected Attributes

unsigned int m_uiDataSize
 
unsigned int m_uiStreamSize
 
unsigned int m_uiStreamPosistion
 
char * m_szStreamBuffer
 
char * m_pszSentBuffer
 
- Protected Attributes inherited from tcp::Receiver
TcpMainm_pParentTcpMain
 
- Protected Attributes inherited from tcp::ReceiverTransmitter
SOCKET m_Socket
 

Private Member Functions

 DataReceiver (const DataReceiver &)
 
DataReceiveroperator= (const DataReceiver &)
 

Additional Inherited Members

- Public Types inherited from eut::RepeatingThread
enum  EuTHREADERROR { EuTHREAD_ERR_NO_THREAD = -10301 , EuTHREAD_ERR_THREAD_ALREADY_WORKING = -10302 , EuTHREAD_ERR_THREAD_BREAK_COUNT_LESS_THAN_ZERO = -10303 , EuTHREAD_ERR_UNKNOWN = -10400 }
 Error range = -10301 to -10400 More...
 
enum  STATUS {
  eAT_THE_START , eWORKING , ePAUSING , eENDING ,
  eCOMPLETED
}
 
enum  ORDER { eUNDEFINED , eDO_WORK , eEXIT }
 

Detailed Description

Superclass for all TcpReceiver that communicate via a SOCKET and deliver their receive result, a type derived from AbstractMessage, to their "owner".
Since a message can be composed (it is a stream, which may be delivered in chunks), a buffer is created here, which contains data as long as the stream is not complete.

Author
Helmut Jakoby

Constructor & Destructor Documentation

◆ DataReceiver() [1/5]

tcp::DataReceiver::DataReceiver ( )
protected

This constructor is not available.

◆ DataReceiver() [2/5]

tcp::DataReceiver::DataReceiver ( SOCKET )
protected

This constructor is not available.

◆ DataReceiver() [3/5]

tcp::DataReceiver::DataReceiver ( TcpMain * ,
SOCKET  )
protected

This constructor is not available.

◆ DataReceiver() [4/5]

tcp::DataReceiver::DataReceiver ( TcpMain * pParent,
SOCKET Socket,
unsigned int uiDataSize )

Constructor with parameter passing.

Parameters
[in]pParentThe owning parent object.
[in]SocketThe socket through which communication takes place.
[in]uiDataSizeThe package size.
Exceptions
eut::ErrorNExceptionAn exception is thrown if an error occurs.

◆ ~DataReceiver()

virtual tcp::DataReceiver::~DataReceiver ( )
virtual

Destructor. It cleans up the individual buffers.

◆ DataReceiver() [5/5]

tcp::DataReceiver::DataReceiver ( const DataReceiver & )
private

The copy constructor is not available.

Member Function Documentation

◆ acceptMessage()

virtual int tcp::DataReceiver::acceptMessage ( AbstractMessage * )
protectedpure virtual

In subclasses, forwards the passed message to its "owner" or edits it itself. The message must be deleted in any case.

Returns
A return < 0 indicates an error.
Attention
The passed object must not be removed from memory by the calling instance.
See also
AbstractMessage, Message, ServerAcceptMessage, ServerMessage

Implemented in tcp::ClientReceiver, and tcp::ServerReceiver.

◆ generateNewTcpMessage() [1/2]

virtual void tcp::DataReceiver::generateNewTcpMessage ( AbstractMessage *& prTcpAbstractMessage,
char * pszRawMsg,
unsigned int uiRawMsgSize,
unsigned int uiMessageID,
int iActionCode,
const std::string & rstrInfo ) const
protectedpure virtual

Generates in subclasses a message derived from AbstractMessage from passed parameters.

Parameters
[in,out]prTcpAbstractMessagePointer to newly generated Message. This object takes over the removal of the pszRawMsg from the memory.
[in]pszRawMsgThe message data.
[in]uiRawMsgSizeThe size or length of the message data.
[in]uiMessageIDA unique ID.
[in]iActionCodeThe ActionCode.
[in]rstrInfoAn additional text info
Attention
The supplied object must be removed from memory by the calling instance.
See also
AbstractMessage, Message, ServerAcceptMessage, ServerMessage

Implemented in tcp::ClientReceiver, and tcp::ServerReceiver.

◆ generateNewTcpMessage() [2/2]

virtual void tcp::DataReceiver::generateNewTcpMessage ( AbstractMessage *& prTcpAbstractMessage,
char * pszTransmitData,
unsigned int uiTransmitDataSize ) const
protectedpure virtual

Generates in subclasses a message derived from AbstractMessage from the passed data buffer and its size.

Parameters
[in,out]prTcpAbstractMessagePointer to newly generated Message. This object takes care of removing the pszTransmitData from the memory.
[in]pszTransmitDataThe data buffer including all required information.
[in]uiTransmitDataSizeThe size or length of the data buffer to be sent.
Attention
The supplied object must be removed from memory by the calling instance.
See also
AbstractMessage, Message, ServerAcceptMessage, ServerMessage

Implemented in tcp::ClientReceiver, and tcp::ServerReceiver.

◆ getDataSize()

unsigned int tcp::DataReceiver::getDataSize ( ) const

Returns the packet size.

Returns
, see above.

◆ initStreamData()

void tcp::DataReceiver::initStreamData ( )
protected

Initializes the stream data (sets everything to zero).

◆ operator=()

DataReceiver & tcp::DataReceiver::operator= ( const DataReceiver & )
private

The assignment operator is not available.

◆ processReceivedData()

int tcp::DataReceiver::processReceivedData ( char * pszSentBuffer,
unsigned int t_uiSentBufferSize )
protected

Processes the received data and constructs a message from it (derived from AbstractMessage by calling the method generateNewTcpMessage (...) ) and passes it on to its owner via acceptMessage (...) .

Parameters
[in]pszSentBufferThe received buffer
[in]t_uiSentBufferSizeThe size of the buffer received
Returns
A return < 0 indicates an error.

◆ setDataSize()

void tcp::DataReceiver::setDataSize ( unsigned int uiDataSize)

Sets the packet size.

Parameters
[in]uiDataSizeThe package size.

Member Data Documentation

◆ m_pszSentBuffer

char* tcp::DataReceiver::m_pszSentBuffer
protected

The received buffer in one receive step. Is transferred to the m_szStreamBuffer. If the size of the expected data packet is not yet reached, the next received buffer is appended to m_szStreamBuffer.

◆ m_szStreamBuffer

char* tcp::DataReceiver::m_szStreamBuffer
protected

The received buffer, possibly composed of several sent m_pszSentBuffer.

See also
m_pszSentBuffer

◆ m_uiDataSize

unsigned int tcp::DataReceiver::m_uiDataSize
protected

The data packet size.

◆ m_uiStreamPosistion

unsigned int tcp::DataReceiver::m_uiStreamPosistion
protected

The current stream position.

◆ m_uiStreamSize

unsigned int tcp::DataReceiver::m_uiStreamSize
protected

The stream size (from the header).


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