| Flutter Linux Embedder |

Classes | Functions | Variables
fl_binary_messenger.cc File Reference
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"`
`#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"`
`#include "flutter/fml/logging.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/fl_method_codec_private.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"`
`#include <gmodule.h>`

Go to the source code of this file.

## Classes
struct | _FlBinaryMessengerResponseHandleImpl
struct | PlatformMessageHandler

## Functions
| G_DEFINE_QUARK (fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) G_DECLARE_FINAL_TYPE(FlBinaryMessengerImpl
GObject | G_DECLARE_FINAL_TYPE (FlBinaryMessengerResponseHandleImpl, fl_binary_messenger_response_handle_impl, FL, BINARY_MESSENGER_RESPONSE_HANDLE_IMPL, FlBinaryMessengerResponseHandle) struct _FlBinaryMessengerImpl
static void | fl_binary_messenger_impl_iface_init (FlBinaryMessengerInterface *iface)
| G_DEFINE_TYPE_WITH_CODE (FlBinaryMessengerImpl, fl_binary_messenger_impl, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(fl_binary_messenger_get_type(), fl_binary_messenger_impl_iface_init)) static void fl_binary_messenger_response_handle_class_init(FlBinaryMessengerResponseHandleClass *klass)
| G_DEFINE_TYPE (FlBinaryMessengerResponseHandle, fl_binary_messenger_response_handle, G_TYPE_OBJECT) static void fl_binary_messenger_response_handle_init(FlBinaryMessengerResponseHandle *self)
| G_DEFINE_TYPE (FlBinaryMessengerResponseHandleImpl, fl_binary_messenger_response_handle_impl, fl_binary_messenger_response_handle_get_type()) static void fl_binary_messenger_default_init(FlBinaryMessengerInterface *iface)
static void | fl_binary_messenger_response_handle_impl_dispose (GObject *object)
static void | fl_binary_messenger_response_handle_impl_class_init (FlBinaryMessengerResponseHandleImplClass *klass)
static void | fl_binary_messenger_response_handle_impl_init (FlBinaryMessengerResponseHandleImpl *self)
static FlBinaryMessengerResponseHandleImpl * | fl_binary_messenger_response_handle_impl_new (FlBinaryMessengerImpl *messenger, const FlutterPlatformMessageResponseHandle *response_handle)
static PlatformMessageHandler * | platform_message_handler_new (FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
static void | platform_message_handler_free (gpointer data)
static gboolean | fl_binary_messenger_platform_message_cb (FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, void *user_data)
static void | fl_binary_messenger_impl_dispose (GObject *object)
static void | set_message_handler_on_channel (FlBinaryMessenger *messenger, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
static gboolean | do_unref (gpointer value)
static gboolean | send_response (FlBinaryMessenger *messenger, FlBinaryMessengerResponseHandle *response_handle_, GBytes *response, GError **error)
static void | platform_message_ready_cb (GObject *object, GAsyncResult *result, gpointer user_data)
static void | send_on_channel (FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
static GBytes * | send_on_channel_finish (FlBinaryMessenger *messenger, GAsyncResult *result, GError **error)
static gboolean | finish_method (GObject *object, GAsyncResult *result, GError **error)
static void | resize_channel_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
static void | resize_channel (FlBinaryMessenger *messenger, const gchar *channel, int64_t new_size)
static void | set_warns_on_channel_overflow_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
static void | set_warns_on_channel_overflow (FlBinaryMessenger *messenger, const gchar *channel, bool warns)
static void | shutdown (FlBinaryMessenger *messenger)
static void | fl_binary_messenger_impl_class_init (FlBinaryMessengerImplClass *klass)
static void | fl_binary_messenger_impl_init (FlBinaryMessengerImpl *self)
FlBinaryMessenger * | fl_binary_messenger_new (FlEngine *engine)
G_MODULE_EXPORT void | fl_binary_messenger_set_message_handler_on_channel (FlBinaryMessenger *self, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT gboolean | fl_binary_messenger_send_response (FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
G_MODULE_EXPORT void | fl_binary_messenger_send_on_channel (FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
G_MODULE_EXPORT GBytes * | fl_binary_messenger_send_on_channel_finish (FlBinaryMessenger *self, GAsyncResult *result, GError **error)
G_MODULE_EXPORT void | fl_binary_messenger_resize_channel (FlBinaryMessenger *self, const gchar *channel, int64_t new_size)
G_MODULE_EXPORT void | fl_binary_messenger_set_warns_on_channel_overflow (FlBinaryMessenger *self, const gchar *channel, bool warns)
gboolean | fl_binary_messenger_handle_message (FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle)
void | fl_binary_messenger_shutdown (FlBinaryMessenger *self)

## Variables
static constexpr char | kControlChannelName [] = "dev.flutter/channel-buffers"
static constexpr char | kResizeMethod [] = "resize"
static constexpr char | kOverflowMethod [] = "overflow"
| fl_binary_messenger_impl
| FL
| BINARY_MESSENGER_IMPL

## Function Documentation

## ◆ do_unref()

static gboolean do_unref | ( | gpointer | value | ) |
| static

Definition at line 204 of file fl_binary_messenger.cc.

204 {
205 g_object_unref(value);
206 return G_SOURCE_REMOVE;
207 }
value
uint8_t value
Definition: fl_standard_message_codec.cc:36

References value.

Referenced by send_response().

## ◆ finish_method()

static gboolean finish_method | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | GError ** | error
| ) |  |
| static

Definition at line 297 of file fl_binary_messenger.cc.

299 {
300 g_autoptr(GBytes) response = fl_binary_messenger_send_on_channel_finish(
301 FL_BINARY_MESSENGER(object), result, error);
302 if (response == nullptr) {
303 return FALSE;
304 }
305 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
306 return fl_method_codec_decode_response(FL_METHOD_CODEC(codec), response,
307 error) != nullptr;
308 }
fl_binary_messenger_send_on_channel_finish
G_MODULE_EXPORT GBytes * fl_binary_messenger_send_on_channel_finish(FlBinaryMessenger *self, GAsyncResult *result, GError **error)
Definition: fl_binary_messenger.cc:449
g_autoptr
g_autoptr(GMutexLocker) locker
fl_method_codec_decode_response
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
Definition: fl_method_codec.cc:88
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_standard_method_codec_new
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
Definition: fl_standard_method_codec.cc:291

References error, fl_binary_messenger_send_on_channel_finish(), fl_method_codec_decode_response(), fl_standard_method_codec_new(), and g_autoptr().

Referenced by resize_channel_response_cb(), and set_warns_on_channel_overflow_response_cb().

## ◆ fl_binary_messenger_handle_message()

gboolean fl_binary_messenger_handle_message | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | GBytes * | message,
|  | const FlutterPlatformMessageResponseHandle * | response_handle
| ) |  |

fl_binary_messenger_handle_message: @messenger: an #FlBinaryMessenger. @channel: channel message received on. @message: message data. @response_handle: handle to provide to fl_engine_send_platform_message_response().

Handles a message received from the engine. Available for testing purposes.

Returns: TRUE if the message is handled.

Definition at line 478 of file fl_binary_messenger.cc.

482 {
483 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
484
485 PlatformMessageHandler* handler = static_cast<PlatformMessageHandler*>(
486 g_hash_table_lookup(self->platform_message_handlers, channel));
487 if (handler == nullptr) {
488 return FALSE;
489 }
490
491 g_autoptr(FlBinaryMessengerResponseHandleImpl) handle =
492 fl_binary_messenger_response_handle_impl_new(self, response_handle);
493 handler->message_handler(FL_BINARY_MESSENGER(self), channel, message,
494 FL_BINARY_MESSENGER_RESPONSE_HANDLE(handle),
495 handler->message_handler_data);
496
497 return TRUE;
498 }
fl_binary_messenger_response_handle_impl_new
static FlBinaryMessengerResponseHandleImpl * fl_binary_messenger_response_handle_impl_new(FlBinaryMessengerImpl *messenger, const FlutterPlatformMessageResponseHandle *response_handle)
Definition: fl_binary_messenger.cc:113
TRUE
return TRUE
Definition: fl_compositor_software.cc:68
PlatformMessageHandler
Definition: fl_binary_messenger.cc:126
PlatformMessageHandler::message_handler
FlBinaryMessengerMessageHandler message_handler
Definition: fl_binary_messenger.cc:127
PlatformMessageHandler::message_handler_data
gpointer message_handler_data
Definition: fl_binary_messenger.cc:128

References fl_binary_messenger_response_handle_impl_new(), g_autoptr(), PlatformMessageHandler::message_handler, PlatformMessageHandler::message_handler_data, and TRUE.

Referenced by fl_binary_messenger_platform_message_cb(), and TEST().

## ◆ fl_binary_messenger_impl_class_init()

static void fl_binary_messenger_impl_class_init | ( | FlBinaryMessengerImplClass * | klass | ) |
| static

Definition at line 370 of file fl_binary_messenger.cc.

371 {
372 G_OBJECT_CLASS(klass)->dispose = fl_binary_messenger_impl_dispose;
373 }
fl_binary_messenger_impl_dispose
static void fl_binary_messenger_impl_dispose(GObject *object)
Definition: fl_binary_messenger.cc:163

References fl_binary_messenger_impl_dispose().

## ◆ fl_binary_messenger_impl_dispose()

static void fl_binary_messenger_impl_dispose | ( | GObject * | object | ) |
| static

Definition at line 163 of file fl_binary_messenger.cc.

163 {
164 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(object);
165
166 g_weak_ref_clear(&self->engine);
167
168 g_clear_pointer(&self->platform_message_handlers, g_hash_table_unref);
169
170 G_OBJECT_CLASS(fl_binary_messenger_impl_parent_class)->dispose(object);
171 }

Referenced by fl_binary_messenger_impl_class_init().

## ◆ fl_binary_messenger_impl_iface_init()

static void fl_binary_messenger_impl_iface_init | ( | FlBinaryMessengerInterface * | iface | ) |
| static

Definition at line 375 of file fl_binary_messenger.cc.

376 {
377 iface->set_message_handler_on_channel = set_message_handler_on_channel;
378 iface->send_response = send_response;
379 iface->send_on_channel = send_on_channel;
380 iface->send_on_channel_finish = send_on_channel_finish;
381 iface->resize_channel = resize_channel;
382 iface->set_warns_on_channel_overflow = set_warns_on_channel_overflow;
383 iface->shutdown = shutdown;
384 }
resize_channel
static void resize_channel(FlBinaryMessenger *messenger, const gchar *channel, int64_t new_size)
Definition: fl_binary_messenger.cc:320
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:255
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:173
send_response
static gboolean send_response(FlBinaryMessenger *messenger, FlBinaryMessengerResponseHandle *response_handle_, GBytes *response, GError **error)
Definition: fl_binary_messenger.cc:210
set_warns_on_channel_overflow
static void set_warns_on_channel_overflow(FlBinaryMessenger *messenger, const gchar *channel, bool warns)
Definition: fl_binary_messenger.cc:345
send_on_channel_finish
static GBytes * send_on_channel_finish(FlBinaryMessenger *messenger, GAsyncResult *result, GError **error)
Definition: fl_binary_messenger.cc:275
shutdown
static void shutdown(FlBinaryMessenger *messenger)
Definition: fl_binary_messenger.cc:359

References resize_channel(), send_on_channel(), send_on_channel_finish(), send_response(), set_message_handler_on_channel(), set_warns_on_channel_overflow(), and shutdown().

## ◆ fl_binary_messenger_impl_init()

static void fl_binary_messenger_impl_init | ( | FlBinaryMessengerImpl * | self | ) |
| static

Definition at line 386 of file fl_binary_messenger.cc.

386 {
387 self->platform_message_handlers = g_hash_table_new_full(
388 g_str_hash, g_str_equal, g_free, platform_message_handler_free);
389 }
platform_message_handler_free
static void platform_message_handler_free(gpointer data)
Definition: fl_binary_messenger.cc:144

References platform_message_handler_free().

## ◆ fl_binary_messenger_new()

FlBinaryMessenger* fl_binary_messenger_new | ( | FlEngine * | engine | ) |

fl_binary_messenger_new: @engine: The #FlEngine to communicate with.

Creates a new #FlBinaryMessenger. The binary messenger will take control of the engines platform message handler.

Returns: a new #FlBinaryMessenger.

Definition at line 391 of file fl_binary_messenger.cc.

391 {
392 g_return_val_if_fail(FL_IS_ENGINE(engine), nullptr);
393
394 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(
395 g_object_new(fl_binary_messenger_impl_get_type(), nullptr));
396
397 // Added to stop compiler complaining about an unused function.
398 FL_IS_BINARY_MESSENGER_IMPL(self);
399
400 g_weak_ref_init(&self->engine, G_OBJECT(engine));
401
402 fl_engine_set_platform_message_handler(
403 engine, fl_binary_messenger_platform_message_cb, self, NULL);
404
405 return FL_BINARY_MESSENGER(self);
406 }
fl_binary_messenger_platform_message_cb
static gboolean fl_binary_messenger_platform_message_cb(FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, void *user_data)
Definition: fl_binary_messenger.cc:152
fl_engine_set_platform_message_handler
void fl_engine_set_platform_message_handler(FlEngine *self, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_engine.cc:982

References fl_binary_messenger_platform_message_cb(), and fl_engine_set_platform_message_handler().

Referenced by fl_engine_new_full(), and TEST().

## ◆ fl_binary_messenger_platform_message_cb()

static gboolean fl_binary_messenger_platform_message_cb | ( | FlEngine * | engine,
|  | const gchar * | channel,
|  | GBytes * | message,
|  | const FlutterPlatformMessageResponseHandle * | response_handle,
|  | void * | user_data
| ) |  |
| static

Definition at line 152 of file fl_binary_messenger.cc.

157 {
158 FlBinaryMessenger* self = FL_BINARY_MESSENGER(user_data);
159 return fl_binary_messenger_handle_message(self, channel, message,
160 response_handle);
161 }
fl_binary_messenger_handle_message
gboolean fl_binary_messenger_handle_message(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle)
Definition: fl_binary_messenger.cc:478
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90

References fl_binary_messenger_handle_message(), and user_data.

Referenced by fl_binary_messenger_new().

## ◆ fl_binary_messenger_resize_channel()

G_MODULE_EXPORT void fl_binary_messenger_resize_channel | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | int64_t | new_size
| ) |  |

fl_binary_messenger_resize_channel: @binary_messenger: an #FlBinaryMessenger. @channel: channel to be resize. @new_size: the new size for the channel buffer.

Sends a message to the control channel asking to resize a channel buffer.

Definition at line 459 of file fl_binary_messenger.cc.

461 {
462 g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
463
464 return FL_BINARY_MESSENGER_GET_IFACE(self)->resize_channel(self, channel,
465 new_size);
466 }

Referenced by TEST().

## ◆ fl_binary_messenger_response_handle_impl_class_init()

static void fl_binary_messenger_response_handle_impl_class_init | ( | FlBinaryMessengerResponseHandleImplClass * | klass | ) |
| static

Definition at line 103 of file fl_binary_messenger.cc.

104 {
105 G_OBJECT_CLASS(klass)->dispose =
106 fl_binary_messenger_response_handle_impl_dispose;
107 }
fl_binary_messenger_response_handle_impl_dispose
static void fl_binary_messenger_response_handle_impl_dispose(GObject *object)
Definition: fl_binary_messenger.cc:86

References fl_binary_messenger_response_handle_impl_dispose().

## ◆ fl_binary_messenger_response_handle_impl_dispose()

static void fl_binary_messenger_response_handle_impl_dispose | ( | GObject * | object | ) |
| static

Definition at line 86 of file fl_binary_messenger.cc.

86 {
87 FlBinaryMessengerResponseHandleImpl* self =
88 FL_BINARY_MESSENGER_RESPONSE_HANDLE_IMPL(object);
89
90 g_autoptr(FlEngine) engine =
91 FL_ENGINE(g_weak_ref_get(&self->messenger->engine));
92 if (self->response_handle != nullptr && engine != nullptr) {
93 g_critical("FlBinaryMessengerResponseHandle was not responded to");
94 }
95
96 g_clear_object(&self->messenger);
97 self->response_handle = nullptr;
98
99 G_OBJECT_CLASS(fl_binary_messenger_response_handle_impl_parent_class)
100 ->dispose(object);
101 }

References g_autoptr().

Referenced by fl_binary_messenger_response_handle_impl_class_init().

## ◆ fl_binary_messenger_response_handle_impl_init()

static void fl_binary_messenger_response_handle_impl_init | ( | FlBinaryMessengerResponseHandleImpl * | self | ) |
| static

Definition at line 109 of file fl_binary_messenger.cc.

110 {}

## ◆ fl_binary_messenger_response_handle_impl_new()

static FlBinaryMessengerResponseHandleImpl* fl_binary_messenger_response_handle_impl_new | ( | FlBinaryMessengerImpl * | messenger,
|  | const FlutterPlatformMessageResponseHandle * | response_handle
| ) |  |
| static

Definition at line 113 of file fl_binary_messenger.cc.

115 {
116 FlBinaryMessengerResponseHandleImpl* self =
117 FL_BINARY_MESSENGER_RESPONSE_HANDLE_IMPL(g_object_new(
118 fl_binary_messenger_response_handle_impl_get_type(), nullptr));
119
120 self->messenger = FL_BINARY_MESSENGER_IMPL(g_object_ref(messenger));
121 self->response_handle = response_handle;
122
123 return self;
124 }

Referenced by fl_binary_messenger_handle_message().

## ◆ fl_binary_messenger_send_on_channel()

G_MODULE_EXPORT void fl_binary_messenger_send_on_channel | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | GBytes * | message,
|  | GCancellable * | cancellable,
|  | GAsyncReadyCallback | callback,
|  | gpointer | user_data
| ) |  |

fl_binary_messenger_send_on_channel: @binary_messenger: an #FlBinaryMessenger. @channel: channel to send to. @message: (allow-none): message buffer to send or NULL for an empty message. @cancellable: (allow-none): a #GCancellable or NULL. @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied. @user_data: (closure): user data to pass to @callback.

Asynchronously sends a platform message.

Definition at line 435 of file fl_binary_messenger.cc.

441 {
442 g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
443 g_return_if_fail(channel != nullptr);
444
445 FL_BINARY_MESSENGER_GET_IFACE(self)->send_on_channel(
446 self, channel, message, cancellable, callback, user_data);
447 }

References user_data.

Referenced by fl_basic_message_channel_send(), fl_event_channel_send(), fl_event_channel_send_end_of_stream(), fl_event_channel_send_error(), fl_method_channel_invoke_method(), resize_channel(), send_lifecycle_state(), set_warns_on_channel_overflow(), and TEST().

## ◆ fl_binary_messenger_send_on_channel_finish()

G_MODULE_EXPORT GBytes* fl_binary_messenger_send_on_channel_finish | ( | FlBinaryMessenger * | messenger,
|  | GAsyncResult * | result,
|  | GError ** | error
| ) |  |

fl_binary_messenger_send_on_channel_finish: @messenger: an #FlBinaryMessenger.

Returns
  : a #GAsyncResult. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore.

Completes request started with fl_binary_messenger_send_on_channel().

Returns: (transfer full): message response on success or NULL on error.

Definition at line 449 of file fl_binary_messenger.cc.

452 {
453 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
454
455 return FL_BINARY_MESSENGER_GET_IFACE(self)->send_on_channel_finish(
456 self, result, error);
457 }

References error.

Referenced by finish_method(), fl_basic_message_channel_send_finish(), fl_method_channel_invoke_method_finish(), and TEST().

## ◆ fl_binary_messenger_send_response()

G_MODULE_EXPORT gboolean fl_binary_messenger_send_response | ( | FlBinaryMessenger * | messenger,
|  | FlBinaryMessengerResponseHandle * | response_handle,
|  | GBytes * | response,
|  | GError ** | error
| ) |  |

fl_binary_messenger_send_response: @binary_messenger: an #FlBinaryMessenger. @response_handle: handle that was provided in a FlBinaryMessengerMessageHandler. @response: (allow-none): response to send or NULL for an empty response. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore.

Responds to a platform message. This function is thread-safe.

Returns: TRUE on success.

Definition at line 422 of file fl_binary_messenger.cc.

426 {
427 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
428 g_return_val_if_fail(FL_IS_BINARY_MESSENGER_RESPONSE_HANDLE(response_handle),
429 FALSE);
430
431 return FL_BINARY_MESSENGER_GET_IFACE(self)->send_response(
432 self, response_handle, response, error);
433 }

References error.

Referenced by fl_basic_message_channel_respond(), fl_method_channel_respond(), message_cb(), and TEST().

## ◆ fl_binary_messenger_set_message_handler_on_channel()

G_MODULE_EXPORT void fl_binary_messenger_set_message_handler_on_channel | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | FlBinaryMessengerMessageHandler | handler,
|  | gpointer | user_data,
|  | GDestroyNotify | destroy_notify
| ) |  |

FlBinaryMessenger:

#FlBinaryMessenger is an object that allows sending and receiving of platform messages with an #FlEngine. FlBinaryMessengerResponseHandle:

#FlBinaryMessengerResponseHandle is an object used to send responses with. fl_binary_messenger_set_platform_message_handler: @binary_messenger: an #FlBinaryMessenger. @channel: channel to listen on. @handler: (allow-none): function to call when a message is received on this channel or NULL to disable a handler @user_data: (closure): user data to pass to @handler. @destroy_notify: (allow-none): a function which gets called to free @user_data, or NULL.

Sets the function called when a platform message is received on the given channel. See FlBinaryMessengerMessageHandler for details on how to respond to messages.

The handler is removed if the channel is closed or is replaced by another handler, set @destroy_notify if you want to detect this.

Definition at line 408 of file fl_binary_messenger.cc.

413 {
414 g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
415 g_return_if_fail(channel != nullptr);
416
417 FL_BINARY_MESSENGER_GET_IFACE(self)->set_message_handler_on_channel(
418 self, channel, handler, user_data, destroy_notify);
419 }

References user_data.

Referenced by fl_basic_message_channel_dispose(), fl_basic_message_channel_new(), fl_event_channel_dispose(), fl_event_channel_new(), fl_method_channel_new(), and TEST().

## ◆ fl_binary_messenger_set_warns_on_channel_overflow()

G_MODULE_EXPORT void fl_binary_messenger_set_warns_on_channel_overflow | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | bool | warns
| ) |  |

fl_binary_messenger_set_warns_on_channel_overflow: @messenger: an #FlBinaryMessenger. @channel: channel to be allowed to overflow silently. @warns: when false, the channel is expected to overflow and warning messages will not be shown.

Sends a message to the control channel asking to allow or disallow a channel to overflow silently.

Definition at line 468 of file fl_binary_messenger.cc.

471 {
472 g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
473
474 return FL_BINARY_MESSENGER_GET_IFACE(self)->set_warns_on_channel_overflow(
475 self, channel, warns);
476 }

Referenced by TEST().

## ◆ fl_binary_messenger_shutdown()

void fl_binary_messenger_shutdown | ( | FlBinaryMessenger * | messenger | ) |

fl_binary_messenger_shutdown: @messenger: an #FlBinaryMessenger.

Shutdown the messenger closing any open channels.

Definition at line 500 of file fl_binary_messenger.cc.

500 {
501 g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
502
503 return FL_BINARY_MESSENGER_GET_IFACE(self)->shutdown(self);
504 }

Referenced by fl_engine_dispose(), fl_test_application_activate(), TEST(), and test_lock_event().

## ◆ G_DECLARE_FINAL_TYPE()

GObject G_DECLARE_FINAL_TYPE | ( | FlBinaryMessengerResponseHandleImpl | ,
|  | fl_binary_messenger_response_handle_impl | ,
|  | FL | ,
|  | BINARY_MESSENGER_RESPONSE_HANDLE_IMPL | ,
|  | FlBinaryMessengerResponseHandle |
| ) |  |

Definition at line 31 of file fl_binary_messenger.cc.

39 {
40 GObject parent_instance;
41
42 GWeakRef engine;
43
44 // PlatformMessageHandler keyed by channel name.
45 GHashTable* platform_message_handlers;
46 };

## ◆ G_DEFINE_QUARK()

G_DEFINE_QUARK | ( | fl_binary_messenger_codec_error_quark | ,
|  | fl_binary_messenger_codec_error |
| ) |  |

## ◆ G_DEFINE_TYPE() [1/2]

G_DEFINE_TYPE | ( | FlBinaryMessengerResponseHandle | ,
|  | fl_binary_messenger_response_handle | ,
|  | G_TYPE_OBJECT |
| ) |  |

Definition at line 61 of file fl_binary_messenger.cc.

66 {}

## ◆ G_DEFINE_TYPE() [2/2]

G_DEFINE_TYPE | ( | FlBinaryMessengerResponseHandleImpl | ,
|  | fl_binary_messenger_response_handle_impl | ,
|  | fl_binary_messenger_response_handle_get_type() |
| ) |  |

Definition at line 79 of file fl_binary_messenger.cc.

84 {}

## ◆ G_DEFINE_TYPE_WITH_CODE()

G_DEFINE_TYPE_WITH_CODE | ( | FlBinaryMessengerImpl | ,
|  | fl_binary_messenger_impl | ,
|  | G_TYPE_OBJECT | ,
|  | G_IMPLEMENT_INTERFACE(fl_binary_messenger_get_type(), fl_binary_messenger_impl_iface_init) |
| ) |  |

Definition at line 51 of file fl_binary_messenger.cc.

59 {}

## ◆ platform_message_handler_free()

static void platform_message_handler_free | ( | gpointer | data | ) |
| static

Definition at line 144 of file fl_binary_messenger.cc.

144 {
145 PlatformMessageHandler* self = static_cast<PlatformMessageHandler*>(data);
146 if (self->message_handler_destroy_notify) {
147 self->message_handler_destroy_notify(self->message_handler_data);
148 }
149 g_free(self);
150 }
PlatformMessageHandler::message_handler_destroy_notify
GDestroyNotify message_handler_destroy_notify
Definition: fl_binary_messenger.cc:129

References PlatformMessageHandler::message_handler_destroy_notify.

Referenced by fl_binary_messenger_impl_init(), and shutdown().

## ◆ platform_message_handler_new()

static PlatformMessageHandler* platform_message_handler_new | ( | FlBinaryMessengerMessageHandler | handler,
|  | gpointer | user_data,
|  | GDestroyNotify | destroy_notify
| ) |  |
| static

Definition at line 132 of file fl_binary_messenger.cc.

135 {
136 PlatformMessageHandler* self = static_cast<PlatformMessageHandler*>(
137 g_malloc0(sizeof(PlatformMessageHandler)));
138 self->message_handler = handler;
139 self->message_handler_data = user_data;
140 self->message_handler_destroy_notify = destroy_notify;
141 return self;
142 }

References PlatformMessageHandler::message_handler, and user_data.

Referenced by set_message_handler_on_channel().

## ◆ platform_message_ready_cb()

static void platform_message_ready_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 248 of file fl_binary_messenger.cc.

250 {
251 g_autoptr(GTask) task = G_TASK(user_data);
252 g_task_return_pointer(task, g_object_ref(result), g_object_unref);
253 }

References g_autoptr(), and user_data.

Referenced by send_on_channel().

## ◆ resize_channel()

static void resize_channel | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | int64_t | new_size
| ) |  |
| static

Definition at line 320 of file fl_binary_messenger.cc.

322 {
323 FML_DCHECK(new_size >= 0);
324 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
325 g_autoptr(FlValue) args = fl_value_new_list();
326 fl_value_append_take(args, fl_value_new_string(channel));
327 fl_value_append_take(args, fl_value_new_int(new_size));
328 g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
329 FL_METHOD_CODEC(codec), kResizeMethod, args, nullptr);
330 fl_binary_messenger_send_on_channel(messenger, kControlChannelName, message,
331 nullptr, resize_channel_response_cb,
332 nullptr);
333 }
fl_binary_messenger_send_on_channel
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_binary_messenger.cc:435
kControlChannelName
static constexpr char kControlChannelName[]
Definition: fl_binary_messenger.cc:18
resize_channel_response_cb
static void resize_channel_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_binary_messenger.cc:311
kResizeMethod
static constexpr char kResizeMethod[]
Definition: fl_binary_messenger.cc:19
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
fl_method_codec_encode_method_call
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
Definition: fl_method_codec.cc:16
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
fl_value_new_list
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:349
fl_value_append_take
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:600
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42

