Flutter Engine
The Flutter Engine
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 PlatformMessageHandlerplatform_message_handler_new (FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
 
static void platform_message_handler_free (gpointer data)
 
static void engine_weak_notify_cb (gpointer user_data, GObject *where_the_object_was)
 
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 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)
 

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 235 of file fl_binary_messenger.cc.

235 {
236 g_object_unref(value);
237 return G_SOURCE_REMOVE;
238}
uint8_t value

◆ engine_weak_notify_cb()

static void engine_weak_notify_cb ( gpointer  user_data,
GObject *  where_the_object_was 
)
static

Definition at line 152 of file fl_binary_messenger.cc.

153 {
154 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(user_data);
155
156 // Disconnect any handlers.
157 // Take the reference in case a handler tries to modify this table.
158 g_autoptr(GHashTable) handlers = self->platform_message_handlers;
159 self->platform_message_handlers = g_hash_table_new_full(
160 g_str_hash, g_str_equal, g_free, platform_message_handler_free);
161 g_hash_table_remove_all(handlers);
162}
static void platform_message_handler_free(gpointer data)
void * user_data

◆ finish_method()

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

Definition at line 324 of file fl_binary_messenger.cc.

326 {
327 g_autoptr(GBytes) response = fl_binary_messenger_send_on_channel_finish(
328 FL_BINARY_MESSENGER(object), result, error);
329 if (response == nullptr) {
330 return FALSE;
331 }
332 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
333 return fl_method_codec_decode_response(FL_METHOD_CODEC(codec), response,
334 error) != nullptr;
335}
G_MODULE_EXPORT GBytes * fl_binary_messenger_send_on_channel_finish(FlBinaryMessenger *self, GAsyncResult *result, GError **error)
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
GAsyncResult * result
return FALSE

◆ fl_binary_messenger_impl_class_init()

static void fl_binary_messenger_impl_class_init ( FlBinaryMessengerImplClass *  klass)
static

Definition at line 386 of file fl_binary_messenger.cc.

387 {
388 G_OBJECT_CLASS(klass)->dispose = fl_binary_messenger_impl_dispose;
389}
static void fl_binary_messenger_impl_dispose(GObject *object)

◆ fl_binary_messenger_impl_dispose()

static void fl_binary_messenger_impl_dispose ( GObject *  object)
static

Definition at line 187 of file fl_binary_messenger.cc.

187 {
188 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(object);
189
190 {
191 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
192 if (engine) {
193 g_object_weak_unref(G_OBJECT(engine), engine_weak_notify_cb, self);
194 }
195 }
196
197 g_weak_ref_clear(&self->engine);
198
199 g_clear_pointer(&self->platform_message_handlers, g_hash_table_unref);
200
201 G_OBJECT_CLASS(fl_binary_messenger_impl_parent_class)->dispose(object);
202}
FlutterEngine engine
Definition: main.cc:68
static void engine_weak_notify_cb(gpointer user_data, GObject *where_the_object_was)

◆ fl_binary_messenger_impl_iface_init()

static void fl_binary_messenger_impl_iface_init ( FlBinaryMessengerInterface *  iface)
static

Definition at line 391 of file fl_binary_messenger.cc.

392 {
393 iface->set_message_handler_on_channel = set_message_handler_on_channel;
394 iface->send_response = send_response;
395 iface->send_on_channel = send_on_channel;
396 iface->send_on_channel_finish = send_on_channel_finish;
397 iface->resize_channel = resize_channel;
398 iface->set_warns_on_channel_overflow = set_warns_on_channel_overflow;
399}
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)
static GBytes * send_on_channel_finish(FlBinaryMessenger *messenger, GAsyncResult *result, GError **error)

◆ fl_binary_messenger_impl_init()

static void fl_binary_messenger_impl_init ( FlBinaryMessengerImpl *  self)
static

Definition at line 401 of file fl_binary_messenger.cc.

401 {
402 self->platform_message_handlers = g_hash_table_new_full(
403 g_str_hash, g_str_equal, g_free, platform_message_handler_free);
404}

◆ 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 406 of file fl_binary_messenger.cc.

