| 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_FL_BINARY_MESSENGER_H_
6 #define FLUTTER_SHELL_PLATFORM_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 FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED,
31 } FlBinaryMessengerError;
32
33 GQuark fl_binary_messenger_codec_error_quark(void) G_GNUC_CONST;
34
35 G_MODULE_EXPORT
36 G_DECLARE_INTERFACE(FlBinaryMessenger,
37 fl_binary_messenger,
38 FL,
39 BINARY_MESSENGER,
40 GObject)
41
42 G_MODULE_EXPORT
43 G_DECLARE_DERIVABLE_TYPE(FlBinaryMessengerResponseHandle,
44 fl_binary_messenger_response_handle,
45 FL,
46 BINARY_MESSENGER_RESPONSE_HANDLE,
47 GObject)
48
49 /**
50 * FlBinaryMessengerMessageHandler:
51 * @messenger: an #FlBinaryMessenger.
52 * @channel: channel message received on.
53 * @message: message content received from Dart.
54 * @response_handle: a handle to respond to the message with.
55 * @user_data: (closure): data provided when registering this handler.
56 *
57 * Function called when platform messages are received. Call
58 * fl_binary_messenger_send_response() to respond to this message. If the
59 * response is not occurring in this callback take a reference to
60 * @response_handle and release that once it has been responded to. Failing to
61 * respond before the last reference to @response_handle is dropped is a
62 * programming error.
63 */
64 typedef void (*FlBinaryMessengerMessageHandler)(
65 FlBinaryMessenger* messenger,
66 const gchar* channel,
67 GBytes* message,
68 FlBinaryMessengerResponseHandle* response_handle,
69 gpointer user_data);
70
71 struct _FlBinaryMessengerInterface {
72 GTypeInterface parent_iface;
73
74 void (*set_message_handler_on_channel)(
75 FlBinaryMessenger* messenger,
76 const gchar* channel,
77 FlBinaryMessengerMessageHandler handler,
78 gpointer user_data,
79 GDestroyNotify destroy_notify);
80
81 gboolean (*send_response)(FlBinaryMessenger* messenger,
82 FlBinaryMessengerResponseHandle* response_handle,
83 GBytes* response,
84 GError** error);
85
86 void (*send_on_channel)(FlBinaryMessenger* messenger,
87 const gchar* channel,
88 GBytes* message,
89 GCancellable* cancellable,
90 GAsyncReadyCallback callback,
91 gpointer user_data);
92
93 GBytes* (*send_on_channel_finish)(FlBinaryMessenger* messenger,
94 GAsyncResult* result,
95 GError** error);
96
97 void (*resize_channel)(FlBinaryMessenger* messenger,
98 const gchar* channel,
99 int64_t new_size);
100
101 void (*set_allow_channel_overflow)(FlBinaryMessenger* messenger,
102 const gchar* channel,
103 bool allowed);
104 };
105
106 struct _FlBinaryMessengerResponseHandleClass {
107 GObjectClass parent_class;
108 };
109
110 /**
111 * FlBinaryMessenger:
112 *
113 * #FlBinaryMessenger is an object that allows sending and receiving of platform
114 * messages with an #FlEngine.
115 */
116
117 /**
118 * FlBinaryMessengerResponseHandle:
119 *
120 * #FlBinaryMessengerResponseHandle is an object used to send responses with.
121 */
122
123 /**
124 * fl_binary_messenger_set_platform_message_handler:
125 * @binary_messenger: an #FlBinaryMessenger.
126 * @channel: channel to listen on.
127 * @handler: (allow-none): function to call when a message is received on this
128 * channel or %NULL to disable a handler
129 * @user_data: (closure): user data to pass to @handler.
130 * @destroy_notify: (allow-none): a function which gets called to free
131 * @user_data, or %NULL.
132 *
133 * Sets the function called when a platform message is received on the given
134 * channel. See #FlBinaryMessengerMessageHandler for details on how to respond
135 * to messages.
136 *
137 * The handler is removed if the channel is closed or is replaced by another
138 * handler, set @destroy_notify if you want to detect this.
139 */
140 void fl_binary_messenger_set_message_handler_on_channel(
141 FlBinaryMessenger* messenger,
142 const gchar* channel,
143 FlBinaryMessengerMessageHandler handler,
144 gpointer user_data,
145 GDestroyNotify destroy_notify);
146
147 /**
148 * fl_binary_messenger_send_response:
149 * @binary_messenger: an #FlBinaryMessenger.
150 * @response_handle: handle that was provided in a
151 * #FlBinaryMessengerMessageHandler.
152 * @response: (allow-none): response to send or %NULL for an empty response.
153 * @error: (allow-none): #GError location to store the error occurring, or %NULL
154 * to ignore.
155 *
156 * Responds to a platform message. This function is thread-safe.
157 *
158 * Returns: %TRUE on success.
159 */
160 gboolean fl_binary_messenger_send_response(
161 FlBinaryMessenger* messenger,
162 FlBinaryMessengerResponseHandle* response_handle,
163 GBytes* response,
164 GError** error);
165
166 /**
167 * fl_binary_messenger_send_on_channel:
168 * @binary_messenger: an #FlBinaryMessenger.
169 * @channel: channel to send to.
170 * @message: (allow-none): message buffer to send or %NULL for an empty message.
171 * @cancellable: (allow-none): a #GCancellable or %NULL.
172 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is
173 * satisfied.
174 * @user_data: (closure): user data to pass to @callback.
175 *
176 * Asynchronously sends a platform message.
177 */
178 void fl_binary_messenger_send_on_channel(FlBinaryMessenger* messenger,
179 const gchar* channel,
180 GBytes* message,
181 GCancellable* cancellable,
182 GAsyncReadyCallback callback,
183 gpointer user_data);
184
185 /**
186 * fl_binary_messenger_send_on_channel_finish:
187 * @messenger: an #FlBinaryMessenger.
188 * @result: a #GAsyncResult.
189 * @error: (allow-none): #GError location to store the error occurring, or %NULL
190 * to ignore.
191 *
192 * Completes request started with fl_binary_messenger_send_on_channel().
193 *
194 * Returns: (transfer full): message response on success or %NULL on error.
195 */
196 GBytes* fl_binary_messenger_send_on_channel_finish(FlBinaryMessenger* messenger,
197 GAsyncResult* result,
198 GError** error);
199
200 /**
201 * fl_binary_messenger_resize_channel:
202 * @binary_messenger: an #FlBinaryMessenger.
203 * @channel: channel to be resize.
204 * @new_size: the new size for the channel buffer.
205 *
206 * Sends a message to the control channel asking to resize a channel buffer.
207 */
208 void fl_binary_messenger_resize_channel(FlBinaryMessenger* messenger,
209 const gchar* channel,
210 int64_t new_size);
211
212 /**
213 * fl_binary_messenger_set_allow_channel_overflow:
214 * @messenger: an #FlBinaryMessenger.
215 * @channel: channel to be allowed to overflow silently.
216 * @allowed: when true the channel is expected to overflow and warning messages
217 * will not be shown.
218 *
219 * Sends a message to the control channel asking to allow or disallow a channel
220 * to overflow silently.
221 */
222 void fl_binary_messenger_set_allow_channel_overflow(
223 FlBinaryMessenger* messenger,
224 const gchar* channel,
225 bool allowed);
226
227 G_END_DECLS
228
229 #endif // FLUTTER_SHELL_PLATFORM_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:71
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:72
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
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:107
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
fl_binary_messenger_set_allow_channel_overflow
void fl_binary_messenger_set_allow_channel_overflow(FlBinaryMessenger *messenger, const gchar *channel, bool allowed)
Definition: fl_binary_messenger.cc:484
_FlBinaryMessengerResponseHandleClass
Definition: fl_binary_messenger.h:106
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:64
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:30
FL
G_MODULE_EXPORT FL
Definition: fl_binary_messenger.h:45
fl_value.h
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
set_allow_channel_overflow
static void set_allow_channel_overflow(FlBinaryMessenger *messenger, const gchar *channel, bool allowed)
Definition: fl_binary_messenger.cc:372
fl_binary_messenger_response_handle
G_MODULE_EXPORT fl_binary_messenger_response_handle
Definition: fl_binary_messenger.h:44
BINARY_MESSENGER_RESPONSE_HANDLE
G_MODULE_EXPORT BINARY_MESSENGER_RESPONSE_HANDLE
Definition: fl_binary_messenger.h:46
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
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