References args, fl_binary_messenger_send_on_channel(), fl_method_codec_encode_method_call(), fl_standard_method_codec_new(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), fl_value_new_string(), g_autoptr(), kControlChannelName, kResizeMethod, and resize_channel_response_cb().

Referenced by fl_binary_messenger_impl_iface_init().

## ◆ resize_channel_response_cb()

static void resize_channel_response_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 311 of file fl_binary_messenger.cc.

313 {
314 g_autoptr(GError) error = nullptr;
315 if (!finish_method(object, result, &error)) {
316 g_warning("Failed to resize channel: %s", error->message);
317 }
318 }
finish_method
static gboolean finish_method(GObject *object, GAsyncResult *result, GError **error)
Definition: fl_binary_messenger.cc:297

References error, finish_method(), and g_autoptr().

Referenced by resize_channel().

## ◆ send_on_channel()

static void send_on_channel | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | GBytes * | message,
|  | GCancellable * | cancellable,
|  | GAsyncReadyCallback | callback,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 255 of file fl_binary_messenger.cc.

260 {
261 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
262
263 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
264 if (engine == nullptr) {
265 return;
266 }
267
268 fl_engine_send_platform_message(
269 engine, channel, message, cancellable,
270 callback != nullptr ? platform_message_ready_cb : nullptr,
271 callback != nullptr ? g_task_new(self, cancellable, callback, user_data)
272 : nullptr);
273 }
platform_message_ready_cb
static void platform_message_ready_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_binary_messenger.cc:248
fl_engine_send_platform_message
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:1033

