| Flutter Linux Embedder |

fl_binary_messenger.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_BINARY_MESSENGER_H_
6 #define FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_BINARY_MESSENGER_H_
7
8 #if !defined(__FLUTTER_LINUX_INSIDE__) && !defined(FLUTTER_LINUX_COMPILATION)
9 #error "Only <flutter_linux/flutter_linux.h> can be included directly."
10 #endif
11
12 #include "fl_value.h"
13
14 #include <gio/gio.h>
15 #include <glib-object.h>
16 #include <gmodule.h>
17
18 G_BEGIN_DECLS
19
20 /**
21 * FlBinaryMessengerError:
22 * @FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED: unable to send response, this
23 * message has already been responded to.
24 *
25 * Errors for #FlBinaryMessenger objects to set on failures.
26 */
27 #define FL_BINARY_MESSENGER_ERROR fl_binary_messenger_codec_error_quark()
28
29 typedef enum {
30 // Part of the public API, so fixing the name is a breaking change.
31 // NOLINTNEXTLINE(readability-identifier-naming)
32 FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED,
33 } FlBinaryMessengerError;
34
35 GQuark fl_binary_messenger_codec_error_quark(void) G_GNUC_CONST;
36
37 G_MODULE_EXPORT
38 G_DECLARE_INTERFACE(FlBinaryMessenger,
39 fl_binary_messenger,
40 FL,
41 BINARY_MESSENGER,
42 GObject)
43
44 G_MODULE_EXPORT
45 G_DECLARE_DERIVABLE_TYPE(FlBinaryMessengerResponseHandle,
46 fl_binary_messenger_response_handle,
47 FL,
48 BINARY_MESSENGER_RESPONSE_HANDLE,
49 GObject)
50
51 /**
52 * FlBinaryMessengerMessageHandler:
53 * @messenger: an #FlBinaryMessenger.
54 * @channel: channel message received on.
55 * @message: message content received from Dart.
56 * @response_handle: a handle to respond to the message with.
57 * @user_data: (closure): data provided when registering this handler.
58 *
59 * Function called when platform messages are received. Call
60 * fl_binary_messenger_send_response() to respond to this message. If the
61 * response is not occurring in this callback take a reference to
62 * @response_handle and release that once it has been responded to. Failing to
63 * respond before the last reference to @response_handle is dropped is a
64 * programming error.
65 */
66 typedef void (*FlBinaryMessengerMessageHandler)(
67 FlBinaryMessenger* messenger,
68 const gchar* channel,
69 GBytes* message,
70 FlBinaryMessengerResponseHandle* response_handle,
71 gpointer user_data);
72
73 struct _FlBinaryMessengerInterface {
74 GTypeInterface parent_iface;
75
76 void (*set_message_handler_on_channel)(
77 FlBinaryMessenger* messenger,
78 const gchar* channel,
79 FlBinaryMessengerMessageHandler handler,
80 gpointer user_data,
81 GDestroyNotify destroy_notify);
82
83 gboolean (*send_response)(FlBinaryMessenger* messenger,
84 FlBinaryMessengerResponseHandle* response_handle,
85 GBytes* response,
86 GError** error);
87
88 void (*send_on_channel)(FlBinaryMessenger* messenger,
89 const gchar* channel,
90 GBytes* message,
91 GCancellable* cancellable,
92 GAsyncReadyCallback callback,
93 gpointer user_data);
94
95 GBytes* (*send_on_channel_finish)(FlBinaryMessenger* messenger,
96 GAsyncResult* result,
97 GError** error);
98
99 void (*resize_channel)(FlBinaryMessenger* messenger,
100 const gchar* channel,
101 int64_t new_size);
102
103 void (*set_warns_on_channel_overflow)(FlBinaryMessenger* messenger,
104 const gchar* channel,
105 bool warns);
106 };
107
108 struct _FlBinaryMessengerResponseHandleClass {
109 GObjectClass parent_class;
110 };
111
112 /**
113 * FlBinaryMessenger:
114 *
115 * #FlBinaryMessenger is an object that allows sending and receiving of platform
116 * messages with an #FlEngine.
117 */
118
119 /**
120 * FlBinaryMessengerResponseHandle:
121 *
122 * #FlBinaryMessengerResponseHandle is an object used to send responses with.
123 */
124
125 /**
126 * fl_binary_messenger_set_platform_message_handler:
127 * @binary_messenger: an #FlBinaryMessenger.
128 * @channel: channel to listen on.
129 * @handler: (allow-none): function to call when a message is received on this
130 * channel or %NULL to disable a handler
131 * @user_data: (closure): user data to pass to @handler.
132 * @destroy_notify: (allow-none): a function which gets called to free
133 * @user_data, or %NULL.
134 *
135 * Sets the function called when a platform message is received on the given
136 * channel. See #FlBinaryMessengerMessageHandler for details on how to respond
137 * to messages.
138 *
139 * The handler is removed if the channel is closed or is replaced by another
140 * handler, set @destroy_notify if you want to detect this.
141 */
142 void fl_binary_messenger_set_message_handler_on_channel(
143 FlBinaryMessenger* messenger,
144 const gchar* channel,
145 FlBinaryMessengerMessageHandler handler,
146 gpointer user_data,
147 GDestroyNotify destroy_notify);
148
149 /**
150 * fl_binary_messenger_send_response:
151 * @binary_messenger: an #FlBinaryMessenger.
152 * @response_handle: handle that was provided in a
153 * #FlBinaryMessengerMessageHandler.
154 * @response: (allow-none): response to send or %NULL for an empty response.
155 * @error: (allow-none): #GError location to store the error occurring, or %NULL
156 * to ignore.
157 *
158 * Responds to a platform message. This function is thread-safe.
159 *
160 * Returns: %TRUE on success.
161 */
162 gboolean fl_binary_messenger_send_response(
163 FlBinaryMessenger* messenger,
164 FlBinaryMessengerResponseHandle* response_handle,
165 GBytes* response,
166 GError** error);
167
168 /**
169 * fl_binary_messenger_send_on_channel:
170 * @binary_messenger: an #FlBinaryMessenger.
171 * @channel: channel to send to.
172 * @message: (allow-none): message buffer to send or %NULL for an empty message.
173 * @cancellable: (allow-none): a #GCancellable or %NULL.
174 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is
175 * satisfied.
176 * @user_data: (closure): user data to pass to @callback.
177 *
178 * Asynchronously sends a platform message.
179 */
180 void fl_binary_messenger_send_on_channel(FlBinaryMessenger* messenger,
181 const gchar* channel,
182 GBytes* message,
183 GCancellable* cancellable,
184 GAsyncReadyCallback callback,
185 gpointer user_data);
186
187 /**
188 * fl_binary_messenger_send_on_channel_finish:
189 * @messenger: an #FlBinaryMessenger.
190 * @result: a #GAsyncResult.
191 * @error: (allow-none): #GError location to store the error occurring, or %NULL
192 * to ignore.
193 *
194 * Completes request started with fl_binary_messenger_send_on_channel().
195 *
196 * Returns: (transfer full): message response on success or %NULL on error.
197 */
198 GBytes* fl_binary_messenger_send_on_channel_finish(FlBinaryMessenger* messenger,
199 GAsyncResult* result,
200 GError** error);
201
202 /**
203 * fl_binary_messenger_resize_channel:
204 * @binary_messenger: an #FlBinaryMessenger.
205 * @channel: channel to be resize.
206 * @new_size: the new size for the channel buffer.
207 *
208 * Sends a message to the control channel asking to resize a channel buffer.
209 */
210 void fl_binary_messenger_resize_channel(FlBinaryMessenger* messenger,
211 const gchar* channel,
212 int64_t new_size);
213
214 /**
215 * fl_binary_messenger_set_warns_on_channel_overflow:
216 * @messenger: an #FlBinaryMessenger.
217 * @channel: channel to be allowed to overflow silently.
218 * @warns: when false, the channel is expected to overflow and warning messages
219 * will not be shown.
220 *
221 * Sends a message to the control channel asking to allow or disallow a channel
222 * to overflow silently.
223 */
224 void fl_binary_messenger_set_warns_on_channel_overflow(
225 FlBinaryMessenger* messenger,
226 const gchar* channel,
227 bool warns);
228
229 G_END_DECLS
230
231 #endif // FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_BINARY_MESSENGER_H_
G_DECLARE_DERIVABLE_TYPE
G_DECLARE_DERIVABLE_TYPE(FlAccessibleNode, fl_accessible_node, FL, ACCESSIBLE_NODE, AtkObject)
_FlBinaryMessengerInterface
Definition: fl_binary_messenger.h:73
send_response
static gboolean send_response(FlBinaryMessenger *messenger, FlBinaryMessengerResponseHandle *response_handle_, GBytes *response, GError **error)
Definition: fl_binary_messenger.cc:241
_FlBinaryMessengerInterface::parent_iface
GTypeInterface parent_iface
Definition: fl_binary_messenger.h:74
fl_binary_messenger_send_on_channel_finish
GBytes * fl_binary_messenger_send_on_channel_finish(FlBinaryMessenger *messenger, GAsyncResult *result, GError **error)
Definition: fl_binary_messenger.cc:465
fl_binary_messenger_set_warns_on_channel_overflow
void fl_binary_messenger_set_warns_on_channel_overflow(FlBinaryMessenger *messenger, const gchar *channel, bool warns)
Definition: fl_binary_messenger.cc:484
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
_FlBinaryMessengerResponseHandleClass::parent_class
GObjectClass parent_class
Definition: fl_binary_messenger.h:109
fl_binary_messenger_send_response
gboolean fl_binary_messenger_send_response(FlBinaryMessenger *messenger, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
Definition: fl_binary_messenger.cc:438
send_on_channel
static void send_on_channel(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_binary_messenger.cc:286
fl_binary_messenger_send_on_channel
void fl_binary_messenger_send_on_channel(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_binary_messenger.cc:451
_FlBinaryMessengerResponseHandleClass
Definition: fl_binary_messenger.h:108
resize_channel
static void resize_channel(FlBinaryMessenger *messenger, const gchar *channel, int64_t new_size)
Definition: fl_binary_messenger.cc:347
fl_binary_messenger_set_message_handler_on_channel
void fl_binary_messenger_set_message_handler_on_channel(FlBinaryMessenger *messenger, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_binary_messenger.cc:424
FlBinaryMessengerMessageHandler
G_MODULE_EXPORT GObject typedef void(* FlBinaryMessengerMessageHandler)(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
Definition: fl_binary_messenger.h:66
FlBinaryMessengerError
FlBinaryMessengerError
Definition: fl_binary_messenger.h:29
result
GAsyncResult * result
Definition: fl_text_input_plugin.cc:106
FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED
@ FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED
Definition: fl_binary_messenger.h:32
FL
G_MODULE_EXPORT FL
Definition: fl_binary_messenger.h:47
fl_value.h
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_binary_messenger_response_handle
G_MODULE_EXPORT fl_binary_messenger_response_handle
Definition: fl_binary_messenger.h:46
BINARY_MESSENGER_RESPONSE_HANDLE
G_MODULE_EXPORT BINARY_MESSENGER_RESPONSE_HANDLE
Definition: fl_binary_messenger.h:48
callback
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Definition: fl_key_channel_responder.cc:120
set_message_handler_on_channel
static void set_message_handler_on_channel(FlBinaryMessenger *messenger, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_binary_messenger.cc:204
fl_binary_messenger_codec_error_quark
GQuark fl_binary_messenger_codec_error_quark(void) G_GNUC_CONST
set_warns_on_channel_overflow
static void set_warns_on_channel_overflow(FlBinaryMessenger *messenger, const gchar *channel, bool warns)
Definition: fl_binary_messenger.cc:372
G_DECLARE_INTERFACE
G_MODULE_EXPORT G_DECLARE_INTERFACE(FlBinaryMessenger, fl_binary_messenger, FL, BINARY_MESSENGER, GObject) G_MODULE_EXPORT G_DECLARE_DERIVABLE_TYPE(FlBinaryMessengerResponseHandle
fl_binary_messenger_resize_channel
void fl_binary_messenger_resize_channel(FlBinaryMessenger *messenger, const gchar *channel, int64_t new_size)
Definition: fl_binary_messenger.cc:475