libvisiontransfer
5.0.1
|
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=1048576, int maxUdpPacketSize=1472) | |
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... | |
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.
Supported transfer modes.
Definition at line 33 of file imagetransfer.h.
The result of a partial image transfer.
Definition at line 46 of file imagetransfer.h.
ImageTransfer::ImageTransfer | ( | OperationMode | mode, |
const char * | remoteAddress, | ||
const char * | remoteService, | ||
const char * | localAddress, | ||
const char * | localService, | ||
int | bufferSize = 1048576 , |
||
int | maxUdpPacketSize = 1472 |
||
) |
Creates a new transfer object.
mode | The transfer mode. This determines which network protocol to use, and whether to operate in server or client mode. |
remoteAddress | Address of the remote host. In TCP server mode this parameter can be set to a null pointer. |
remoteService | The remote port number as string or as textual service name. In TCP server mode this parameter can be set to a null pointer. |
localAddress | Local interface address that is used for communication. If set to a null pointer, the default interface is used. |
localService | The local port number as string or a textual service name. If set to a null pointer an automatically assigned port number is used. |
bufferSize | Buffer size for sending / receiving network data. |
maxUdpPacketSize | Maximum allowed size of a UDP packet when sending 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 184 of file imagetransfer.cpp.
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 229 of file imagetransfer.cpp.
std::string ImageTransfer::getClientAddress | ( | ) | const |
Returns the address of the connected client.
This method can only be used in TCP server mode.
Definition at line 233 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 225 of file imagetransfer.cpp.
bool ImageTransfer::receiveImagePair | ( | ImagePair & | imagePair, |
bool | block = true |
||
) |
Waits for and receives a new image pair.
imagePair | Will be set to the received image pair. |
block | If set to true, the method will block and wait for further image data, if a complete image pair hasn't yet been received. |
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.
Definition at line 213 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 217 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 196 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 201 of file imagetransfer.cpp.
void ImageTransfer::setTransferImagePair | ( | const ImagePair & | imagePair | ) |
Sets a new image pair that shall be transmitted.
imagePair | The image pair that shall be transmitted. |
After setting the image pair, subsequent calls to transferData() are necessary for performing the image transmission.
Definition at line 205 of file imagetransfer.cpp.
ImageTransfer::TransferStatus ImageTransfer::transferData | ( | bool | block | ) |
Performs a partial (or full) image transmission.
block | If 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. |
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 209 of file imagetransfer.cpp.
bool ImageTransfer::tryAccept | ( | ) |
Tries to accept a client connection.
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 221 of file imagetransfer.cpp.