References fl_engine_send_platform_message(), g_autoptr(), platform_message_ready_cb(), and user_data.

Referenced by fl_binary_messenger_impl_iface_init().

## ◆ send_on_channel_finish()

static GBytes* send_on_channel_finish | ( | FlBinaryMessenger * | messenger,
|  | GAsyncResult * | result,
|  | GError ** | error
| ) |  |
| static

Definition at line 275 of file fl_binary_messenger.cc.

277 {
278 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
279 g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
280
281 GTask* task = G_TASK(result);
282 g_autoptr(GAsyncResult) r =
283 G_ASYNC_RESULT(g_task_propagate_pointer(task, error));
284 if (r == nullptr) {
285 return nullptr;
286 }
287
288 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
289 if (engine == nullptr) {
290 return nullptr;
291 }
292
293 return fl_engine_send_platform_message_finish(engine, r, error);
294 }
fl_engine_send_platform_message_finish
GBytes * fl_engine_send_platform_message_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:1092

References error, fl_engine_send_platform_message_finish(), and g_autoptr().

Referenced by fl_binary_messenger_impl_iface_init().

## ◆ send_response()

static gboolean send_response | ( | FlBinaryMessenger * | messenger,
|  | FlBinaryMessengerResponseHandle * | response_handle_,
|  | GBytes * | response,
|  | GError ** | error
| ) |  |
| static

