Debian Codegraph @

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

raw symbols SCIP
1 #ifndef AWS_EVENT_STREAM_CHANNEL_HANDLER_H
2 #define AWS_EVENT_STREAM_CHANNEL_HANDLER_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.h>
9
10 AWS_PUSH_SANE_WARNING_LEVEL
11
12 struct aws_event_stream_channel_handler;
13 struct aws_channel_handler;
14
15 /**
16 * Invoked when an aws_event_stream_message is encountered. If the message
17 * parsed successfully, message will be non-null and error_code will be AWS_ERROR_SUCCESS.
18 * Otherwise message will be null and error_code will represent the error that was encountered.
19 * Note that any case that error_code was not AWS_OP_SUCCESS, the channel also shuts down.
20 */
21 typedef void(aws_event_stream_channel_handler_on_message_received_fn)(
22 struct aws_event_stream_message *message,
23 int error_code,
24 void *user_data);
25
26 /**
27 * Invoked when an aws_event_stream_message is flushed to the IO interface. When error_code is AWS_ERROR_SUCCESS the
28 * write happened successfuly. Regardless, message is held from the aws_event_stream_channel_handler_write_message()
29 * call and should likely be freed in this callback. If error_code is non-zero, the channel will be shutdown immediately
30 * after this callback returns.
31 */
32 typedef void(aws_event_stream_channel_handler_on_message_written_fn)(
33 struct aws_event_stream_message *message,
34 int error_code,
35 void *user_data);
36
37 struct aws_event_stream_channel_handler_options {
38 /** Callback for when messages are received. Can not be null. */
39 aws_event_stream_channel_handler_on_message_received_fn *on_message_received;
40 /** user data passed to message callback. Optional */
41 void *user_data;
42 /** initial window size to use for the channel. If automatic window management is set to true, this value is
43 * ignored. */
44 size_t initial_window_size;
45 /**
46 * if set to false (the default), windowing will be managed automatically for the user.
47 * Otherwise, after any on_message_received, the user must invoke
48 * aws_event_stream_channel_handler_increment_read_window()
49 */
50 bool manual_window_management;
51 };
52
53 AWS_EXTERN_C_BEGIN
54 /**
55 * Allocates and initializes a new channel handler for processing aws_event_stream_message() events. Handler options
56 * must not be null.
57 */
58 AWS_EVENT_STREAM_API struct aws_channel_handler *aws_event_stream_channel_handler_new(
59 struct aws_allocator *allocator,
60 const struct aws_event_stream_channel_handler_options *handler_options);
61
62 /**
63 * Writes an aws_event_stream_message() to the channel. Once the channel flushes or an error occurs, on_message_written
64 * will be invoked. message should stay valid until the callback is invoked. If an error an occurs, the channel will
65 * automatically be shutdown.
66 */
67 AWS_EVENT_STREAM_API int aws_event_stream_channel_handler_write_message(
68 struct aws_channel_handler *handler,
69 struct aws_event_stream_message *message,
70 aws_event_stream_channel_handler_on_message_written_fn *on_message_written,
71 void *user_data);
72
73 /**
74 * Updates the read window for the channel if automatic_window_managemanet was set to false.
75 */
76 AWS_EVENT_STREAM_API void aws_event_stream_channel_handler_increment_read_window(
77 struct aws_channel_handler *handler,
78 size_t window_update_size);
79
80 AWS_EVENT_STREAM_API void *aws_event_stream_channel_handler_get_user_data(struct aws_channel_handler *handler);
81
82 AWS_EXTERN_C_END
83 AWS_POP_SANE_WARNING_LEVEL
84
85 #endif /* AWS_EVENT_STREAM_CHANNEL_HANDLER_H */