AWS IoT Device SDK C++ v2
1.34.0
AWS IoT Device SDK C++ v2
|
Go to the documentation of this file.
20 #include <aws/event-stream/event_stream_rpc_client.h>
21 #include <aws/io/host_resolver.h>
34 class ClientBootstrap;
37 namespace Eventstreamrpc
72 const struct aws_event_stream_header_value_pair &header,
81 bool GetValueAsString(
Crt::String &)
const noexcept;
83 const struct aws_event_stream_header_value_pair *GetUnderlyingHandle()
const;
90 struct aws_event_stream_header_value_pair m_underlyingHandle;
134 ConnectionConfig() noexcept : m_clientBootstrap(
nullptr), m_connectRequestCallback(
nullptr) {}
141 return m_tlsConnectionOptions;
147 return [&](void) ->
const MessageAmendment & {
return m_connectAmendment; };
151 void SetPort(uint32_t port) noexcept { m_port = port; }
154 m_socketOptions = socketOptions;
158 m_connectAmendment = connectAmendment;
162 m_tlsConnectionOptions = tlsConnectionOptions;
166 m_clientBootstrap = clientBootstrap;
170 m_connectRequestCallback = connectRequestCallback;
221 virtual
void OnConnectCallback();
227 virtual
void OnDisconnectCallback(
RpcError status);
235 virtual
bool OnErrorCallback(
RpcError status);
240 virtual
void OnPingCallback(
242 const Crt::Optional<Crt::
ByteBuf> &payload);
254 : clientContinuation(clientContinuation), allocator(allocator)
256 continuationDestroyed =
false;
278 uint32_t messageFlags) = 0;
326 std::future<RpcError> Activate(
331 uint32_t messageFlags,
338 bool IsClosed() noexcept;
350 std::future<RpcError> SendMessage(
354 uint32_t messageFlags,
361 struct aws_event_stream_rpc_client_continuation_token *m_continuationToken;
364 static void s_onContinuationMessage(
365 struct aws_event_stream_rpc_client_continuation_token *continuationToken,
366 const struct aws_event_stream_rpc_message_args *messageArgs,
367 void *userData) noexcept;
368 static void s_onContinuationClosed(
369 struct aws_event_stream_rpc_client_continuation_token *continuationToken,
370 void *userData) noexcept;
382 virtual
void SerializeToJsonObject(Crt::JsonObject &payloadObject) const = 0;
383 virtual Crt::
String GetModelName() const noexcept = 0;
397 virtual
void SerializeToJsonObject(Crt::JsonObject &payloadObject) const override;
398 virtual Crt::Optional<Crt::
String> GetMessage() noexcept = 0;
414 virtual
void OnStreamClosed();
454 operator bool()
const noexcept;
472 RpcError GetRpcError()
const noexcept;
484 : m_response(std::move(response))
488 OperationResult() noexcept : m_response(
nullptr) {}
489 ~OperationResult() noexcept {};
490 Crt::ScopedResource<AbstractShapeBase> m_response;
491 Crt::ScopedResource<OperationError> m_error;
494 OperationResult m_operationResult;
513 const Crt::
String &modelName) const noexcept = 0;
515 const Crt::
String &modelName) const noexcept = 0;
517 const Crt::
String &modelName) const noexcept = 0;
525 const Crt::
String &errorModelName,
527 Crt::
Allocator *allocator) const noexcept = 0;
548 Crt::
Allocator *allocator) const noexcept = 0;
558 Crt::
Allocator *allocator) const noexcept = 0;
564 virtual Crt::
String GetInitialResponseModelName() const noexcept = 0;
570 virtual Crt::
String GetRequestModelName() const noexcept = 0;
576 virtual Crt::Optional<Crt::
String> GetStreamingResponseModelName() const noexcept = 0;
584 virtual Crt::
String GetOperationName() const noexcept = 0;
594 const Crt::
String &errorModelName,
596 Crt::
Allocator *allocator) const noexcept
598 return m_serviceModel.AllocateOperationErrorFromPayload(errorModelName, stringView, allocator);
613 std::shared_ptr<StreamResponseHandler> streamHandler,
642 void WithLaunchMode(
std::launch mode) noexcept;
660 virtual Crt::
String GetModelName() const noexcept = 0;
663 std::launch m_asyncLaunchMode;
668 const Crt::
String &modelName,
669 const Crt::Optional<Crt::
ByteBuf> &payload,
670 uint32_t messageFlags);
674 void OnContinuationMessage(
676 const Crt::Optional<Crt::
ByteBuf> &payload,
678 uint32_t messageFlags) override;
686 void OnContinuationClosed() override;
690 const Crt::
String &name) noexcept;
699 uint32_t m_messageCount;
701 std::shared_ptr<StreamResponseHandler> m_streamHandler;
704 std::mutex m_continuationMutex;
705 bool m_resultReceived;
706 std::promise<TaggedResult> m_initialResponsePromise;
707 std::atomic_int m_expectedCloses;
708 std::atomic_bool m_streamClosedCalled;
709 std::condition_variable m_closeReady;
735 Crt::Io::ClientBootstrap &clientBootstrap) noexcept;
739 const Crt::Optional<Crt::
ByteBuf> &payload,
744 const Crt::Optional<Crt::
ByteBuf> &payload,
758 void Close() noexcept;
764 bool IsOpen() const noexcept
766 if (this->m_underlyingConnection ==
nullptr)
772 return aws_event_stream_rpc_client_connection_is_open(this->m_underlyingConnection);
779 operator bool() const noexcept {
return IsOpen(); }
788 WAITING_FOR_CONNECT_ACK,
793 std::recursive_mutex m_stateMutex;
795 struct aws_event_stream_rpc_client_connection *m_underlyingConnection;
796 ClientState m_clientState;
799 std::promise<void> m_connectionSetupPromise;
800 bool m_connectionWillSetup;
801 std::promise<RpcError> m_connectAckedPromise;
802 std::promise<RpcError> m_closedPromise;
803 bool m_onConnectCalled;
808 std::future<RpcError> SendProtocolMessage(
812 uint32_t messageFlags,
815 static void s_onConnectionShutdown(
816 struct aws_event_stream_rpc_client_connection *connection,
818 void *userData) noexcept;
819 static void s_onConnectionSetup(
820 struct aws_event_stream_rpc_client_connection *connection,
822 void *userData) noexcept;
823 static void s_onProtocolMessage(
824 struct aws_event_stream_rpc_client_connection *connection,
825 const struct aws_event_stream_rpc_message_args *messageArgs,
826 void *userData) noexcept;
828 static void s_protocolMessageCallback(
int errorCode,
void *userData) noexcept;
833 static std::future<RpcError> s_sendProtocolMessage(
838 uint32_t messageFlags,
841 static std::future<RpcError> s_sendPing(
847 static std::future<RpcError> s_sendPingResponse(
Definition: EventStreamClient.h:298
@ EVENT_STREAM_RPC_CONTINUATION_CLOSED
Definition: EventStreamClient.h:193
Crt::Io::ClientBootstrap * GetClientBootstrap() const noexcept
Definition: EventStreamClient.h:143
Crt::Optional< Crt::Io::SocketOptions > m_socketOptions
Definition: EventStreamClient.h:176
Definition: EventStreamClient.h:201
virtual void OnContinuationMessage(const Crt::List< EventStreamHeader > &headers, const Crt::Optional< Crt::ByteBuf > &payload, MessageType messageType, uint32_t messageFlags)=0
ResultType GetResultType() const noexcept
Definition: EventStreamClient.h:478
void SetSocketOptions(const Crt::Io::SocketOptions &socketOptions) noexcept
Definition: EventStreamClient.h:152
@ EVENT_STREAM_RPC_CRT_ERROR
Definition: EventStreamClient.h:197
Definition: EventStreamClient.h:212
Definition: EventStreamClient.h:393
@ RPC_ERROR
Definition: EventStreamClient.h:434
@ EVENT_STREAM_RPC_ALLOCATION_ERROR
Definition: EventStreamClient.h:188
std::function< ExpectedResponseFactory(const Crt::String &modelName)> LoneResponseRetriever
Definition: EventStreamClient.h:503
std::unique_ptr< T, std::function< void(T *)> > ScopedResource
Definition: Types.h:163
std::future< RpcError > Close(OnMessageFlushCallback onMessageFlushCallback=nullptr) noexcept
Definition: EventStreamClient.cpp:1521
ClientConnection & operator=(const ClientConnection &) noexcept=delete
Crt::Allocator * allocator
Definition: EventStreamClient.h:262
@ EVENT_STREAM_RPC_CONNECTION_CLOSED
Definition: EventStreamClient.h:192
ClientConnection(const ClientConnection &) noexcept=delete
EventStreamRpcStatusCode
Definition: EventStreamClient.h:184
int crtError
Definition: EventStreamClient.h:203
Crt::Io::ClientBootstrap * m_clientBootstrap
Definition: EventStreamClient.h:178
MessageAmendment m_connectAmendment
Definition: EventStreamClient.h:179
OnMessageFlushCallback GetConnectRequestCallback() const noexcept
Definition: EventStreamClient.h:144
bool operator=(const ClientOperation &clientOperation) noexcept=delete
Crt::Optional< uint32_t > m_port
Definition: EventStreamClient.h:175
aws_event_stream_header_value_type HeaderValueType
Definition: EventStreamClient.h:45
Crt::Optional< Crt::Io::TlsConnectionOptions > m_tlsConnectionOptions
Definition: EventStreamClient.h:177
void SetConnectAmendment(const MessageAmendment &connectAmendment) noexcept
Definition: EventStreamClient.h:156
std::list< T, StlAllocator< T > > List
Definition: Types.h:54
std::function< ExpectedResponseFactory(const Crt::String &modelName)> StreamingResponseRetriever
Definition: EventStreamClient.h:504
Definition: TlsOptions.h:293
@ OPERATION_ERROR
Definition: EventStreamClient.h:433
Definition: EventStreamClient.h:716
ClientOperation(ClientOperation &&clientOperation) noexcept=delete
virtual ~ServiceModel() noexcept=default
OnMessageFlushCallback m_connectRequestCallback
Definition: EventStreamClient.h:180
@ EVENT_STREAM_RPC_UNMAPPED_DATA
Definition: EventStreamClient.h:195
@ EVENT_STREAM_RPC_CONNECTION_ALREADY_ESTABLISHED
Definition: EventStreamClient.h:191
bool operator=(ClientOperation &&clientOperation) noexcept=delete
Definition: EventStreamClient.h:441
Definition: EventStreamClient.h:269
Definition: EventStreamClient.h:132
Definition: EventStreamClient.h:407
@ EVENT_STREAM_RPC_CONNECTION_SETUP_FAILED
Definition: EventStreamClient.h:189
virtual ~ClientContinuationHandler() noexcept=default
EventStreamRpcStatusCode baseStatus
Definition: EventStreamClient.h:202
std::mutex callbackMutex
Definition: EventStreamClient.h:260
ClientOperation(const ClientOperation &clientOperation) noexcept=delete
ConnectMessageAmender GetConnectMessageAmender() const noexcept
Definition: EventStreamClient.h:145
virtual ~OperationModelContext() noexcept=default
virtual ~AbstractShapeBase() noexcept=default
Definition: EventStreamClient.h:508
Crt::Optional< Crt::Io::TlsConnectionOptions > GetTlsConnectionOptions() const noexcept
Definition: EventStreamClient.h:139
std::function< const MessageAmendment &(void)> ConnectMessageAmender
Definition: EventStreamClient.h:59
ConnectionConfig() noexcept
Definition: EventStreamClient.h:134
void SetPort(uint32_t port) noexcept
Definition: EventStreamClient.h:151
std::function< Crt::ScopedResource< OperationError >(const Crt::StringView &payload, Crt::Allocator *allocator)> ErrorResponseFactory
Definition: EventStreamClient.h:501
AWS_CRT_CPP_API Allocator * g_allocator
Definition: Allocator.cpp:22
Definition: EventStreamClient.h:609
std::function< Crt::ScopedResource< AbstractShapeBase >(const Crt::StringView &payload, Crt::Allocator *allocator)> ExpectedResponseFactory
Definition: EventStreamClient.h:499
std::function< ErrorResponseFactory(const Crt::String &modelName)> ErrorResponseRetriever
Definition: EventStreamClient.h:505
Crt::Optional< Crt::String > m_hostName
Definition: EventStreamClient.h:174
@ OPERATION_RESPONSE
Definition: EventStreamClient.h:432
Crt::Optional< MessageAmendment > GetConnectAmendment() const noexcept
Definition: EventStreamClient.h:138
ResultType
Definition: EventStreamClient.h:431
@ EVENT_STREAM_RPC_SUCCESS
Definition: EventStreamClient.h:185
Definition: EventStreamClient.h:521
void SetConnectRequestCallback(OnMessageFlushCallback connectRequestCallback) noexcept
Definition: EventStreamClient.h:168
ClientContinuation * clientContinuation
Definition: EventStreamClient.h:261
@ EVENT_STREAM_RPC_UNINITIALIZED
Definition: EventStreamClient.h:187
OperationError() noexcept=default
@ EVENT_STREAM_RPC_UNKNOWN_PROTOCOL_MESSAGE
Definition: EventStreamClient.h:194
bool continuationDestroyed
Definition: EventStreamClient.h:259
std::function< void(int errorCode)> OnMessageFlushCallback
Definition: EventStreamClient.h:52
string_view StringView
Definition: StringView.h:846
Definition: SocketOptions.h:48
void SetTlsConnectionOptions(Crt::Io::TlsConnectionOptions tlsConnectionOptions) noexcept
Definition: EventStreamClient.h:160
Definition: StringView.h:33
aws_byte_buf ByteBuf
Definition: Types.h:30
Definition: StringView.h:852
@ EVENT_STREAM_RPC_NULL_PARAMETER
Definition: EventStreamClient.h:186
Definition: Allocator.h:11
virtual ~ConnectionLifecycleHandler() noexcept=default
virtual ~StreamResponseHandler() noexcept=default
aws_allocator Allocator
Definition: Allocator.h:14
ContinuationCallbackData(ClientContinuation *clientContinuation, Crt::Allocator *allocator=Crt::g_allocator) noexcept
Definition: EventStreamClient.h:251
@ EVENT_STREAM_RPC_CONNECTION_ACCESS_DENIED
Definition: EventStreamClient.h:190
void SetClientBootstrap(Crt::Io::ClientBootstrap *clientBootstrap) noexcept
Definition: EventStreamClient.h:164
#define AWS_EVENTSTREAMRPC_API
Definition: Exports.h:19
virtual ~ResponseRetriever() noexcept=default
Definition: Bootstrap.h:35
Definition: EventStreamClient.h:534
Definition: EventStreamClient.h:377
Crt::Optional< Crt::Io::SocketOptions > GetSocketOptions() const noexcept
Definition: EventStreamClient.h:137
ContinuationCallbackData(const ContinuationCallbackData &lhs) noexcept=delete
@ EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE
Definition: EventStreamClient.h:196
Definition: EventStreamClient.h:99
aws_event_stream_rpc_message_type MessageType
Definition: EventStreamClient.h:46
void SetHostName(Crt::String hostName) noexcept
Definition: EventStreamClient.h:150
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:45
Crt::Optional< Crt::String > GetHostName() const noexcept
Definition: EventStreamClient.h:135
Crt::Optional< uint32_t > GetPort() const noexcept
Definition: EventStreamClient.h:136
Definition: EventStreamClient.h:249
virtual void OnContinuationClosed()=0