Definition at line 210 of file fl_binary_messenger.cc.

213 {
214 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
215 g_return_val_if_fail(
216 FL_IS_BINARY_MESSENGER_RESPONSE_HANDLE_IMPL(response_handle_), FALSE);
217 FlBinaryMessengerResponseHandleImpl* response_handle =
218 FL_BINARY_MESSENGER_RESPONSE_HANDLE_IMPL(response_handle_);
219
220 g_return_val_if_fail(response_handle->messenger == self, FALSE);
221 g_return_val_if_fail(response_handle->response_handle != nullptr, FALSE);
222
223 FlEngine* engine = FL_ENGINE(g_weak_ref_get(&self->engine));
224 if (engine == nullptr) {
225 return TRUE;
226 }
227
228 gboolean result = false;
229 if (response_handle->response_handle == nullptr) {
230 g_set_error(
231 error, FL_BINARY_MESSENGER_ERROR,
232 FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED,
233 "Attempted to respond to a message that is already responded to");
234 result = FALSE;
235 } else {
236 result = fl_engine_send_platform_message_response(
237 engine, response_handle->response_handle, response, error);
238 response_handle->response_handle = nullptr;
239 }
240
241 // This guarantees that the dispose method for the engine is executed
242 // on the platform thread in the rare chance this is the last ref.
243 g_idle_add(do_unref, engine);
244
245 return result;
246 }
do_unref
static gboolean do_unref(gpointer value)
Definition: fl_binary_messenger.cc:204
FL_BINARY_MESSENGER_ERROR
#define FL_BINARY_MESSENGER_ERROR
Definition: fl_binary_messenger.h:27
FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED
@ FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED
Definition: fl_binary_messenger.h:31
fl_engine_send_platform_message_response
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:1001

