Skip to content

Commit 1d30dc0

Browse files
committed
Refactor Connect parameters into Config class
1 parent a04fcb2 commit 1d30dc0

File tree

7 files changed

+83
-11044
lines changed

7 files changed

+83
-11044
lines changed

eventstreamrpc/include/aws/eventstreamrpc/EventStreamClient.h

Lines changed: 31 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace Aws
3737
namespace Eventstreamrpc
3838
{
3939
class EventStreamHeader;
40-
class EventStreamRpcClient;
4140
class MessageAmendment;
4241
class ClientConnection;
4342
class ClientContinuation;
@@ -46,19 +45,28 @@ namespace Aws
4645
using HeaderValueType = aws_event_stream_header_value_type;
4746
using MessageType = aws_event_stream_rpc_message_type;
4847

48+
/**
49+
* A callback prototype that is called upon flushing a message over the wire.
50+
* @param errorCode A non-zero value if an error occured while attempting to flush the message.
51+
*/
4952
using OnMessageFlushCallback = std::function<void(int errorCode)>;
5053

5154
/**
52-
* Allows the application to append headers and change the payload of the CONNECT
53-
* packet being sent out.
55+
* Allows the application to add headers and change the payload of the CONNECT
56+
* packet sent out by the client.
57+
* @return The `MessageAmendment` for the client to use during an attempt to connect.
5458
*/
5559
using ConnectMessageAmender = std::function<MessageAmendment &(void)>;
5660

61+
/**
62+
* A wrapper around an `aws_event_stream_header_value_pair` object.
63+
*/
5764
class AWS_EVENTSTREAMRPC_API EventStreamHeader final
5865
{
5966
public:
6067
EventStreamHeader(const EventStreamHeader &lhs) noexcept;
6168
EventStreamHeader(EventStreamHeader &&rhs) noexcept;
69+
EventStreamHeader &operator=(const EventStreamHeader &lhs) noexcept;
6270
~EventStreamHeader() noexcept;
6371
EventStreamHeader(
6472
const struct aws_event_stream_header_value_pair &header,
@@ -100,13 +108,19 @@ namespace Aws
100108
struct aws_event_stream_header_value_pair m_underlyingHandle;
101109
};
102110

111+
/**
112+
* A means to append headers or modify the payload of a message to be sent by the client.
113+
* @note The exception specifiers for move, copy constructors & assignment operators are required since
114+
* this class is usually wrapped with `Crt::Optional`.
115+
*/
103116
class AWS_EVENTSTREAMRPC_API MessageAmendment final
104117
{
105118
public:
106119
MessageAmendment(const MessageAmendment &lhs) = default;
107120
MessageAmendment(MessageAmendment &&rhs) = default;
121+
MessageAmendment &operator=(const MessageAmendment &rhs) = default;
108122
~MessageAmendment() noexcept;
109-
explicit MessageAmendment(Crt::Allocator *allocator = Crt::g_allocator);
123+
explicit MessageAmendment(Crt::Allocator *allocator = Crt::g_allocator) noexcept;
110124
MessageAmendment(
111125
const Crt::List<EventStreamHeader> &headers,
112126
Crt::Optional<Crt::ByteBuf> &payload,
@@ -129,57 +143,11 @@ namespace Aws
129143
Crt::Allocator *m_allocator;
130144
};
131145

132-
class AWS_CRT_CPP_API UnixSocketResolver final : public Crt::Io::HostResolver
133-
{
134-
public:
135-
/**
136-
* Resolves UNIX sockets.
137-
*/
138-
UnixSocketResolver(
139-
Crt::Io::EventLoopGroup &elGroup,
140-
size_t maxHosts,
141-
Crt::Allocator *allocator = Crt::g_allocator) noexcept;
142-
~UnixSocketResolver();
143-
UnixSocketResolver(const UnixSocketResolver &) = delete;
144-
UnixSocketResolver &operator=(const UnixSocketResolver &) = delete;
145-
UnixSocketResolver(UnixSocketResolver &&) = delete;
146-
UnixSocketResolver &operator=(UnixSocketResolver &&) = delete;
147-
148-
bool ResolveHost(const Crt::String &host, const Crt::Io::OnHostResolved &onResolved) noexcept override;
149-
150-
/**
151-
* @return true if the instance is in a valid state, false otherwise.
152-
*/
153-
operator bool() const noexcept { return m_initialized; }
154-
/**
155-
* @return the value of the last aws error encountered by operations on this instance.
156-
*/
157-
int LastError() const noexcept { return aws_last_error(); }
158-
159-
/// @private
160-
aws_host_resolver *GetUnderlyingHandle() noexcept override { return m_resolver; }
161-
/// @private
162-
aws_host_resolution_config *GetConfig() noexcept override { return NULL; }
163-
164-
private:
165-
aws_host_resolver *m_resolver;
166-
Crt::Allocator *m_allocator;
167-
bool m_initialized;
168-
169-
static void s_onHostResolved(
170-
struct aws_host_resolver *resolver,
171-
const struct aws_string *host_name,
172-
int err_code,
173-
const struct aws_array_list *host_addresses,
174-
void *user_data);
175-
};
176-
177146
/**
178147
* Configuration structure holding all options relating to eventstream RPC connection establishment
179148
*/
180149
struct AWS_EVENTSTREAMRPC_API ClientConnectionOptions final
181150
{
182-
public:
183151
ClientConnectionOptions();
184152
ClientConnectionOptions(const ClientConnectionOptions &rhs) = default;
185153
ClientConnectionOptions(ClientConnectionOptions &&rhs) = default;
@@ -258,7 +226,6 @@ namespace Aws
258226
EVENT_STREAM_RPC_UNMAPPED_DATA,
259227
EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE,
260228
EVENT_STREAM_RPC_STREAM_CLOSED_PREMATURELY,
261-
EVENT_STREAM_RPC_UNEXPECTED_ERROR,
262229
EVENT_STREAM_RPC_CRT_ERROR
263230
};
264231

@@ -273,15 +240,15 @@ namespace Aws
273240
{
274241
/* A wrapper around std::promise so that it cannot be set twice without having to catch exceptions. */
275242
public:
276-
ProtectedPromise() noexcept;
277-
ProtectedPromise(const ProtectedPromise &lhs) noexcept = delete;
278-
ProtectedPromise(ProtectedPromise &&rhs) noexcept;
279-
ProtectedPromise &operator=(ProtectedPromise &&) noexcept;
280-
ProtectedPromise(std::promise<T> &&promise) noexcept;
281-
void SetValue(T &&r) noexcept;
282-
void SetValue(const T &r) noexcept;
283-
std::future<T> GetFuture() noexcept;
284-
void Reset() noexcept;
243+
ProtectedPromise();
244+
ProtectedPromise(const ProtectedPromise &lhs) = delete;
245+
ProtectedPromise(ProtectedPromise &&rhs);
246+
ProtectedPromise &operator=(ProtectedPromise &&);
247+
ProtectedPromise(std::promise<T> &&promise);
248+
void SetValue(T &&r);
249+
void SetValue(const T &r);
250+
std::future<T> GetFuture();
251+
void Reset();
285252

286253
private:
287254
bool m_fulfilled;
@@ -332,7 +299,6 @@ namespace Aws
332299
enum ClientState
333300
{
334301
DISCONNECTED = 1,
335-
CONNECTING_TO_SOCKET,
336302
WAITING_FOR_CONNECT_ACK,
337303
CONNECTED,
338304
DISCONNECTING,
@@ -428,7 +394,7 @@ namespace Aws
428394
class AWS_EVENTSTREAMRPC_API AbstractShapeBase
429395
{
430396
public:
431-
AbstractShapeBase(Crt::Allocator *allocator = Crt::g_allocator) noexcept;
397+
AbstractShapeBase() noexcept;
432398
virtual ~AbstractShapeBase() noexcept;
433399
static void s_customDeleter(AbstractShapeBase *shape) noexcept;
434400
virtual void SerializeToJsonObject(Crt::JsonObject &payloadObject) const = 0;
@@ -441,7 +407,7 @@ namespace Aws
441407
class AWS_EVENTSTREAMRPC_API OperationResponse : public AbstractShapeBase
442408
{
443409
public:
444-
OperationResponse(Crt::Allocator *allocator = Crt::g_allocator) noexcept;
410+
OperationResponse() noexcept;
445411
static void s_customDeleter(OperationResponse *shape) noexcept;
446412
/* A response does not necessarily have to be serialized so provide a default implementation. */
447413
virtual void SerializeToJsonObject(Crt::JsonObject &payloadObject) const override;
@@ -450,13 +416,13 @@ namespace Aws
450416
class AWS_EVENTSTREAMRPC_API OperationRequest : public AbstractShapeBase
451417
{
452418
public:
453-
OperationRequest(Crt::Allocator *allocator = Crt::g_allocator) noexcept;
419+
OperationRequest() noexcept;
454420
};
455421

456422
class AWS_EVENTSTREAMRPC_API OperationError : public AbstractShapeBase
457423
{
458424
public:
459-
explicit OperationError(Crt::Allocator *allocator = Crt::g_allocator) noexcept;
425+
explicit OperationError() noexcept;
460426
static void s_customDeleter(OperationError *shape) noexcept;
461427
virtual void SerializeToJsonObject(Crt::JsonObject &payloadObject) const override;
462428
virtual Crt::Optional<Crt::String> GetMessage() noexcept = 0;

0 commit comments

Comments
 (0)