406 {
407 g_return_val_if_fail(FL_IS_ENGINE(engine), nullptr);
408
409 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(
410 g_object_new(fl_binary_messenger_impl_get_type(), nullptr));
411
412 // Added to stop compiler complaining about an unused function.
413 FL_IS_BINARY_MESSENGER_IMPL(self);
414
415 g_weak_ref_init(&self->engine, G_OBJECT(engine));
416 g_object_weak_ref(G_OBJECT(engine), engine_weak_notify_cb, self);
417
420
421 return FL_BINARY_MESSENGER(self);
422}
static gboolean fl_binary_messenger_platform_message_cb(FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, void *user_data)
void fl_engine_set_platform_message_handler(FlEngine *self, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_engine.cc:603

◆ 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 164 of file fl_binary_messenger.cc.

169 {
170 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(user_data);
171
172 PlatformMessageHandler* handler = static_cast<PlatformMessageHandler*>(
173 g_hash_table_lookup(self->platform_message_handlers, channel));
174 if (handler == nullptr) {
175 return FALSE;
176 }
177
178 g_autoptr(FlBinaryMessengerResponseHandleImpl) handle =
180 handler->message_handler(FL_BINARY_MESSENGER(self), channel, message,
181 FL_BINARY_MESSENGER_RESPONSE_HANDLE(handle),
182 handler->message_handler_data);
183
184 return TRUE;
185}
static FlBinaryMessengerResponseHandleImpl * fl_binary_messenger_response_handle_impl_new(FlBinaryMessengerImpl *messenger, const FlutterPlatformMessageResponseHandle *response_handle)
Win32Message message
FlBinaryMessengerMessageHandler message_handler

◆ 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 475 of file fl_binary_messenger.cc.

477 {
478 g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
479
480 return FL_BINARY_MESSENGER_GET_IFACE(self)->resize_channel(self, channel,
481 new_size);
482}

◆ 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 =
107}
static void fl_binary_messenger_response_handle_impl_dispose(GObject *object)

◆ 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}

◆ 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}

◆ 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 451 of file fl_binary_messenger.cc.

457 {
458 g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
459 g_return_if_fail(channel != nullptr);
460
461 FL_BINARY_MESSENGER_GET_IFACE(self)->send_on_channel(
462 self, channel, message, cancellable, callback, user_data);
463}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ 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 465 of file fl_binary_messenger.cc.

468 {
469 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
470
471 return FL_BINARY_MESSENGER_GET_IFACE(self)->send_on_channel_finish(
472 self, result, error);
473}

◆ 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 438 of file fl_binary_messenger.cc.

442 {
443 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
444 g_return_val_if_fail(FL_IS_BINARY_MESSENGER_RESPONSE_HANDLE(response_handle),
445 FALSE);
446
447 return FL_BINARY_MESSENGER_GET_IFACE(self)->send_response(
448 self, response_handle, response, error);
449}

◆ 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 424 of file fl_binary_messenger.cc.

429 {
430 g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
431 g_return_if_fail(channel != nullptr);
432
433 FL_BINARY_MESSENGER_GET_IFACE(self)->set_message_handler_on_channel(
434 self, channel, handler, user_data, destroy_notify);
435}

◆ 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 484 of file fl_binary_messenger.cc.

487 {
488 g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
489
490 return FL_BINARY_MESSENGER_GET_IFACE(self)->set_warns_on_channel_overflow(
491 self, channel, warns);
492}

◆ 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 {
146 if (self->message_handler_destroy_notify) {
147 self->message_handler_destroy_notify(self->message_handler_data);
148 }
149 g_free(self);
150}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ 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 {
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}

◆ platform_message_ready_cb()

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

Definition at line 279 of file fl_binary_messenger.cc.

281 {
282 GTask* task = G_TASK(user_data);
283 g_task_return_pointer(task, result, g_object_unref);
284}

◆ resize_channel()

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

Definition at line 347 of file fl_binary_messenger.cc.

349 {
350 FML_DCHECK(new_size >= 0);
351 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
352 g_autoptr(FlValue) args = fl_value_new_list();
356 FL_METHOD_CODEC(codec), kResizeMethod, args, nullptr);
359 nullptr);
360}
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
static constexpr char kControlChannelName[]
static void resize_channel_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static constexpr char kResizeMethod[]
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:600
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:349
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ resize_channel_response_cb()

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

Definition at line 338 of file fl_binary_messenger.cc.

340 {
341 g_autoptr(GError) error = nullptr;
342 if (!finish_method(object, result, &error)) {
343 g_warning("Failed to resize channel: %s", error->message);
344 }
345}
static gboolean finish_method(GObject *object, GAsyncResult *result, GError **error)