References do_unref(), error, FL_BINARY_MESSENGER_ERROR, FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED, fl_engine_send_platform_message_response(), and TRUE.

Referenced by fl_binary_messenger_impl_iface_init().

## ◆ 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
| ) |  |
| static

Definition at line 173 of file fl_binary_messenger.cc.

178 {
179 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
180
181 // Don't set handlers if engine already gone.
182 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
183 if (engine == nullptr) {
184 if (handler != nullptr) {
185 g_warning(
186 "Attempted to set message handler on an FlBinaryMessenger without an "
187 "engine");
188 }
189 if (destroy_notify != nullptr) {
190 destroy_notify(user_data);
191 }
192 return;
193 }
194
195 if (handler != nullptr) {
196 g_hash_table_replace(
197 self->platform_message_handlers, g_strdup(channel),
198 platform_message_handler_new(handler, user_data, destroy_notify));
199 } else {
200 g_hash_table_remove(self->platform_message_handlers, channel);
201 }
202 }
platform_message_handler_new
static PlatformMessageHandler * platform_message_handler_new(FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_binary_messenger.cc:132

References g_autoptr(), platform_message_handler_new(), and user_data.

Referenced by fl_binary_messenger_impl_iface_init().

## ◆ set_warns_on_channel_overflow()

static void set_warns_on_channel_overflow | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | channel,
|  | bool | warns
| ) |  |
| static

