libvisiontransfer
10.8.0
|
Class for asynchronous transfer of image sets.
This class opens a network socket for delivering or receiving image sets. All operations are performed asynchronously, which means that they do not block. The class encapsulates ImageTransfer.
Definition at line 50 of file asynctransfer.h.
#include <visiontransfer/asynctransfer.h>
Classes | |
class | Pimpl |
Public Member Functions | |
AsyncTransfer (const char *address, const char *service="7681", ImageProtocol::ProtocolType protType=ImageProtocol::PROTOCOL_UDP, bool server=false, int bufferSize=16 *1048576, int maxUdpPacketSize=1472, int autoReconnectDelay=1) | |
Creates a new transfer object. More... | |
AsyncTransfer (const DeviceInfo &device, int bufferSize=16 *1048576, int maxUdpPacketSize=1472, int autoReconnectDelay=1) | |
Creates a new transfer object by using the device information from device enumeration. More... | |
void | sendImageSetAsync (const ImageSet &imageSet, bool deleteData=false) |
Starts an asynchronous transmission of the given image set. More... | |
bool | collectReceivedImageSet (ImageSet &imageSet, double timeout=-1) |
Collects the asynchronously received image. 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... | |
void | setConnectionStateChangeCallback (std::function< void(visiontransfer::ConnectionState)> callback) |
Install a handler that will be called when the connection state changes (e.g. socket is disconnected). [C++11] More... | |
void | setAutoReconnect (int secondsBetweenRetries=1) |
visiontransfer::AsyncTransfer::AsyncTransfer | ( | const char * | address, |
const char * | service = "7681" , |
||
ImageProtocol::ProtocolType | protType = ImageProtocol::PROTOCOL_UDP , |
||
bool | server = false , |
||
int | bufferSize = 16*1048576 , |
||
int | maxUdpPacketSize = 1472 , |
||
int | autoReconnectDelay = 1 |
||
) |
Creates a new transfer object.
address | Address of the remote host to which a connection should be established. In server mode this can be a local interface address or NULL. |
service | The port number that should be used as string or as textual service name. |
protType | Specifies whether the UDP or TCP transport protocol shall be used. |
server | If set to true, this object will be a communication server. |
bufferSize | Buffer size for sending / receiving network data. |
maxUdpPacketSize | Maximum allowed size of a UDP packet when sending data. |
autoReconnectDelay | Auto-reconnection behavior, see setAutoReconnect |
Please see ImageTransfer::ImageTransfer() for further details.
Definition at line 115 of file asynctransfer.cpp.
visiontransfer::AsyncTransfer::AsyncTransfer | ( | const DeviceInfo & | device, |
int | bufferSize = 16*1048576 , |
||
int | maxUdpPacketSize = 1472 , |
||
int | autoReconnectDelay = 1 |
||
) |
Creates a new transfer object by using the device information from device enumeration.
device | Information on the device to which a connection should be established. |
bufferSize | Buffer size for sending / receiving network data. |
maxUdpPacketSize | Maximum allowed size of a UDP packet when sending data. |
autoReconnectDelay | Auto-reconnection behavior, see setAutoReconnect |
Definition at line 122 of file asynctransfer.cpp.
bool visiontransfer::AsyncTransfer::collectReceivedImageSet | ( | ImageSet & | imageSet, |
double | timeout = -1 |
||
) |
Collects the asynchronously received image.
imageSet | The received image set. |
timeout | The maximum time in seconds for which to wait if no image set has been received yet. |
If no image set has been received, this method might block or return false. Otherwise the returned image set is valid until the next call.
If timeout is set to a value < 0, the function will block indefinitely. If timeout = 0, the function will return immediately, and if timeout is > 0 then the function will block for the given amount of time in seconds. The received image set is only valid until the next call of collectReceivedImageSet().
Definition at line 136 of file asynctransfer.cpp.
void visiontransfer::AsyncTransfer::disconnect | ( | ) |
Terminates the current connection.
If connected to a remote host this connection will be closed.
Definition at line 148 of file asynctransfer.cpp.
int visiontransfer::AsyncTransfer::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 140 of file asynctransfer.cpp.
std::string visiontransfer::AsyncTransfer::getRemoteAddress | ( | ) | const |
Returns the address of the remote host.
Definition at line 154 of file asynctransfer.cpp.
bool visiontransfer::AsyncTransfer::isConnected | ( | ) | const |
Returns true if a remote connection is established.
Definition at line 144 of file asynctransfer.cpp.
void visiontransfer::AsyncTransfer::sendImageSetAsync | ( | const ImageSet & | imageSet, |
bool | deleteData = false |
||
) |
Starts an asynchronous transmission of the given image set.
imageSet | The image set that shall be transmitted. |
deleteData | If set to true, the pointers to the pixel data that are contained in imageSet , will be deleted after the image set has been transmitted. |
If deleteData is set to false, the pixel data contained in imageSet
must not be freed before the data has been transmitted. As transmission happens asynchronously, it is recommended to let AsyncTransfer delete the data pointers.
Definition at line 132 of file asynctransfer.cpp.
void visiontransfer::AsyncTransfer::setConnectionStateChangeCallback | ( | std::function< void(visiontransfer::ConnectionState)> | callback | ) |
Install a handler that will be called when the connection state changes (e.g. socket is disconnected). [C++11]
Definition at line 162 of file asynctransfer.cpp.
bool visiontransfer::AsyncTransfer::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 158 of file asynctransfer.cpp.