libvisiontransfer  10.8.0
asynctransfer.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_ASYNCTRANSFER_H
16 #define VISIONTRANSFER_ASYNCTRANSFER_H
17 
18 #include "visiontransfer/common.h"
19 #include "visiontransfer/types.h"
20 #include "visiontransfer/imagetransfer.h"
21 #include "visiontransfer/imageset.h"
22 #include "visiontransfer/imageprotocol.h"
23 #include "visiontransfer/deviceinfo.h"
24 
25 #if VISIONTRANSFER_CPLUSPLUS_VERSION >= 201103L
26 #include <functional>
27 #endif
28 
29 namespace visiontransfer {
30 
38 class VT_EXPORT AsyncTransfer {
39 public:
57  AsyncTransfer(const char* address, const char* service = "7681",
59  bool server = false, int bufferSize = 16*1048576, int maxUdpPacketSize = 1472,
60  int autoReconnectDelay=1);
61 
72  AsyncTransfer(const DeviceInfo& device, int bufferSize = 16*1048576, int maxUdpPacketSize = 1472,
73  int autoReconnectDelay=1);
74 
75  ~AsyncTransfer();
76 
90  void sendImageSetAsync(const ImageSet& imageSet, bool deleteData = false);
91 
92 #ifndef DOXYGEN_SHOULD_SKIP_THIS
93  DEPRECATED("Use sendImageSetAsync() instead")
94  inline void sendImagePairAsync(const ImageSet& imageSet, bool deleteData = false) {
95  sendImageSetAsync(imageSet, deleteData);
96  }
97 #endif
98 
115  bool collectReceivedImageSet(ImageSet& imageSet, double timeout = -1);
116 
117 #ifndef DOXYGEN_SHOULD_SKIP_THIS
118  DEPRECATED("Use collectReceivedImageSet() instead")
119  inline bool collectReceivedImagePair(ImageSet& imageSet, double timeout = -1) {
120  return collectReceivedImageSet(imageSet, timeout);
121  }
122 #endif
123 
131  int getNumDroppedFrames() const;
132 
142  bool tryAccept();
143 
147  bool isConnected() const;
148 
154  void disconnect();
155 
161  std::string getRemoteAddress() const;
162 
163 #if VISIONTRANSFER_CPLUSPLUS_VERSION >= 201103L
164 
168  void setConnectionStateChangeCallback(std::function<void(visiontransfer::ConnectionState)> callback);
169 #endif
170 
171  /*
172  * \brief Configure automatic reconnection behavior (for TCP client mode).
173  *
174  * When enabled, this functionality is initiated whenever a disconnection
175  * is detected, instead of just reporting the disconnection.
176  * By default, automatic reconnection is active with a 1-second wait time.
177  *
178  * In AsyncTransfer, this behavior runs in the background and does not
179  * block the user-accessible functionality. For being informed of the
180  * current connection state, see setConnectionStateChangeCallback.
181  *
182  * \param secondsBetweenRetries Number of seconds to wait between
183  * consecutive reconnection attempts, or 0 to disable auto-reconnection.
184  */
185  void setAutoReconnect(int secondsBetweenRetries=1);
186 
187 private:
188  // We follow the pimpl idiom
189  class Pimpl;
190  Pimpl* pimpl;
191 
192  // This class cannot be copied
193  AsyncTransfer(const AsyncTransfer& other);
194  AsyncTransfer& operator=(const AsyncTransfer&);
195 };
196 
197 } // namespace
198 
199 #endif
visiontransfer::ImageProtocol::PROTOCOL_UDP
@ PROTOCOL_UDP
The connection-less UDP transport protocol.
Definition: imageprotocol.h:84
visiontransfer::ImageProtocol::ProtocolType
ProtocolType
Supported network protocols.
Definition: imageprotocol.h:67
Allied Vision