libvisiontransfer  4.1.5
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  OperationMode { UDP, TCP_CLIENT, TCP_SERVER }
 Supported transfer modes. More...
 
enum  TransferStatus {
  CONNECTION_CLOSED, ALL_TRANSFERRED, PARTIAL_TRANSFER, NO_VALID_DATA,
  WOULD_BLOCK
}
 The result of a partial image transfer. More...
 

Public Member Functions

 ImageTransfer (OperationMode mode, const char *remoteAddress, const char *remoteService, const char *localAddress, const char *localService, int bufferSize=1000000)
 Creates a new transfer object. 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 (bool block)
 Performs a partial (or full) image transmission. More...
 
bool receiveImagePair (ImagePair &imagePair, bool block=true)
 Waits for and receives a new image pair. More...
 
bool receivePartialImagePair (ImagePair &imagePair, int &validRows, bool &complete, bool block=false)
 Returns the received image pair, even if it is not yet complete. More...
 
bool tryAccept ()
 Tries to accept a client connection. More...
 
bool isClientConnected () const
 Returns true if a client is connected. More...
 
void disconnect ()
 Terminates the current connection. More...
 
std::string getClientAddress () const
 Returns the address of the connected client. 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.

Definition at line 30 of file imagetransfer.h.

Member Enumeration Documentation

Supported transfer modes.

Enumerator
UDP 

Using UDP for network transfers. Differentiation between server and client role is not necessary.

TCP_CLIENT 

Using TCP and acting as communication client.

TCP_SERVER 

Using TCP and acting as communication server.

Definition at line 33 of file imagetransfer.h.

The result of a partial image transfer.

Enumerator
CONNECTION_CLOSED 

The connection has been closed by the remote host.

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.

Definition at line 46 of file imagetransfer.h.

Constructor & Destructor Documentation

ImageTransfer::ImageTransfer ( OperationMode  mode,
const char *  remoteAddress,
const char *  remoteService,
const char *  localAddress,
const char *  localService,
int  bufferSize = 1000000 
)

Creates a new transfer object.

Parameters
modeThe transfer mode. This determines which network protocol to use, and whether to operate in server or client mode.
remoteAddressAddress of the remote host. In TCP server mode this parameter can be set to a null pointer.
remoteServiceThe remote port number as string or as textual service name. In TCP server mode this parameter can be set to a null pointer.
localAddressLocal interface address that is used for communication. If set to a null pointer, the default interface is used.
localServiceThe local port number as string or a textual service name. If set to a null pointer an automatically assigned port number is used.
bufferSizeBuffer size for sending / receiving network data.

In TCP server mode, a port is opened to which clients can establish connections. In TCP client mode, a connection is established to the given address and service name.

In UDP mode, a port is opened to which another host can transmit image data. When calling transferData(), image data is transmitted to remote host given in remoteAddress.

Definition at line 180 of file imagetransfer.cpp.

Member Function Documentation

void ImageTransfer::disconnect ( )

Terminates the current connection.

If connected to a server or if a client is currently connected, this connection will be closed.

Definition at line 223 of file imagetransfer.cpp.

std::string ImageTransfer::getClientAddress ( ) const

Returns the address of the connected client.

Returns
Client address or "" if no client is connected.

This method can only be used in TCP server mode.

Definition at line 227 of file imagetransfer.cpp.

bool ImageTransfer::isClientConnected ( ) const

Returns true if a client is connected.

This method can only be used in TCP server mode.

Definition at line 219 of file imagetransfer.cpp.

bool ImageTransfer::receiveImagePair ( ImagePair imagePair,
bool  block = true 
)

Waits for and receives a new image pair.

Parameters
imagePairWill be set to the received image pair.
blockIf set to true, the method will block and wait for further image data, if a complete image pair hasn't yet been received.
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 block is set to true, the method will not block indefinitely, but return after a short timeout.

See also
ImageProtocol::getReceivedImagePair()

Definition at line 207 of file imagetransfer.cpp.

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

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 211 of file imagetransfer.cpp.

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 190 of file imagetransfer.cpp.

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 195 of file imagetransfer.cpp.

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 199 of file imagetransfer.cpp.

ImageTransfer::TransferStatus ImageTransfer::transferData ( bool  block)

Performs a partial (or full) image transmission.

Parameters
blockIf set to true and if the the send buffer is full, the method will block. Otherwise it will return immediately with TransferStatus::WOULD_BLOCK in case of full send buffers.
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.

Definition at line 203 of file imagetransfer.cpp.

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 non-blocking.

Definition at line 215 of file imagetransfer.cpp.


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