GoPxL SDK
GoCtrlChannel.h
Go to the documentation of this file.
1 
10 #ifndef GO_PXL_SDK_GOCTRLCHANNEL_H
11 #define GO_PXL_SDK_GOCTRLCHANNEL_H
12 
13 
14 #include <kApi/Io/kNetwork.h>
15 #include <kApi/kApiDef.h>
16 
17 #include <GoPxLSdk/Def.h>
18 #include <GoPxLSdk/GoResponse.h>
19 #include <GoPxLSdk/GoRequest.h>
20 
21 namespace GoPxLSdk
22 {
23 
24 enum class ReadErrorType
25 {
26  Unknown, // Indicates there was an unhandled error.
27  DeserializationError, // Indicates there was an error while deserializing data.
28  InvalidMessageType, // Indicates the received message type is invalid.
29  InvalidMessageContent, // Indicates the received message content is invalid.
30 };
31 
35 using GoCtrlChannelResponseHandler = std::function<void(const std::shared_ptr<GoResponse> response)>;
36 
40 using GoCtrlChannelWriteErrorHandler = std::function<void(k64u id, const std::exception& e)>;
41 
45 using GoCtrlChannelReadErrorHandler = std::function<void(ReadErrorType readErrorType, const std::exception& e)>;
46 
52 {
53 public:
60  virtual ~GoCtrlChannel() = default;
61 
72  virtual void Connect(const kIpAddress& address, k16u port,
73  k64u connectionTimeout = GO_PXL_SDK_DEFAULT_TCP_TIMEOUT_MILLISECONDS) = 0;
74 
81  virtual void Disconnect() = 0;
82 
90  virtual bool IsConnected() const = 0;
91 
102  virtual void SendRequest(const GoRequest& request) = 0;
103 
111  virtual void SetResponseHandler(GoCtrlChannelResponseHandler callback) = 0;
112 
113 
122  virtual void SetWriteErrorHandler(GoCtrlChannelWriteErrorHandler callback) = 0;
123 
132  virtual void SetReadErrorHandler(GoCtrlChannelReadErrorHandler callback) = 0;
133 };
134 
135 }
136 
137 #endif
std::function< void(const std::shared_ptr< GoResponse > response)> GoCtrlChannelResponseHandler
Function to receive responses from the server asynchronously.
Definition: GoCtrlChannel.h:35
#define GoPxLSdkClass
Definition: Def.h:35
Interface for all control channel implementations.
Definition: GoCtrlChannel.h:51
Declares the GoPxLSdk.GoResponse class.
constexpr k32u GO_PXL_SDK_DEFAULT_TCP_TIMEOUT_MILLISECONDS
Definition: Def.h:38
Definition: GoRequest.h:22
Declares the general SDK definitions.
ReadErrorType
Definition: GoCtrlChannel.h:24
std::function< void(k64u id, const std::exception &e)> GoCtrlChannelWriteErrorHandler
Function to receive write thread errors.
Definition: GoCtrlChannel.h:40
Declares the GoPxLSdk.GoRequest class.
Definition: Def.h:46
std::function< void(ReadErrorType readErrorType, const std::exception &e)> GoCtrlChannelReadErrorHandler
Function to receive read thread errors.
Definition: GoCtrlChannel.h:45