Debian Codegraph @

crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_client.h

raw symbols SCIP
1 #ifndef AWS_EVENT_STREAM_RPC_CLIENT_H
2 #define AWS_EVENT_STREAM_RPC_CLIENT_H
3 /**
4 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: Apache-2.0.
6 */
7
8 #include <aws/event-stream/event_stream_rpc.h>
9
10 AWS_PUSH_SANE_WARNING_LEVEL
11
12 struct aws_channel;
13 struct aws_event_loop;
14 struct aws_event_stream_rpc_client_connection;
15 struct aws_event_stream_rpc_client_continuation_token;
16
17 /**
18 * Invoked when a connection receives a message on an existing stream. message_args contains the
19 * message data.
20 */
21 typedef void(aws_event_stream_rpc_client_stream_continuation_fn)(
22 struct aws_event_stream_rpc_client_continuation_token *token,
23 const struct aws_event_stream_rpc_message_args *message_args,
24 void *user_data);
25
26 /**
27 * Invoked when a continuation has either been closed with the TERMINATE_STREAM flag, or when the connection
28 * shuts down and deletes the continuation.
29 */
30 typedef void(aws_event_stream_rpc_client_stream_continuation_closed_fn)(
31 struct aws_event_stream_rpc_client_continuation_token *token,
32 void *user_data);
33
34 /**
35 * Invoked after a continuation has been fully destroyed. Listeners know that no further callbacks are possible.
36 */
37 typedef void(aws_event_stream_rpc_client_stream_continuation_terminated_fn)(void *user_data);
38
39 struct aws_event_stream_rpc_client_stream_continuation_options {
40 aws_event_stream_rpc_client_stream_continuation_fn *on_continuation;
41 aws_event_stream_rpc_client_stream_continuation_closed_fn *on_continuation_closed;
42 aws_event_stream_rpc_client_stream_continuation_terminated_fn *on_continuation_terminated;
43 void *user_data;
44 };
45
46 /**
47 * Invoked when a non-stream level message is received on a connection.
48 */
49 typedef void(aws_event_stream_rpc_client_connection_protocol_message_fn)(
50 struct aws_event_stream_rpc_client_connection *connection,
51 const struct aws_event_stream_rpc_message_args *message_args,
52 void *user_data);
53
54 /**
55 * Invoked when a successfully created connection is shutdown. error_code will indicate the reason for the shutdown.
56 */
57 typedef void(aws_event_stream_rpc_client_on_connection_shutdown_fn)(
58 struct aws_event_stream_rpc_client_connection *connection,
59 int error_code,
60 void *user_data);
61
62 /**
63 * Invoked when a connection attempt completes.
64 *
65 * If the attempt was unsuccessful, the error_code will be non-zero and the connection pointer will be NULL,
66 * and aws_event_stream_rpc_client_on_connection_shutdown_fn will not be invoked.
67 *
68 * If the attempt was successful, error_code will be 0 and the connection pointer will be valid.
69 * You must call aws_event_stream_rpc_client_connection_acquire()
70 * to prevent the pointer's memory from being destroyed before you are ready.
71 * When you are completely done with the connection pointer you must call
72 * aws_event_stream_rpc_client_connection_release() or its memory will leak.
73 * aws_event_stream_rpc_client_on_connection_shutdown_fn will be invoked
74 * when the network connection has closed. If you are done with the connection,
75 * but it is still open, you must call aws_aws_event_stream_rpc_client_close()
76 * or network connection will remain open, even if you call release().
77 */
78 typedef void(aws_event_stream_rpc_client_on_connection_setup_fn)(
79 struct aws_event_stream_rpc_client_connection *connection,
80 int error_code,
81 void *user_data);
82
83 /**
84 * Invoked when a connection has been completely destroyed.
85 */
86 typedef void(aws_event_stream_rpc_client_on_connection_terminated_fn)(void *user_data);
87
88 /**
89 * Invoked whenever a message has been flushed to the channel.
90 */
91 typedef void(aws_event_stream_rpc_client_message_flush_fn)(int error_code, void *user_data);
92
93 struct aws_client_bootstrap;
94
95 struct aws_event_stream_rpc_client_connection_options {
96 /** host name to use for the connection. This depends on your socket type. */
97 const char *host_name;
98 /** port to use for your connection, assuming for the appropriate socket type. */
99 uint32_t port;
100 /** socket options for establishing the connection to the RPC server. */
101 const struct aws_socket_options *socket_options;
102 /** optional: tls options for using when establishing your connection. */
103 const struct aws_tls_connection_options *tls_options;
104 struct aws_client_bootstrap *bootstrap;
105 aws_event_stream_rpc_client_on_connection_setup_fn *on_connection_setup;
106 aws_event_stream_rpc_client_connection_protocol_message_fn *on_connection_protocol_message;
107 aws_event_stream_rpc_client_on_connection_shutdown_fn *on_connection_shutdown;
108 aws_event_stream_rpc_client_on_connection_terminated_fn *on_connection_terminated;
109 void *user_data;
110 };
111
112 AWS_EXTERN_C_BEGIN
113
114 /**
115 * Initiate a new connection. If this function returns AWS_OP_SUCESSS, the
116 * aws_event_stream_rpc_client_connection_options::on_connection_setup is guaranteed to be called exactly once. If that
117 * callback successfully creates a connection, aws_event_stream_rpc_client_connection_options::on_connection_shutdown
118 * will be invoked upon connection closure. However if the connection was never successfully setup,
119 * aws_event_stream_rpc_client_connection_options::on_connection_shutdown will not be invoked later.
120 */
121 AWS_EVENT_STREAM_API int aws_event_stream_rpc_client_connection_connect(
122 struct aws_allocator *allocator,
123 const struct aws_event_stream_rpc_client_connection_options *conn_options);
124 AWS_EVENT_STREAM_API void aws_event_stream_rpc_client_connection_acquire(
125 const struct aws_event_stream_rpc_client_connection *connection);
126 AWS_EVENT_STREAM_API void aws_event_stream_rpc_client_connection_release(
127 const struct aws_event_stream_rpc_client_connection *connection);
128
129 /**
130 * Closes the connection if it is open and aws_event_stream_rpc_client_connection_options::on_connection_shutdown will
131 * be invoked upon shutdown. shutdown_error_code will indicate the reason for shutdown. For a graceful shutdown pass 0
132 * or AWS_ERROR_SUCCESS.
133 */
134 AWS_EVENT_STREAM_API void aws_event_stream_rpc_client_connection_close(
135 struct aws_event_stream_rpc_client_connection *connection,
136 int shutdown_error_code);
137
138 /**
139 * Returns true if the connection is open, false otherwise.
140 */
141 AWS_EVENT_STREAM_API bool aws_event_stream_rpc_client_connection_is_open(
142 const struct aws_event_stream_rpc_client_connection *connection);
143
144 /**
145 * Sends a message on the connection. These must be connection level messages (not application messages).
146 *
147 * flush_fn will be invoked when the message has been successfully writen to the wire or when it fails.
148 *
149 * returns AWS_OP_SUCCESS if the message was successfully created and queued, and in that case flush_fn will always be
150 * invoked. Otherwise, flush_fn will not be invoked.
151 */
152 AWS_EVENT_STREAM_API int aws_event_stream_rpc_client_connection_send_protocol_message(
153 struct aws_event_stream_rpc_client_connection *connection,
154 const struct aws_event_stream_rpc_message_args *message_args,
155 aws_event_stream_rpc_client_message_flush_fn *flush_fn,
156 void *user_data);
157
158 /**
159 * Returns the event loop that a connection is seated on.
160 */
161 AWS_EVENT_STREAM_API struct aws_event_loop *aws_event_stream_rpc_client_connection_get_event_loop(
162 const struct aws_event_stream_rpc_client_connection *connection);
163
164 /**
165 * Create a new stream. continuation_option's callbacks will not be invoked, and nothing will be sent across the wire
166 * until aws_event_stream_rpc_client_continuation_activate() is invoked.
167 *
168 * returns an instance of a aws_event_stream_rpc_client_continuation_token on success with a reference count of 1. You
169 * must call aws_event_stream_rpc_client_continuation_release() when you're finished with it. Returns NULL on failure.
170 */
171 AWS_EVENT_STREAM_API struct aws_event_stream_rpc_client_continuation_token *
172 aws_event_stream_rpc_client_connection_new_stream(
173 struct aws_event_stream_rpc_client_connection *connection,
174 const struct aws_event_stream_rpc_client_stream_continuation_options *continuation_options);
175 AWS_EVENT_STREAM_API void aws_event_stream_rpc_client_continuation_acquire(
176 const struct aws_event_stream_rpc_client_continuation_token *continuation);
177 AWS_EVENT_STREAM_API void aws_event_stream_rpc_client_continuation_release(
178 const struct aws_event_stream_rpc_client_continuation_token *continuation);
179
180 /**
181 * returns true if the continuation has been closed.
182 */
183 AWS_EVENT_STREAM_API bool aws_event_stream_rpc_client_continuation_is_closed(
184 const struct aws_event_stream_rpc_client_continuation_token *continuation);
185
186 /**
187 * Actually sends the initial stream to the peer. Callbacks from aws_event_stream_rpc_client_connection_new_stream()
188 * will actually be invoked if this function returns AWS_OP_SUCCESS, otherwise, the stream has not been queued and no
189 * callbacks will be invoked.
190 *
191 * operation_name is the name to identify which logical rpc call you want to kick off with the peer. It must be
192 * non-empty. flush_fn will be invoked once the message has either been written to the wire or it fails.
193 */
194 AWS_EVENT_STREAM_API int aws_event_stream_rpc_client_continuation_activate(
195 struct aws_event_stream_rpc_client_continuation_token *continuation,
196 struct aws_byte_cursor operation_name,
197 const struct aws_event_stream_rpc_message_args *message_args,
198 aws_event_stream_rpc_client_message_flush_fn *flush_fn,
199 void *user_data);
200
201 AWS_EVENT_STREAM_API void *aws_event_stream_rpc_client_continuation_get_user_data(
202 struct aws_event_stream_rpc_client_continuation_token *continuation);
203
204 /**
205 * Sends a message on the continuation. aws_event_stream_rpc_client_continuation_activate() must be successfully invoked
206 * prior to calling this function.
207 *
208 * If this function returns AWS_OP_SUCCESS, flush_fn will be invoked once the message has either been written to the
209 * wire or it fails.
210 */
211 AWS_EVENT_STREAM_API int aws_event_stream_rpc_client_continuation_send_message(
212 struct aws_event_stream_rpc_client_continuation_token *continuation,
213 const struct aws_event_stream_rpc_message_args *message_args,
214 aws_event_stream_rpc_client_message_flush_fn *flush_fn,
215 void *user_data);
216
217 AWS_EXTERN_C_END
218 AWS_POP_SANE_WARNING_LEVEL
219
220 #endif /* AWS_EVENT_STREAM_RPC_CLIENT_H */