◆ 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 286 of file fl_binary_messenger.cc.

291 {
292 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
293
294 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
295 if (engine == nullptr) {
296 return;
297 }
298
300 engine, channel, message, cancellable,
301 callback != nullptr ? platform_message_ready_cb : nullptr,
302 callback != nullptr ? g_task_new(self, cancellable, callback, user_data)
303 : nullptr);
304}
static void platform_message_ready_cb(GObject *object, GAsyncResult *result, gpointer user_data)
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:688

◆ send_on_channel_finish()

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

Definition at line 306 of file fl_binary_messenger.cc.

308 {
309 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
310 g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
311
312 g_autoptr(GTask) task = G_TASK(result);
313 GAsyncResult* r = G_ASYNC_RESULT(g_task_propagate_pointer(task, nullptr));
314
315 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
316 if (engine == nullptr) {
317 return nullptr;
318 }
319
321}
GBytes * fl_engine_send_platform_message_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:747

◆ send_response()

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

Definition at line 241 of file fl_binary_messenger.cc.

244 {
245 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
246 g_return_val_if_fail(
247 FL_IS_BINARY_MESSENGER_RESPONSE_HANDLE_IMPL(response_handle_), FALSE);
248 FlBinaryMessengerResponseHandleImpl* response_handle =
249 FL_BINARY_MESSENGER_RESPONSE_HANDLE_IMPL(response_handle_);
250
251 g_return_val_if_fail(response_handle->messenger == self, FALSE);
252 g_return_val_if_fail(response_handle->response_handle != nullptr, FALSE);
253
254 FlEngine* engine = FL_ENGINE(g_weak_ref_get(&self->engine));
255 if (engine == nullptr) {
256 return TRUE;
257 }
258
259 gboolean result = false;
260 if (response_handle->response_handle == nullptr) {
261 g_set_error(
264 "Attempted to respond to a message that is already responded to");
265 result = FALSE;
266 } else {
268 engine, response_handle->response_handle, response, error);
269 response_handle->response_handle = nullptr;
270 }
271
272 // This guarantees that the dispose method for the engine is executed
273 // on the platform thread in the rare chance this is the last ref.
274 g_idle_add(do_unref, engine);
275
276 return result;
277}
static gboolean do_unref(gpointer value)
#define FL_BINARY_MESSENGER_ERROR
@ FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:656

◆ 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 204 of file fl_binary_messenger.cc.

209 {
210 FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
211
212 // Don't set handlers if engine already gone.
213 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
214 if (engine == nullptr) {
215 if (handler != nullptr) {
216 g_warning(
217 "Attempted to set message handler on an FlBinaryMessenger without an "
218 "engine");
219 }
220 if (destroy_notify != nullptr) {
221 destroy_notify(user_data);
222 }
223 return;
224 }
225
226 if (handler != nullptr) {
227 g_hash_table_replace(
228 self->platform_message_handlers, g_strdup(channel),
229 platform_message_handler_new(handler, user_data, destroy_notify));
230 } else {
231 g_hash_table_remove(self->platform_message_handlers, channel);
232 }
233}
static PlatformMessageHandler * platform_message_handler_new(FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)

◆ set_warns_on_channel_overflow()

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

Definition at line 372 of file fl_binary_messenger.cc.

374 {
375 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
376 g_autoptr(FlValue) args = fl_value_new_list();
380 FL_METHOD_CODEC(codec), kOverflowMethod, args, nullptr);
382 messenger, kControlChannelName, message, nullptr,
384}
static constexpr char kOverflowMethod[]
static void set_warns_on_channel_overflow_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255

◆ 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 363 of file fl_binary_messenger.cc.

365 {
366 g_autoptr(GError) error = nullptr;
367 if (!finish_method(object, result, &error)) {
368 g_warning("Failed to set warns on channel overflow: %s", error->message);
369 }
370}

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"
staticconstexpr

Definition at line 18 of file fl_binary_messenger.cc.

◆ kOverflowMethod

constexpr char kOverflowMethod[] = "overflow"
staticconstexpr

Definition at line 20 of file fl_binary_messenger.cc.

◆ kResizeMethod

constexpr char kResizeMethod[] = "resize"
staticconstexpr

Definition at line 19 of file fl_binary_messenger.cc.