AWS IoT Device SDK C++ v2: eventstream_rpc/include/aws/eventstreamrpc/EventStreamClient.h Source File

AWS IoT Device SDK C++ v2 1.14.0 AWS IoT Device SDK C++ v2

EventStreamClient.h
Go to the documentation of this file.
1#pragma once
7#include <aws/eventstreamrpc/Exports.h>
8
9#include <aws/crt/DateTime.h>
10#include <aws/crt/JsonObject.h>
11#include <aws/crt/StlAllocator.h>
12#include <aws/crt/Types.h>
13#include <aws/crt/UUID.h>
14#include <aws/crt/io/EventLoopGroup.h>
15#include <aws/crt/io/SocketOptions.h>
16#include <aws/crt/io/TlsOptions.h>
17
18#include <aws/crt/io/HostResolver.h>
19
20#include <aws/event-stream/event_stream_rpc_client.h>
21#include <aws/io/host_resolver.h>
22
23#include <atomic>
24#include <functional>
25#include <future>
26#include <memory>
27
28namespace Aws
29{
30 namespace Crt
31 {
32 namespace Io
33 {
34 class ClientBootstrap;
35 }
36 } // namespace Crt
37 namespace Eventstreamrpc
38 {
39 class EventStreamHeader;
40 class MessageAmendment;
41 class ClientOperation;
42 class ClientConnection;
43 class ClientContinuation;
44
45 using HeaderValueType = aws_event_stream_header_value_type;
46 using MessageType = aws_event_stream_rpc_message_type;
47
52 using OnMessageFlushCallback = std::function<void(int errorCode)>;
53
59 using ConnectMessageAmender = std::function<const MessageAmendment &(void)>;
60
64 class AWS_EVENTSTREAMRPC_API EventStreamHeader final
65 {
66 public:
67 EventStreamHeader(const EventStreamHeader &lhs) noexcept;
68 EventStreamHeader(EventStreamHeader &&rhs) noexcept;
69 EventStreamHeader &operator=(const EventStreamHeader &lhs) noexcept;
70 ~EventStreamHeader() noexcept;
71 EventStreamHeader(
72 const struct aws_event_stream_header_value_pair &header,
73 Crt::Allocator *allocator = Crt::g_allocator);
74 EventStreamHeader(const Crt::String &name, bool value);
75 EventStreamHeader(const Crt::String &name, int8_t value);
76 EventStreamHeader(const Crt::String &name, int16_t value);
77 EventStreamHeader(const Crt::String &name, int32_t value);
78 EventStreamHeader(const Crt::String &name, int64_t value);
79 EventStreamHeader(const Crt::String &name, Crt::DateTime &value);
80 EventStreamHeader(
81 const Crt::String &name,
82 const Crt::String &value,
83 Crt::Allocator *allocator = Crt::g_allocator) noexcept;
84 EventStreamHeader(const Crt::String &name, Crt::ByteBuf &value);
85 EventStreamHeader(const Crt::String &name, Crt::UUID value);
86
87 HeaderValueType GetHeaderValueType();
88 Crt::String GetHeaderName() const noexcept;
89 void SetHeaderName(const Crt::String &);
90
91 bool GetValueAsBoolean(bool &);
92 bool GetValueAsByte(int8_t &);
93 bool GetValueAsShort(int16_t &);
94 bool GetValueAsInt(int32_t &);
95 bool GetValueAsLong(int64_t &);
96 bool GetValueAsTimestamp(Crt::DateTime &);
97 bool GetValueAsString(Crt::String &) const noexcept;
98 bool GetValueAsBytes(Crt::ByteBuf &);
99 bool GetValueAsUUID(Crt::UUID &);
100
101 const struct aws_event_stream_header_value_pair *GetUnderlyingHandle() const;
102
103 bool operator==(const EventStreamHeader &other) const noexcept;
104
105 private:
106 Crt::Allocator *m_allocator;
107 Crt::ByteBuf m_valueByteBuf;
108 struct aws_event_stream_header_value_pair m_underlyingHandle;
109 };
110
116 class AWS_EVENTSTREAMRPC_API MessageAmendment final
117 {
118 public:
119 MessageAmendment(const MessageAmendment &lhs);
120 MessageAmendment(MessageAmendment &&rhs);
121 MessageAmendment &operator=(const MessageAmendment &lhs);
122 ~MessageAmendment() noexcept;
123 explicit MessageAmendment(Crt::Allocator *allocator = Crt::g_allocator) noexcept;
124 MessageAmendment(
125 const Crt::List<EventStreamHeader> &headers,
126 Crt::Optional<Crt::ByteBuf> &payload,
127 Crt::Allocator *allocator) noexcept;
128 MessageAmendment(
129 const Crt::List<EventStreamHeader> &headers,
130 Crt::Allocator *allocator = Crt::g_allocator) noexcept;
131 MessageAmendment(
132 Crt::List<EventStreamHeader> &&headers,
133 Crt::Allocator *allocator = Crt::g_allocator) noexcept;
134 MessageAmendment(const Crt::ByteBuf &payload, Crt::Allocator *allocator = Crt::g_allocator) noexcept;
135 void AddHeader(EventStreamHeader &&header) noexcept;
136 void SetPayload(const Crt::Optional<Crt::ByteBuf> &payload) noexcept;
137 const Crt::List<EventStreamHeader> &GetHeaders() const noexcept;
138 const Crt::Optional<Crt::ByteBuf> &GetPayload() const noexcept;
139
140 private:
141 Crt::List<EventStreamHeader> m_headers;
142 Crt::Optional<Crt::ByteBuf> m_payload;
143 Crt::Allocator *m_allocator;
144 };
145
149 class ConnectionConfig
150 {
151 public:
152 ConnectionConfig() noexcept : m_clientBootstrap(nullptr), m_connectRequestCallback(nullptr) {}
153 Crt::Optional<Crt::String> GetHostName() const noexcept { return m_hostName; }
154 Crt::Optional<uint16_t> GetPort() const noexcept { return m_port; }
155 Crt::Optional<Crt::Io::SocketOptions> GetSocketOptions() const noexcept { return m_socketOptions; }
156 Crt::Optional<MessageAmendment> GetConnectAmendment() const noexcept { return m_connectAmendment; }
157 Crt::Optional<Crt::Io::TlsConnectionOptions> GetTlsConnectionOptions() const noexcept
158 {
159 return m_tlsConnectionOptions;
160 }
161 Crt::Io::ClientBootstrap *GetClientBootstrap() const noexcept { return m_clientBootstrap; }
162 OnMessageFlushCallback GetConnectRequestCallback() const noexcept { return m_connectRequestCallback; }
163 ConnectMessageAmender GetConnectMessageAmender() const noexcept
164 {
165 return [&](void) -> const MessageAmendment & { return m_connectAmendment; };
166 }
167
168 void SetHostName(Crt::String hostName) noexcept { m_hostName = hostName; }
169 void SetPort(uint16_t port) noexcept { m_port = port; }
170 void SetSocketOptions(const Crt::Io::SocketOptions &socketOptions) noexcept
171 {
172 m_socketOptions = socketOptions;
173 }
174 void SetConnectAmendment(const MessageAmendment &connectAmendment) noexcept
175 {
176 m_connectAmendment = connectAmendment;
177 }
178 void SetTlsConnectionOptions(Crt::Io::TlsConnectionOptions tlsConnectionOptions) noexcept
179 {
180 m_tlsConnectionOptions = tlsConnectionOptions;
181 }
182 void SetClientBootstrap(Crt::Io::ClientBootstrap *clientBootstrap) noexcept
183 {
184 m_clientBootstrap = clientBootstrap;
185 }
186 void SetConnectRequestCallback(OnMessageFlushCallback connectRequestCallback) noexcept
187 {
188 m_connectRequestCallback = connectRequestCallback;
189 }
190
191 protected:
192 Crt::Optional<Crt::String> m_hostName;
193 Crt::Optional<uint16_t> m_port;
194 Crt::Optional<Crt::Io::SocketOptions> m_socketOptions;
195 Crt::Optional<Crt::Io::TlsConnectionOptions> m_tlsConnectionOptions;
196 Crt::Io::ClientBootstrap *m_clientBootstrap;
197 MessageAmendment m_connectAmendment;
198 OnMessageFlushCallback m_connectRequestCallback;
199 };
200
201 enum EventStreamRpcStatusCode
202 {
203 EVENT_STREAM_RPC_SUCCESS = 0,
204 EVENT_STREAM_RPC_NULL_PARAMETER,
205 EVENT_STREAM_RPC_UNINITIALIZED,
206 EVENT_STREAM_RPC_ALLOCATION_ERROR,
207 EVENT_STREAM_RPC_CONNECTION_SETUP_FAILED,
208 EVENT_STREAM_RPC_CONNECTION_ACCESS_DENIED,
209 EVENT_STREAM_RPC_CONNECTION_ALREADY_ESTABLISHED,
210 EVENT_STREAM_RPC_CONNECTION_CLOSED,
211 EVENT_STREAM_RPC_CONTINUATION_CLOSED,
212 EVENT_STREAM_RPC_UNKNOWN_PROTOCOL_MESSAGE,
213 EVENT_STREAM_RPC_UNMAPPED_DATA,
214 EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE,
215 EVENT_STREAM_RPC_CRT_ERROR
216 };
217
218 struct RpcError
219 {
220 EventStreamRpcStatusCode baseStatus;
221 int crtError;
222 operator bool() const noexcept { return baseStatus == EVENT_STREAM_RPC_SUCCESS; }
223 Crt::String StatusToString();
224 };
225
226 class AWS_EVENTSTREAMRPC_API ConnectionLifecycleHandler
227 {
228 public:
234 virtual void OnConnectCallback();
240 virtual void OnDisconnectCallback(RpcError status);
248 virtual bool OnErrorCallback(RpcError status);
253 virtual void OnPingCallback(
254 const Crt::List<EventStreamHeader> &headers,
255 const Crt::Optional<Crt::ByteBuf> &payload);
256 };
257
258 /* User data passed to callbacks for a new stream. */
259 class ContinuationCallbackData
260 {
261 public:
262 ContinuationCallbackData(
263 ClientContinuation *clientContinuation,
264 Crt::Allocator *allocator = Crt::g_allocator) noexcept
265 : clientContinuation(clientContinuation), allocator(allocator)
266 {
267 continuationDestroyed = false;
268 }
269 ContinuationCallbackData(const ContinuationCallbackData &lhs) noexcept = delete;
270 bool continuationDestroyed;
271 std::mutex callbackMutex;
272 ClientContinuation *clientContinuation;
273 Crt::Allocator *allocator;
274 };
275
276 class AWS_EVENTSTREAMRPC_API ClientContinuationHandler
277 {
278 public:
282 virtual void OnContinuationMessage(
283 const Crt::List<EventStreamHeader> &headers,
284 const Crt::Optional<Crt::ByteBuf> &payload,
285 MessageType messageType,
286 uint32_t messageFlags) = 0;
294 virtual void OnContinuationClosed() = 0;
295 ~ClientContinuationHandler() noexcept;
296
297 private:
298 friend class ClientContinuation;
299 ContinuationCallbackData *m_callbackData;
300 };
301
302 class AWS_EVENTSTREAMRPC_API ClientContinuation final
303 {
304 public:
305 ClientContinuation(
306 ClientConnection *connection,
307 ClientContinuationHandler &continuationHandler,
308 Crt::Allocator *allocator) noexcept;
309 ~ClientContinuation() noexcept;
310 std::future<RpcError> Activate(
311 const Crt::String &operation,
312 const Crt::List<EventStreamHeader> &headers,
313 const Crt::Optional<Crt::ByteBuf> &payload,
314 MessageType messageType,
315 uint32_t messageFlags,
316 OnMessageFlushCallback onMessageFlushCallback) noexcept;
317 bool IsClosed() noexcept;
318 void Release() noexcept;
319 std::future<RpcError> SendMessage(
320 const Crt::List<EventStreamHeader> &headers,
321 const Crt::Optional<Crt::ByteBuf> &payload,
322 MessageType messageType,
323 uint32_t messageFlags,
324 OnMessageFlushCallback onMessageFlushCallback) noexcept;
325
326 private:
327 friend class ClientOperation;
328 Crt::Allocator *m_allocator;
329 ClientContinuationHandler &m_continuationHandler;
330 struct aws_event_stream_rpc_client_continuation_token *m_continuationToken;
331 static void s_onContinuationMessage(
332 struct aws_event_stream_rpc_client_continuation_token *continuationToken,
333 const struct aws_event_stream_rpc_message_args *messageArgs,
334 void *userData) noexcept;
335 static void s_onContinuationClosed(
336 struct aws_event_stream_rpc_client_continuation_token *continuationToken,
337 void *userData) noexcept;
338 };
339
340 class AWS_EVENTSTREAMRPC_API AbstractShapeBase
341 {
342 public:
343 AbstractShapeBase() noexcept;
344 virtual ~AbstractShapeBase() noexcept;
345 static void s_customDeleter(AbstractShapeBase *shape) noexcept;
346 virtual void SerializeToJsonObject(Crt::JsonObject &payloadObject) const = 0;
347 virtual Crt::String GetModelName() const noexcept = 0;
348
349 protected:
350 Crt::Allocator *m_allocator;
351 };
352
353 class AWS_EVENTSTREAMRPC_API OperationError : public AbstractShapeBase
354 {
355 public:
356 explicit OperationError() noexcept;
357 static void s_customDeleter(OperationError *shape) noexcept;
358 virtual void SerializeToJsonObject(Crt::JsonObject &payloadObject) const override;
359 virtual Crt::Optional<Crt::String> GetMessage() noexcept = 0;
360 };
361
367 class AWS_EVENTSTREAMRPC_API StreamResponseHandler
368 {
369 public:
373 virtual void OnStreamClosed();
374
375 protected:
376 friend class ClientOperation;
380 virtual void OnStreamEvent(Crt::ScopedResource<AbstractShapeBase> response);
386 virtual bool OnStreamError(Crt::ScopedResource<OperationError> operationError, RpcError rpcError);
387 };
388
389 enum AWS_EVENTSTREAMRPC_API ResultType
390 {
391 OPERATION_RESPONSE,
392 OPERATION_ERROR,
393 RPC_ERROR
394 };
395
396 class AWS_EVENTSTREAMRPC_API TaggedResult
397 {
398 public:
399 TaggedResult() noexcept;
400 explicit TaggedResult(Crt::ScopedResource<AbstractShapeBase> response) noexcept;
401 explicit TaggedResult(Crt::ScopedResource<OperationError> error) noexcept;
402 explicit TaggedResult(RpcError rpcError) noexcept;
403 TaggedResult(TaggedResult &&rhs) noexcept;
404 TaggedResult &operator=(TaggedResult &&rhs) noexcept;
405 ~TaggedResult() noexcept;
410 operator bool() const noexcept;
411
412 AbstractShapeBase *GetOperationResponse() const noexcept;
413 OperationError *GetOperationError() const noexcept;
414 RpcError GetRpcError() const noexcept;
415 ResultType GetResultType() const noexcept { return m_responseType; }
416
417 private:
418 union AWS_EVENTSTREAMRPC_API OperationResult {
419 OperationResult(Crt::ScopedResource<AbstractShapeBase> &&response) noexcept
420 : m_response(std::move(response))
421 {
422 }
423 OperationResult(Crt::ScopedResource<OperationError> &&error) noexcept : m_error(std::move(error)) {}
424 OperationResult() noexcept : m_response(nullptr) {}
425 ~OperationResult() noexcept {};
426 Crt::ScopedResource<AbstractShapeBase> m_response;
427 Crt::ScopedResource<OperationError> m_error;
428 };
429 ResultType m_responseType;
430 OperationResult m_operationResult;
431 RpcError m_rpcError;
432 };
433
434 using ExpectedResponseFactory = std::function<
435 Crt::ScopedResource<AbstractShapeBase>(const Crt::StringView &payload, Crt::Allocator *allocator)>;
436 using ErrorResponseFactory = std::function<
437 Crt::ScopedResource<OperationError>(const Crt::StringView &payload, Crt::Allocator *allocator)>;
438
439 using LoneResponseRetriever = std::function<ExpectedResponseFactory(const Crt::String &modelName)>;
440 using StreamingResponseRetriever = std::function<ExpectedResponseFactory(const Crt::String &modelName)>;
441 using ErrorResponseRetriever = std::function<ErrorResponseFactory(const Crt::String &modelName)>;
442
443 class AWS_EVENTSTREAMRPC_API ResponseRetriever
444 {
445 /* An interface shared by all operations for retrieving the response object given the model name. */
446 public:
447 virtual ExpectedResponseFactory GetInitialResponseFromModelName(const Crt::String &modelName) const
448 noexcept = 0;
449 virtual ExpectedResponseFactory GetStreamingResponseFromModelName(const Crt::String &modelName) const
450 noexcept = 0;
451 virtual ErrorResponseFactory GetOperationErrorFromModelName(const Crt::String &modelName) const
452 noexcept = 0;
453 };
454
455 class AWS_EVENTSTREAMRPC_API ServiceModel
456 {
457 public:
458 virtual Crt::ScopedResource<OperationError> AllocateOperationErrorFromPayload(
459 const Crt::String &errorModelName,
460 Crt::StringView stringView,
461 Crt::Allocator *allocator) const noexcept = 0;
462 };
463
464 class AWS_EVENTSTREAMRPC_API OperationModelContext
465 {
466 public:
467 OperationModelContext(const ServiceModel &serviceModel) noexcept;
468 virtual Crt::ScopedResource<AbstractShapeBase> AllocateInitialResponseFromPayload(
469 Crt::StringView stringView,
470 Crt::Allocator *allocator) const noexcept = 0;
471 virtual Crt::ScopedResource<AbstractShapeBase> AllocateStreamingResponseFromPayload(
472 Crt::StringView stringView,
473 Crt::Allocator *allocator) const noexcept = 0;
474 virtual Crt::String GetInitialResponseModelName() const noexcept = 0;
475 virtual Crt::String GetRequestModelName() const noexcept = 0;
476 virtual Crt::Optional<Crt::String> GetStreamingResponseModelName() const noexcept = 0;
477 virtual Crt::String GetOperationName() const noexcept = 0;
478 Crt::ScopedResource<OperationError> AllocateOperationErrorFromPayload(
479 const Crt::String &errorModelName,
480 Crt::StringView stringView,
481 Crt::Allocator *allocator) const noexcept
482 {
483 return m_serviceModel.AllocateOperationErrorFromPayload(errorModelName, stringView, allocator);
484 }
485
486 private:
487 const ServiceModel &m_serviceModel;
488 };
489
490 class AWS_EVENTSTREAMRPC_API ClientOperation : private ClientContinuationHandler
491 {
492 public:
493 ClientOperation(
494 ClientConnection &connection,
495 StreamResponseHandler *streamHandler,
496 const OperationModelContext &operationModelContext,
497 Crt::Allocator *allocator) noexcept;
498 ~ClientOperation() noexcept;
499 ClientOperation(const ClientOperation &clientOperation) noexcept = delete;
500 ClientOperation(ClientOperation &&clientOperation) noexcept;
501 std::future<RpcError> Close(OnMessageFlushCallback onMessageFlushCallback = nullptr) noexcept;
502 std::future<TaggedResult> GetOperationResult() noexcept;
503
504 protected:
505 std::future<RpcError> Activate(
506 const AbstractShapeBase *shape,
507 OnMessageFlushCallback onMessageFlushCallback) noexcept;
508 std::future<RpcError> SendStreamEvent(
509 AbstractShapeBase *shape,
510 OnMessageFlushCallback onMessageFlushCallback) noexcept;
511 virtual Crt::String GetModelName() const noexcept = 0;
512 const OperationModelContext &m_operationModelContext;
513
514 private:
515 EventStreamRpcStatusCode HandleData(const Crt::Optional<Crt::ByteBuf> &payload);
516 EventStreamRpcStatusCode HandleError(
517 const Crt::String &modelName,
518 const Crt::Optional<Crt::ByteBuf> &payload,
519 uint32_t messageFlags);
523 void OnContinuationMessage(
524 const Crt::List<EventStreamHeader> &headers,
525 const Crt::Optional<Crt::ByteBuf> &payload,
526 MessageType messageType,
527 uint32_t messageFlags) override;
535 void OnContinuationClosed() override;
536
537 const EventStreamHeader *GetHeaderByName(
538 const Crt::List<EventStreamHeader> &headers,
539 const Crt::String &name) noexcept;
540
541 enum CloseState
542 {
543 WONT_CLOSE = 0,
544 WILL_CLOSE,
545 ALREADY_CLOSED
546 };
547
548 uint32_t m_messageCount;
549 Crt::Allocator *m_allocator;
550 StreamResponseHandler *m_streamHandler;
551 ClientContinuation m_clientContinuation;
552 /* This mutex protects m_resultReceived & m_closeState. */
553 std::mutex m_continuationMutex;
554 bool m_resultReceived;
555 std::promise<TaggedResult> m_initialResponsePromise;
556 std::atomic_int m_expectedCloses;
557 std::atomic_bool m_streamClosedCalled;
558 std::condition_variable m_closeReady;
559 };
560
561 class AWS_EVENTSTREAMRPC_API ClientConnection final
562 {
563 public:
564 ClientConnection(Crt::Allocator *allocator = Crt::g_allocator) noexcept;
565 ~ClientConnection() noexcept;
566 ClientConnection(const ClientConnection &) noexcept = delete;
567 ClientConnection &operator=(const ClientConnection &) noexcept = delete;
568 ClientConnection(ClientConnection &&) noexcept;
569 ClientConnection &operator=(ClientConnection &&) noexcept;
570
571 std::future<RpcError> Connect(
572 const ConnectionConfig &connectionOptions,
573 ConnectionLifecycleHandler *connectionLifecycleHandler,
574 Crt::Io::ClientBootstrap &clientBootstrap) noexcept;
575
576 std::future<RpcError> SendPing(
577 const Crt::List<EventStreamHeader> &headers,
578 const Crt::Optional<Crt::ByteBuf> &payload,
579 OnMessageFlushCallback onMessageFlushCallback) noexcept;
580
581 std::future<RpcError> SendPingResponse(
582 const Crt::List<EventStreamHeader> &headers,
583 const Crt::Optional<Crt::ByteBuf> &payload,
584 OnMessageFlushCallback onMessageFlushCallback) noexcept;
585
586 ClientContinuation NewStream(ClientContinuationHandler &clientContinuationHandler) noexcept;
587
588 void Close() noexcept;
589
590 bool IsOpen() const noexcept
591 {
592 if (this->m_underlyingConnection == nullptr)
593 {
594 return false;
595 }
596 else
597 {
598 return aws_event_stream_rpc_client_connection_is_open(this->m_underlyingConnection);
599 }
600 }
601
605 operator bool() const noexcept { return IsOpen(); }
606
607 private:
608 friend class ClientContinuation;
609 friend std::future<RpcError> ClientOperation::Close(OnMessageFlushCallback onMessageFlushCallback) noexcept;
610 enum ClientState
611 {
612 DISCONNECTED = 1,
613 CONNECTING_SOCKET,
614 WAITING_FOR_CONNECT_ACK,
615 CONNECTED,
616 DISCONNECTING,
617 };
618 std::mutex m_continuationVectorMutex;
619 Crt::Vector<ContinuationCallbackData *> m_continuationCallbackVector;
620 /* This recursive mutex protects m_clientState & m_connectionWillSetup */
621 std::recursive_mutex m_stateMutex;
622 Crt::Allocator *m_allocator;
623 struct aws_event_stream_rpc_client_connection *m_underlyingConnection;
624 ClientState m_clientState;
625 ConnectionLifecycleHandler *m_lifecycleHandler;
626 ConnectMessageAmender m_connectMessageAmender;
627 std::promise<void> m_connectionSetupPromise;
628 bool m_connectionWillSetup;
629 std::promise<RpcError> m_connectAckedPromise;
630 std::promise<RpcError> m_closedPromise;
631 bool m_onConnectCalled;
632 RpcError m_closeReason;
633 OnMessageFlushCallback m_onConnectRequestCallback;
634 Crt::Io::SocketOptions m_socketOptions;
635 ConnectionConfig m_connectionConfig;
636 std::future<RpcError> SendProtocolMessage(
637 const Crt::List<EventStreamHeader> &headers,
638 const Crt::Optional<Crt::ByteBuf> &payload,
639 MessageType messageType,
640 uint32_t messageFlags,
641 OnMessageFlushCallback onMessageFlushCallback) noexcept;
642
643 static void s_onConnectionShutdown(
644 struct aws_event_stream_rpc_client_connection *connection,
645 int errorCode,
646 void *userData) noexcept;
647 static void s_onConnectionSetup(
648 struct aws_event_stream_rpc_client_connection *connection,
649 int errorCode,
650 void *userData) noexcept;
651 static void s_onProtocolMessage(
652 struct aws_event_stream_rpc_client_connection *connection,
653 const struct aws_event_stream_rpc_message_args *messageArgs,
654 void *userData) noexcept;
655
656 static void s_protocolMessageCallback(int errorCode, void *userData) noexcept;
657 static std::future<RpcError> s_sendProtocolMessage(
658 ClientConnection *connection,
659 const Crt::List<EventStreamHeader> &headers,
660 const Crt::Optional<Crt::ByteBuf> &payload,
661 MessageType messageType,
662 uint32_t messageFlags,
663 OnMessageFlushCallback onMessageFlushCallback) noexcept;
664
665 static std::future<RpcError> s_sendPing(
666 ClientConnection *connection,
667 const Crt::List<EventStreamHeader> &headers,
668 const Crt::Optional<Crt::ByteBuf> &payload,
669 OnMessageFlushCallback onMessageFlushCallback) noexcept;
670
671 static std::future<RpcError> s_sendPingResponse(
672 ClientConnection *connection,
673 const Crt::List<EventStreamHeader> &headers,
674 const Crt::Optional<Crt::ByteBuf> &payload,
675 OnMessageFlushCallback onMessageFlushCallback) noexcept;
676 };
677 } // namespace Eventstreamrpc
678} // namespace Aws
DateTime.h
EventLoopGroup.h
OPERATION_RESPONSE
OPERATION_RESPONSE
Definition: EventStreamClient.h:391
OPERATION_ERROR
OPERATION_ERROR
Definition: EventStreamClient.h:392
HostResolver.h
JsonObject.h
SocketOptions.h
StlAllocator.h
TlsOptions.h
Types.h
UUID.h
Aws::Crt::DateTime
Definition: DateTime.h:53
Aws::Crt::Io::ClientBootstrap
Definition: Bootstrap.h:35
Aws::Crt::Io::SocketOptions
Definition: SocketOptions.h:48
Aws::Crt::Io::TlsConnectionOptions
Definition: TlsOptions.h:274
Aws::Crt::JsonObject
Definition: JsonObject.h:21
Aws::Crt::Optional
Definition: Optional.h:17
Aws::Crt::UUID
Definition: UUID.h:19
Aws::Crt::basic_string_view
Definition: StringView.h:32
Aws::Eventstreamrpc::AbstractShapeBase
Definition: EventStreamClient.h:341
Aws::Eventstreamrpc::AbstractShapeBase::SerializeToJsonObject
virtual void SerializeToJsonObject(Crt::JsonObject &payloadObject) const =0
Aws::Eventstreamrpc::AbstractShapeBase::GetModelName
virtual Crt::String GetModelName() const noexcept=0
Aws::Eventstreamrpc::ClientConnection
Definition: EventStreamClient.h:562
Aws::Eventstreamrpc::ClientConnection::operator=
ClientConnection & operator=(const ClientConnection &) noexcept=delete
Aws::Eventstreamrpc::ClientConnection::ClientConnection
ClientConnection(const ClientConnection &) noexcept=delete
Aws::Eventstreamrpc::ClientContinuationHandler
Definition: EventStreamClient.h:277
Aws::Eventstreamrpc::ClientContinuationHandler::OnContinuationMessage
virtual void OnContinuationMessage(const Crt::List< EventStreamHeader > &headers, const Crt::Optional< Crt::ByteBuf > &payload, MessageType messageType, uint32_t messageFlags)=0
Aws::Eventstreamrpc::ClientContinuationHandler::OnContinuationClosed
virtual void OnContinuationClosed()=0
Aws::Eventstreamrpc::ClientContinuation
Definition: EventStreamClient.h:303
Aws::Eventstreamrpc::ClientContinuation::Release
void Release() noexcept
Aws::Eventstreamrpc::ClientOperation
Definition: EventStreamClient.h:491
Aws::Eventstreamrpc::ClientOperation::Close
std::future< RpcError > Close(OnMessageFlushCallback onMessageFlushCallback=nullptr) noexcept
Definition: EventStreamClient.cpp:1532
Aws::Eventstreamrpc::ClientOperation::ClientOperation
ClientOperation(const ClientOperation &clientOperation) noexcept=delete
Aws::Eventstreamrpc::ConnectionConfig
Definition: EventStreamClient.h:150
Aws::Eventstreamrpc::ConnectionConfig::m_port
Crt::Optional< uint16_t > m_port
Definition: EventStreamClient.h:193
Aws::Eventstreamrpc::ConnectionConfig::SetTlsConnectionOptions
void SetTlsConnectionOptions(Crt::Io::TlsConnectionOptions tlsConnectionOptions) noexcept
Definition: EventStreamClient.h:178
Aws::Eventstreamrpc::ConnectionConfig::SetConnectAmendment
void SetConnectAmendment(const MessageAmendment &connectAmendment) noexcept
Definition: EventStreamClient.h:174
Aws::Eventstreamrpc::ConnectionConfig::SetSocketOptions
void SetSocketOptions(const Crt::Io::SocketOptions &socketOptions) noexcept
Definition: EventStreamClient.h:170
Aws::Eventstreamrpc::ConnectionConfig::GetHostName
Crt::Optional< Crt::String > GetHostName() const noexcept
Definition: EventStreamClient.h:153
Aws::Eventstreamrpc::ConnectionConfig::GetClientBootstrap
Crt::Io::ClientBootstrap * GetClientBootstrap() const noexcept
Definition: EventStreamClient.h:161
Aws::Eventstreamrpc::ConnectionConfig::m_tlsConnectionOptions
Crt::Optional< Crt::Io::TlsConnectionOptions > m_tlsConnectionOptions
Definition: EventStreamClient.h:195
Aws::Eventstreamrpc::ConnectionConfig::SetConnectRequestCallback
void SetConnectRequestCallback(OnMessageFlushCallback connectRequestCallback) noexcept
Definition: EventStreamClient.h:186
Aws::Eventstreamrpc::ConnectionConfig::GetTlsConnectionOptions
Crt::Optional< Crt::Io::TlsConnectionOptions > GetTlsConnectionOptions() const noexcept
Definition: EventStreamClient.h:157
Aws::Eventstreamrpc::ConnectionConfig::SetPort
void SetPort(uint16_t port) noexcept
Definition: EventStreamClient.h:169
Aws::Eventstreamrpc::ConnectionConfig::ConnectionConfig
ConnectionConfig() noexcept
Definition: EventStreamClient.h:152
Aws::Eventstreamrpc::ConnectionConfig::GetConnectRequestCallback
OnMessageFlushCallback GetConnectRequestCallback() const noexcept
Definition: EventStreamClient.h:162
Aws::Eventstreamrpc::ConnectionConfig::m_clientBootstrap
Crt::Io::ClientBootstrap * m_clientBootstrap
Definition: EventStreamClient.h:196
Aws::Eventstreamrpc::ConnectionConfig::GetConnectAmendment
Crt::Optional< MessageAmendment > GetConnectAmendment() const noexcept
Definition: EventStreamClient.h:156
Aws::Eventstreamrpc::ConnectionConfig::m_connectAmendment
MessageAmendment m_connectAmendment
Definition: EventStreamClient.h:197
Aws::Eventstreamrpc::ConnectionConfig::SetHostName
void SetHostName(Crt::String hostName) noexcept
Definition: EventStreamClient.h:168
Aws::Eventstreamrpc::ConnectionConfig::m_hostName
Crt::Optional< Crt::String > m_hostName
Definition: EventStreamClient.h:192
Aws::Eventstreamrpc::ConnectionConfig::m_connectRequestCallback
OnMessageFlushCallback m_connectRequestCallback
Definition: EventStreamClient.h:198
Aws::Eventstreamrpc::ConnectionConfig::SetClientBootstrap
void SetClientBootstrap(Crt::Io::ClientBootstrap *clientBootstrap) noexcept
Definition: EventStreamClient.h:182
Aws::Eventstreamrpc::ConnectionConfig::GetPort
Crt::Optional< uint16_t > GetPort() const noexcept
Definition: EventStreamClient.h:154
Aws::Eventstreamrpc::ConnectionConfig::GetConnectMessageAmender
ConnectMessageAmender GetConnectMessageAmender() const noexcept
Definition: EventStreamClient.h:163
Aws::Eventstreamrpc::ConnectionConfig::GetSocketOptions
Crt::Optional< Crt::Io::SocketOptions > GetSocketOptions() const noexcept
Definition: EventStreamClient.h:155
Aws::Eventstreamrpc::ConnectionConfig::m_socketOptions
Crt::Optional< Crt::Io::SocketOptions > m_socketOptions
Definition: EventStreamClient.h:194
Aws::Eventstreamrpc::ConnectionLifecycleHandler
Definition: EventStreamClient.h:227
Aws::Eventstreamrpc::ContinuationCallbackData
Definition: EventStreamClient.h:260
Aws::Eventstreamrpc::ContinuationCallbackData::clientContinuation
ClientContinuation * clientContinuation
Definition: EventStreamClient.h:272
Aws::Eventstreamrpc::ContinuationCallbackData::ContinuationCallbackData
ContinuationCallbackData(ClientContinuation *clientContinuation, Crt::Allocator *allocator=Crt::g_allocator) noexcept
Definition: EventStreamClient.h:262
Aws::Eventstreamrpc::ContinuationCallbackData::continuationDestroyed
bool continuationDestroyed
Definition: EventStreamClient.h:270
Aws::Eventstreamrpc::ContinuationCallbackData::callbackMutex
std::mutex callbackMutex
Definition: EventStreamClient.h:271
Aws::Eventstreamrpc::ContinuationCallbackData::allocator
Crt::Allocator * allocator
Definition: EventStreamClient.h:273
Aws::Eventstreamrpc::ContinuationCallbackData::ContinuationCallbackData
ContinuationCallbackData(const ContinuationCallbackData &lhs) noexcept=delete
Aws::Eventstreamrpc::EventStreamHeader
Definition: EventStreamClient.h:65
Aws::Eventstreamrpc::EventStreamHeader::EventStreamHeader
EventStreamHeader(const Crt::String &name, int64_t value)
Aws::Eventstreamrpc::EventStreamHeader::EventStreamHeader
EventStreamHeader(const Crt::String &name, int8_t value)
Aws::Eventstreamrpc::EventStreamHeader::EventStreamHeader
EventStreamHeader(const Crt::String &name, Crt::UUID value)
Aws::Eventstreamrpc::EventStreamHeader::EventStreamHeader
EventStreamHeader(const Crt::String &name, Crt::ByteBuf &value)
Aws::Eventstreamrpc::EventStreamHeader::EventStreamHeader
EventStreamHeader(const Crt::String &name, int32_t value)
Aws::Eventstreamrpc::EventStreamHeader::EventStreamHeader
EventStreamHeader(const Crt::String &name, bool value)
Aws::Eventstreamrpc::EventStreamHeader::EventStreamHeader
EventStreamHeader(const Crt::String &name, int16_t value)
Aws::Eventstreamrpc::EventStreamHeader::GetHeaderValueType
HeaderValueType GetHeaderValueType()
Aws::Eventstreamrpc::EventStreamHeader::EventStreamHeader
EventStreamHeader(const Crt::String &name, Crt::DateTime &value)
Aws::Eventstreamrpc::MessageAmendment
Definition: EventStreamClient.h:117
Aws::Eventstreamrpc::OperationError
Definition: EventStreamClient.h:354
Aws::Eventstreamrpc::OperationError::GetMessage
virtual Crt::Optional< Crt::String > GetMessage() noexcept=0
Aws::Eventstreamrpc::OperationModelContext
Definition: EventStreamClient.h:465
Aws::Eventstreamrpc::OperationModelContext::AllocateStreamingResponseFromPayload
virtual Crt::ScopedResource< AbstractShapeBase > AllocateStreamingResponseFromPayload(Crt::StringView stringView, Crt::Allocator *allocator) const noexcept=0
Aws::Eventstreamrpc::OperationModelContext::AllocateInitialResponseFromPayload
virtual Crt::ScopedResource< AbstractShapeBase > AllocateInitialResponseFromPayload(Crt::StringView stringView, Crt::Allocator *allocator) const noexcept=0
Aws::Eventstreamrpc::OperationModelContext::GetInitialResponseModelName
virtual Crt::String GetInitialResponseModelName() const noexcept=0
Aws::Eventstreamrpc::ResponseRetriever
Definition: EventStreamClient.h:444
Aws::Eventstreamrpc::ResponseRetriever::GetStreamingResponseFromModelName
virtual ExpectedResponseFactory GetStreamingResponseFromModelName(const Crt::String &modelName) const noexcept=0
Aws::Eventstreamrpc::ResponseRetriever::GetOperationErrorFromModelName
virtual ErrorResponseFactory GetOperationErrorFromModelName(const Crt::String &modelName) const noexcept=0
Aws::Eventstreamrpc::ResponseRetriever::GetInitialResponseFromModelName
virtual ExpectedResponseFactory GetInitialResponseFromModelName(const Crt::String &modelName) const noexcept=0
Aws::Eventstreamrpc::ServiceModel
Definition: EventStreamClient.h:456
Aws::Eventstreamrpc::ServiceModel::AllocateOperationErrorFromPayload
virtual Crt::ScopedResource< OperationError > AllocateOperationErrorFromPayload(const Crt::String &errorModelName, Crt::StringView stringView, Crt::Allocator *allocator) const noexcept=0
Aws::Eventstreamrpc::StreamResponseHandler
Definition: EventStreamClient.h:368
Aws::Eventstreamrpc::TaggedResult
Definition: EventStreamClient.h:397
Aws::Eventstreamrpc::TaggedResult::GetResultType
ResultType GetResultType() const noexcept
Definition: EventStreamClient.h:415
Exports.h
AWS_EVENTSTREAMRPC_API
#define AWS_EVENTSTREAMRPC_API
Definition: Exports.h:19
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:17
Aws::Crt::List
std::list< T, StlAllocator< T > > List
Definition: Types.h:56
Aws::Crt::g_allocator
AWS_CRT_CPP_API Allocator * g_allocator
Definition: Api.cpp:21
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:47
Aws::Crt::StringView
string_view StringView
Definition: StringView.h:845
Aws::Crt::ByteBuf
aws_byte_buf ByteBuf
Definition: Types.h:32
Aws::Crt::ScopedResource
std::unique_ptr< T, std::function< void(T *)> > ScopedResource
Definition: Types.h:165
Aws::Crt::Vector
std::vector< T, StlAllocator< T > > Vector
Definition: Types.h:55
Aws::Eventstreamrpc::MessageType
aws_event_stream_rpc_message_type MessageType
Definition: EventStreamClient.h:46
Aws::Eventstreamrpc::ErrorResponseRetriever
std::function< ErrorResponseFactory(const Crt::String &modelName)> ErrorResponseRetriever
Definition: EventStreamClient.h:441
Aws::Eventstreamrpc::OnMessageFlushCallback
std::function< void(int errorCode)> OnMessageFlushCallback
Definition: EventStreamClient.h:52
Aws::Eventstreamrpc::HeaderValueType
aws_event_stream_header_value_type HeaderValueType
Definition: EventStreamClient.h:45
Aws::Eventstreamrpc::ExpectedResponseFactory
std::function< Crt::ScopedResource< AbstractShapeBase >(const Crt::StringView &payload, Crt::Allocator *allocator)> ExpectedResponseFactory
Definition: EventStreamClient.h:435
Aws::Eventstreamrpc::EventStreamRpcStatusCode
EventStreamRpcStatusCode
Definition: EventStreamClient.h:202
Aws::Eventstreamrpc::EVENT_STREAM_RPC_CONNECTION_SETUP_FAILED
@ EVENT_STREAM_RPC_CONNECTION_SETUP_FAILED
Definition: EventStreamClient.h:207
Aws::Eventstreamrpc::EVENT_STREAM_RPC_UNMAPPED_DATA
@ EVENT_STREAM_RPC_UNMAPPED_DATA
Definition: EventStreamClient.h:213
Aws::Eventstreamrpc::EVENT_STREAM_RPC_CONNECTION_ALREADY_ESTABLISHED
@ EVENT_STREAM_RPC_CONNECTION_ALREADY_ESTABLISHED
Definition: EventStreamClient.h:209
Aws::Eventstreamrpc::EVENT_STREAM_RPC_UNINITIALIZED
@ EVENT_STREAM_RPC_UNINITIALIZED
Definition: EventStreamClient.h:205
Aws::Eventstreamrpc::EVENT_STREAM_RPC_NULL_PARAMETER
@ EVENT_STREAM_RPC_NULL_PARAMETER
Definition: EventStreamClient.h:204
Aws::Eventstreamrpc::EVENT_STREAM_RPC_CRT_ERROR
@ EVENT_STREAM_RPC_CRT_ERROR
Definition: EventStreamClient.h:215
Aws::Eventstreamrpc::EVENT_STREAM_RPC_SUCCESS
@ EVENT_STREAM_RPC_SUCCESS
Definition: EventStreamClient.h:203
Aws::Eventstreamrpc::EVENT_STREAM_RPC_CONNECTION_ACCESS_DENIED
@ EVENT_STREAM_RPC_CONNECTION_ACCESS_DENIED
Definition: EventStreamClient.h:208
Aws::Eventstreamrpc::EVENT_STREAM_RPC_CONTINUATION_CLOSED
@ EVENT_STREAM_RPC_CONTINUATION_CLOSED
Definition: EventStreamClient.h:211
Aws::Eventstreamrpc::EVENT_STREAM_RPC_CONNECTION_CLOSED
@ EVENT_STREAM_RPC_CONNECTION_CLOSED
Definition: EventStreamClient.h:210
Aws::Eventstreamrpc::EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE
@ EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE
Definition: EventStreamClient.h:214
Aws::Eventstreamrpc::EVENT_STREAM_RPC_UNKNOWN_PROTOCOL_MESSAGE
@ EVENT_STREAM_RPC_UNKNOWN_PROTOCOL_MESSAGE
Definition: EventStreamClient.h:212
Aws::Eventstreamrpc::EVENT_STREAM_RPC_ALLOCATION_ERROR
@ EVENT_STREAM_RPC_ALLOCATION_ERROR
Definition: EventStreamClient.h:206
Aws::Eventstreamrpc::StreamingResponseRetriever
std::function< ExpectedResponseFactory(const Crt::String &modelName)> StreamingResponseRetriever
Definition: EventStreamClient.h:440
Aws::Eventstreamrpc::ConnectMessageAmender
std::function< const MessageAmendment &(void)> ConnectMessageAmender
Definition: EventStreamClient.h:59
Aws::Eventstreamrpc::LoneResponseRetriever
std::function< ExpectedResponseFactory(const Crt::String &modelName)> LoneResponseRetriever
Definition: EventStreamClient.h:439
Aws::Eventstreamrpc::ErrorResponseFactory
std::function< Crt::ScopedResource< OperationError >(const Crt::StringView &payload, Crt::Allocator *allocator)> ErrorResponseFactory
Definition: EventStreamClient.h:437
Aws
Definition: Api.h:17
Aws::name
const char *const name
Definition: cJSON.h:282
std
Definition: StringView.h:851
Aws::Eventstreamrpc::RpcError
Definition: EventStreamClient.h:219
Aws::Eventstreamrpc::RpcError::crtError
int crtError
Definition: EventStreamClient.h:221
Aws::Eventstreamrpc::RpcError::baseStatus
EventStreamRpcStatusCode baseStatus
Definition: EventStreamClient.h:220
error
Definition: cJSON.cpp:105