libvisiontransfer  10.8.0
imagetransfer.h
1 /*******************************************************************************
2  * Copyright (c) 2024 Allied Vision Technologies GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #ifndef VISIONTRANSFER_IMAGETRANSFER_H
16 #define VISIONTRANSFER_IMAGETRANSFER_H
17 
18 #include <string>
19 #include "visiontransfer/common.h"
20 #include "visiontransfer/types.h"
21 #include "visiontransfer/imageprotocol.h"
22 #include "visiontransfer/imageset.h"
23 #include "visiontransfer/deviceinfo.h"
24 
25 #if VISIONTRANSFER_CPLUSPLUS_VERSION >= 201103L
26 #include <functional>
27 #endif
28 
29 namespace visiontransfer {
30 
45 class VT_EXPORT ImageTransfer {
46 public:
48  enum TransferStatus {
50  ALL_TRANSFERRED,
51 
54  PARTIAL_TRANSFER,
55 
57  NO_VALID_DATA,
58 
60  WOULD_BLOCK,
61 
63  NOT_CONNECTED
64  };
65 
82  ImageTransfer(const char* address, const char* service = "7681",
84  bool server = false, int bufferSize = 16*1048576, int maxUdpPacketSize = 1472,
85  int autoReconnectDelay=1);
86 
97  ImageTransfer(const DeviceInfo& device, int bufferSize = 16 * 1048576,
98  int maxUdpPacketSize = 1472, int autoReconnectDelay=1);
99 
100  ~ImageTransfer();
101 
108  void setRawTransferData(const ImageSet& metaData, const std::vector<unsigned char*>& rawData,
109  int firstTileWidth = 0, int middleTileWidth = 0, int lastTileWidth = 0);
110 
116  void setRawValidBytes(const std::vector<int>& validBytes);
117 
128  void setTransferImageSet(const ImageSet& imageSet);
129 
152  TransferStatus transferData();
153 
169  bool receiveImageSet(ImageSet& imageSet);
170 
171 #ifndef DOXYGEN_SHOULD_SKIP_THIS
172  DEPRECATED("Use receiveImageSet() instead")
173  inline bool receiveImagePair(ImageSet& imageSet) {
174  return receiveImageSet(imageSet);
175  }
176 #endif
177 
187  bool receivePartialImageSet(ImageSet& imageSet, int& validRows, bool& complete);
188 
189 #ifndef DOXYGEN_SHOULD_SKIP_THIS
190  DEPRECATED("Use receivePartialImageSet() instead")
191  inline bool receivePartialImagePair(ImageSet& imageSet, int& validRows, bool& complete) {
192  return receivePartialImageSet(imageSet, validRows, complete);
193  }
194 #endif
195 
203  int getNumDroppedFrames() const;
204 
214  bool tryAccept();
215 
220  bool isConnected() const;
221 
227  void disconnect();
228 
234  std::string getRemoteAddress() const;
235 
236 #ifndef DOXYGEN_SHOULD_SKIP_THIS
237  std::string statusReport();
239 #endif
240 
241 #if VISIONTRANSFER_CPLUSPLUS_VERSION >= 201103L
242 
246  void setConnectionStateChangeCallback(std::function<void(visiontransfer::ConnectionState)> callback);
247 #endif
248 
249  /*
250  * \brief Configure automatic reconnection behavior (for TCP client mode).
251  *
252  * When enabled, this functionality is initiated whenever a disconnection
253  * is detected, instead of just reporting the disconnection.
254  * By default, automatic reconnection is active with a 1-second wait time.
255  *
256  * NOTE: If enabled, ImageTransfer's receiving and sending functions
257  * will block indefinitely on disconnection until the connection has been
258  * restored. Disconnection will be reported before blocking (see
259  * setConnectionStateChangeCallback).
260  *
261  * \param secondsBetweenRetries Number of seconds to wait between
262  * consecutive reconnection attempts, or 0 to disable auto-reconnection.
263  */
264  void setAutoReconnect(int secondsBetweenRetries=1);
265 
266 private:
267  // We follow the pimpl idiom
268  class Pimpl;
269  Pimpl* pimpl;
270 
271  // This class cannot be copied
272  ImageTransfer(const ImageTransfer& other);
273  ImageTransfer& operator=(const ImageTransfer&);
274 };
275 
276 } // namespace
277 
278 #endif
visiontransfer::ImageTransfer::TransferStatus
TransferStatus
The result of a partial image transfer.
Definition: imagetransfer.h:72
visiontransfer::ImageProtocol::PROTOCOL_UDP
@ PROTOCOL_UDP
The connection-less UDP transport protocol.
Definition: imageprotocol.h:84
visiontransfer::DeviceInfo
Aggregates information about a discovered device.
Definition: deviceinfo.h:59
visiontransfer::ImageSet
A set of one to three images, but usually two (the left camera image and the disparity map)....
Definition: imageset.h:50
visiontransfer::ImageProtocol::ProtocolType
ProtocolType
Supported network protocols.
Definition: imageprotocol.h:67
visiontransfer::ImageTransfer
Class for synchronous transfer of image sets.
Definition: imagetransfer.h:57
Allied Vision