GoPxL SDK

- Home
- Files
- Namespace

GoRestClient.h
Go to the documentation of this file.
1
9 #ifndef GO_PXL_SDK_GORESTCLIENT_H
10 #define GO_PXL_SDK_GORESTCLIENT_H
11
12 #include <kApi/Io/kNetwork.h>
13
14 #include <GoPxLSdk/GoJson.h>
15 #include <GoPxLSdk/GoResponse.h>
16 #include <GoPxLSdk/GoTransaction.h>
17 #include <GoPxLSdk/Internal/GoCtrlChannel.h>
18 #include <GoPxLSdk/Internal/V1/GoCtrlChannelV1.h>
19
20 class GoRestClientTests;
21
22 namespace GoPxLSdk
23 {
28 using GoNotificationHandler = std::function<void(const std::shared_ptr<GoNotificationResponse>&)>;
29
34 using GoStreamHandler = std::function<void(const std::shared_ptr<GoStreamResponse>&)>;
35
36 class GoPxLSdkClass GoRestClient
37 {
38 public:
45 GoRestClient();
46
47 ~GoRestClient() = default;
48
58 void Connect(kIpAddress address, k32u port = 0);
59
67 void Disconnect();
68
76 bool IsConnected() const;
77
90 GoTransaction Read(const std::string& uri, const GoJson& content = {}, const GoJson& args = {});
91
104 GoTransaction Update(const std::string& uri, const GoJson& content = {}, const GoJson& args = {});
105
117 GoTransaction Create(const std::string& uri, const GoJson& content = {}, const GoJson& args = {});
118
131 GoTransaction Delete(const std::string& uri, const GoJson& content = {}, const GoJson& args = {});
132
144 GoTransaction Call(const std::string& uri, const GoJson& content = {}, const GoJson& args = {});
145
159 GoTransaction Sub(const std::string& uri, const GoJson& content = {}, const GoJson& args = {});
160
172 GoTransaction UnSub(const std::string& uri, const GoJson& content = {}, const GoJson& args = {});
173
181 void SetSubHandler(const GoNotificationHandler& callback);
182
196 GoTransaction StartStream(const std::string & uri, const GoJson& content = {}, const GoJson& args = {});
197
209 GoTransaction StopStream(const std::string& uri, const GoJson& content = {}, const GoJson& args = {});
210
218 void SetStreamHandler(const GoStreamHandler& callback);
219
220 private:
221 void ResponseHandler(std::shared_ptr<GoResponse> response);
222
223 void ErrorHandler(GoCtrlChannelErrorType type, k64u requestId, const std::exception& e);
224
225 void Callback(std::shared_ptr<GoResponse> response);
226
227 void HandleReadError(const std::exception& e);
228
229 void HandleWriteError(k64u requestId, const std::exception& e);
230
234 std::mutex commandMutex;
235
236 // Using std::deque instead of std::queue, because it provides iterator used by `HandleReadError` and `HandleWriteError`.
237 std::deque<GoTransaction> transactionQueue;
238
239 std::shared_ptr<GoCtrlChannel> channel;
240
241 GoStreamHandler streamHandler;
242 GoNotificationHandler notificationHandler;
243
244 friend class ::GoRestClientTests;
245 };
246
247 }
248
249 #endif
GoPxLSdk::GoJson
Simplify working with json data.
Definition: GoJson.h:38
GoPxLSdk::GoStreamHandler
std::function< void(const std::shared_ptr< GoStreamResponse > &)> GoStreamHandler
Data handler used in GoRestClient::StartStream.
Definition: GoRestClient.h:34
GoPxLSdkClass
#define GoPxLSdkClass
Definition: Def.h:35
GoPxLSdk::GoCtrlChannelErrorType
GoCtrlChannelErrorType
Definition: GoCtrlChannel.h:23
GoCtrlChannel.h
GoPxLSdk::GoCtrlChannelErrorType::Read
GoResponse.h
GoPxLSdk::GoNotificationHandler
std::function< void(const std::shared_ptr< GoNotificationResponse > &)> GoNotificationHandler
Notification handler used in GoRestClient::Sub.
Definition: GoRestClient.h:28
GoCtrlChannelV1.h
GoPxLSdk::GoRestClient
Definition: GoRestClient.h:36
GoTransaction.h
GoJson.h
GoPxLSdk::GoTransaction
Definition: GoTransaction.h:23
GoPxLSdk
Definition: Def.h:46