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