libvisiontransfer  6.1.1
Classes | Public Types | Public Member Functions | List of all members
ImageTransfer Class Reference

Class for synchronous transfer of image pairs. More...

#include <visiontransfer/imagetransfer.h>

Classes

class  Pimpl
 

Public Types

enum  TransferStatus {
  ALL_TRANSFERRED, PARTIAL_TRANSFER, NO_VALID_DATA, WOULD_BLOCK,
  NOT_CONNECTED
}
 The result of a partial image transfer. More...
 

Public Member Functions

 ImageTransfer (const char *address, const char *service="7681", ImageProtocol::ProtocolType protType=ImageProtocol::PROTOCOL_UDP, bool server=false, int bufferSize=1048576, int maxUdpPacketSize=1472)
 Creates a new transfer object by manually specifying the target address. More...
 
 ImageTransfer (const DeviceInfo &device, int bufferSize=1048576, int maxUdpPacketSize=1472)
 Creates a new transfer object by using the device information from device enumeration,. More...
 
void setRawTransferData (const ImagePair &metaData, unsigned char *rawData, int secondTileWidth=0, int validBytes=0x7FFFFFFF)
 Sets the raw pixel data for a partial image transmission. More...
 
void setRawValidBytes (int validBytes)
 Updates the number of valid bytes in a partial raw transmission. More...
 
void setTransferImagePair (const ImagePair &imagePair)
 Sets a new image pair that shall be transmitted. More...
 
TransferStatus transferData ()
 Performs a partial (or full) image transmission. More...
 
bool receiveImagePair (ImagePair &imagePair)
 Waits for and receives a new image pair. More...
 
bool receivePartialImagePair (ImagePair &imagePair, int &validRows, bool &complete)
 Returns the received image pair, even if it is not yet complete. More...
 
int getNumDroppedFrames () const
 Returns the number of frames that have been dropped since connecting to the current remote host. More...
 
bool tryAccept ()
 Tries to accept a client connection. More...
 
bool isConnected () const
 Returns true if a remote connection is established. More...
 
void disconnect ()
 Terminates the current connection. More...
 
std::string getRemoteAddress () const
 Returns the address of the remote host. More...
 

Detailed Description

Class for synchronous transfer of image pairs.

This class opens a network socket for delivering or receiving image pairs. All operations are performed synchronously, which means that they might block. The class encapsulates ImageProtocol.

This class is thread safe for as long as sending and receiving data each has its dedicated thread.

Definition at line 34 of file imagetransfer.h.

Member Enumeration Documentation

◆ TransferStatus

The result of a partial image transfer.

Enumerator
ALL_TRANSFERRED 

The image pair has been transferred completely.

PARTIAL_TRANSFER 

The image pair has been transferred partially. Further transfers are necessary.

NO_VALID_DATA 

There is currently no more data that could be transmitted.

WOULD_BLOCK 

The operation would block and blocking as been disabled.

NOT_CONNECTED 

No network connection has been established.

Definition at line 37 of file imagetransfer.h.

Constructor & Destructor Documentation

◆ ImageTransfer() [1/2]

ImageTransfer::ImageTransfer ( const char *  address,
const char *  service = "7681",
ImageProtocol::ProtocolType  protType = ImageProtocol::PROTOCOL_UDP,
bool  server = false,
int  bufferSize = 1048576,
int  maxUdpPacketSize = 1472 
)

Creates a new transfer object by manually specifying the target address.

Parameters
addressAddress of the remote host to which a connection should be established. In server mode this can be a local interface address or NULL.
serviceThe port number that should be used as string or as textual service name.
protTypeSpecifies whether the UDP or TCP transport protocol shall be used.
serverIf set to true, this object will be a communication server.
bufferSizeBuffer size for sending / receiving network data.
maxUdpPacketSizeMaximum allowed size of a UDP packet when sending data.

Definition at line 98 of file imagetransfer.cpp.

◆ ImageTransfer() [2/2]

ImageTransfer::ImageTransfer ( const DeviceInfo device,
int  bufferSize = 1048576,
int  maxUdpPacketSize = 1472 
)

Creates a new transfer object by using the device information from device enumeration,.

Parameters
deviceInformation on the device to which a connection should be established.
bufferSizeBuffer size for sending / receiving network data.
maxUdpPacketSizeMaximum allowed size of a UDP packet when sending data.