Definition at line 345 of file fl_binary_messenger.cc.

347 {
348 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
349 g_autoptr(FlValue) args = fl_value_new_list();
350 fl_value_append_take(args, fl_value_new_string(channel));
351 fl_value_append_take(args, fl_value_new_bool(!warns));
352 g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
353 FL_METHOD_CODEC(codec), kOverflowMethod, args, nullptr);
354 fl_binary_messenger_send_on_channel(
355 messenger, kControlChannelName, message, nullptr,
356 set_warns_on_channel_overflow_response_cb, nullptr);
357 }
kOverflowMethod
static constexpr char kOverflowMethod[]
Definition: fl_binary_messenger.cc:20
set_warns_on_channel_overflow_response_cb
static void set_warns_on_channel_overflow_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_binary_messenger.cc:336
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255

References args, fl_binary_messenger_send_on_channel(), fl_method_codec_encode_method_call(), fl_standard_method_codec_new(), fl_value_append_take(), fl_value_new_bool(), fl_value_new_list(), fl_value_new_string(), g_autoptr(), kControlChannelName, kOverflowMethod, and set_warns_on_channel_overflow_response_cb().

Referenced by fl_binary_messenger_impl_iface_init().

## ◆ set_warns_on_channel_overflow_response_cb()

static void set_warns_on_channel_overflow_response_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 336 of file fl_binary_messenger.cc.