Definition at line 104 of file imagetransfer.cpp.

Member Function Documentation

◆ disconnect()

void ImageTransfer::disconnect ( )

Terminates the current connection.

If connected to a remote host this connection will be closed.

Definition at line 147 of file imagetransfer.cpp.

◆ getNumDroppedFrames()

int ImageTransfer::getNumDroppedFrames ( ) const

Returns the number of frames that have been dropped since connecting to the current remote host.

Dropped frames are caused by dropped packets due to a poor network connection

Definition at line 139 of file imagetransfer.cpp.

◆ getRemoteAddress()

std::string ImageTransfer::getRemoteAddress ( ) const

Returns the address of the remote host.

Returns
Remote address or "" if no connection has been established.

Definition at line 151 of file imagetransfer.cpp.

◆ isConnected()

bool ImageTransfer::isConnected ( ) const

Returns true if a remote connection is established.

Definition at line 143 of file imagetransfer.cpp.

◆ receiveImagePair()

bool ImageTransfer::receiveImagePair ( ImagePair imagePair)

Waits for and receives a new image pair.

Parameters
imagePairWill be set to the received image pair.
Returns
Returns true if a new image pair has been received. Otherwise false.

The received image pair is only valid until the next call of receiveImagePair(). Even if the object is set to blocking mode, the method will not block indefinitely, but return after a short timeout.

See also
ImageProtocol::getReceivedImagePair()

Definition at line 131 of file imagetransfer.cpp.

◆ receivePartialImagePair()

bool ImageTransfer::receivePartialImagePair ( ImagePair imagePair,
int &  validRows,
bool &  complete 
)

Returns the received image pair, even if it is not yet complete.

The received image pair is only valid until calling receivePartialImagePair() for the first time after the current image pair has been received completely. The method returns false if no image data has been received.

Please see ImageProtocol::getPartiallyReceivedImagePair() for further details.

Definition at line 135 of file imagetransfer.cpp.

◆ setRawTransferData()

void ImageTransfer::setRawTransferData ( const ImagePair metaData,
unsigned char *  rawData,
int  secondTileWidth = 0,
int  validBytes = 0x7FFFFFFF 
)

Sets the raw pixel data for a partial image transmission.

This method has to be used in conjunction with transferData(). Please see ImageProtocol::setRawTransferData() for further details.

Definition at line 114 of file imagetransfer.cpp.

◆ setRawValidBytes()

void ImageTransfer::setRawValidBytes ( int  validBytes)

Updates the number of valid bytes in a partial raw transmission.

Please see ImageProtocol::setRawValidBytes() for further details.

Definition at line 119 of file imagetransfer.cpp.

◆ setTransferImagePair()

void ImageTransfer::setTransferImagePair ( const ImagePair imagePair)

Sets a new image pair that shall be transmitted.

Parameters
imagePairThe image pair that shall be transmitted.

After setting the image pair, subsequent calls to transferData() are necessary for performing the image transmission.

See also
ImageProtocol::setTransferImagePair()

Definition at line 123 of file imagetransfer.cpp.

◆ transferData()

ImageTransfer::TransferStatus ImageTransfer::transferData ( )

Performs a partial (or full) image transmission.

Returns
Status of the transmission. See below.

The method transfers up to the specified number of valid bytes. It has to be called in cycles in order to transfer a full image pair. If there is no more data to be transferred, it will return TransferStatus::NO_VALID_DATA.

If the transfer is compete, the method will return TransferStatus::ALL_TRANSFERRED. If there remains outstanding data for this transfer, the return value will be TransferStatus::PARTIAL_TRANSFER. If the connection is no longer open, TransferStatus::CONNECTION_CLOSED is returned. If this call would block and the non-blocking mode is active, then TransferStatus::WOULD_BLOCK is returned.

Even after a complete transfer this method should be continued to be called in case a packed needs to be retransmitted due to an unreliable network connection. Also for a communication server this method should be called frequently to accept incoming connections.

Definition at line 127 of file imagetransfer.cpp.

◆ tryAccept()

bool ImageTransfer::tryAccept ( )

Tries to accept a client connection.

Returns
True if a client has connected.

This method can only be used in TCP server mode. It shall be called in regular intervals to allow for client connections. The method is always non-blocking.

Definition at line 155 of file imagetransfer.cpp.


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