338 {
339 g_autoptr(GError) error = nullptr;
340 if (!finish_method(object, result, &error)) {
341 g_warning("Failed to set warns on channel overflow: %s", error->message);
342 }
343 }

References error, finish_method(), and g_autoptr().

Referenced by set_warns_on_channel_overflow().

## ◆ shutdown()

static void shutdown | ( | FlBinaryMessenger * | messenger | ) |
| static

Definition at line 359 of file fl_binary_messenger.cc.

359 {
360 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
361
362 // Disconnect any handlers.
363 // Take the reference in case a handler tries to modify this table.
364 g_autoptr(GHashTable) handlers = self->platform_message_handlers;
365 self->platform_message_handlers = g_hash_table_new_full(
366 g_str_hash, g_str_equal, g_free, platform_message_handler_free);
367 g_hash_table_remove_all(handlers);
368 }

References g_autoptr(), and platform_message_handler_free().

Referenced by fl_binary_messenger_impl_iface_init(), and G_DECLARE_INTERFACE().

## Variable Documentation

## ◆ BINARY_MESSENGER_IMPL

BINARY_MESSENGER_IMPL

Definition at line 28 of file fl_binary_messenger.cc.

## ◆ FL

FL

Definition at line 27 of file fl_binary_messenger.cc.

## ◆ fl_binary_messenger_impl

fl_binary_messenger_impl

Definition at line 26 of file fl_binary_messenger.cc.

## ◆ kControlChannelName

constexpr char kControlChannelName[] = "dev.flutter/channel-buffers"
| static constexpr

Definition at line 18 of file fl_binary_messenger.cc.

Referenced by resize_channel(), flutter::internal::ResizeChannel(), set_warns_on_channel_overflow(), and flutter::internal::SetChannelWarnsOnOverflow().

## ◆ kOverflowMethod

constexpr char kOverflowMethod[] = "overflow"
| static constexpr

Definition at line 20 of file fl_binary_messenger.cc.

Referenced by set_warns_on_channel_overflow(), and flutter::internal::SetChannelWarnsOnOverflow().

## ◆ kResizeMethod

constexpr char kResizeMethod[] = "resize"
| static constexpr

Definition at line 19 of file fl_binary_messenger.cc.

Referenced by resize_channel(), and flutter::internal::ResizeChannel().