5#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
6#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
8#include "flutter/fml/logging.h"
9#include "flutter/shell/platform/linux/fl_engine_private.h"
10#include "flutter/shell/platform/linux/fl_method_codec_private.h"
11#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
12#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
13#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h"
14#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
23 fl_binary_messenger_codec_error)
32 fl_binary_messenger_response_handle_impl,
34 BINARY_MESSENGER_RESPONSE_HANDLE_IMPL,
35 FlBinaryMessengerResponseHandle)
39struct _FlBinaryMessengerImpl {
40 GObject parent_instance;
45 GHashTable* platform_message_handlers;
49 FlBinaryMessengerInterface* iface);
52 FlBinaryMessengerImpl,
55 G_IMPLEMENT_INTERFACE(fl_binary_messenger_get_type(),
58static void fl_binary_messenger_response_handle_class_init(
59 FlBinaryMessengerResponseHandleClass* klass) {}
65static void fl_binary_messenger_response_handle_init(
66 FlBinaryMessengerResponseHandle*
self) {}
80 fl_binary_messenger_response_handle_impl,
81 fl_binary_messenger_response_handle_get_type())
83static
void fl_binary_messenger_default_init(
84 FlBinaryMessengerInterface* iface) {}
87 FlBinaryMessengerResponseHandleImpl*
self =
88 FL_BINARY_MESSENGER_RESPONSE_HANDLE_IMPL(
object);
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");
96 g_clear_object(&
self->messenger);
97 self->response_handle =
nullptr;
99 G_OBJECT_CLASS(fl_binary_messenger_response_handle_impl_parent_class)
104 FlBinaryMessengerResponseHandleImplClass* klass) {
105 G_OBJECT_CLASS(klass)->dispose =
110 FlBinaryMessengerResponseHandleImpl*
self) {}
112static FlBinaryMessengerResponseHandleImpl*
114 FlBinaryMessengerImpl* messenger,
116 FlBinaryMessengerResponseHandleImpl*
self =
117 FL_BINARY_MESSENGER_RESPONSE_HANDLE_IMPL(g_object_new(
118 fl_binary_messenger_response_handle_impl_get_type(),
nullptr));
120 self->messenger = FL_BINARY_MESSENGER_IMPL(g_object_ref(messenger));
121 self->response_handle = response_handle;
135 GDestroyNotify destroy_notify) {
138 self->message_handler = handler;
140 self->message_handler_destroy_notify = destroy_notify;
146 if (
self->message_handler_destroy_notify) {
147 self->message_handler_destroy_notify(
self->message_handler_data);
153 GObject* where_the_object_was) {
154 FlBinaryMessengerImpl*
self = FL_BINARY_MESSENGER_IMPL(
user_data);
158 g_autoptr(GHashTable) handlers =
self->platform_message_handlers;
159 self->platform_message_handlers = g_hash_table_new_full(
161 g_hash_table_remove_all(handlers);
166 const gchar* channel,
170 FlBinaryMessengerImpl*
self = FL_BINARY_MESSENGER_IMPL(
user_data);
173 g_hash_table_lookup(
self->platform_message_handlers, channel));
174 if (handler ==
nullptr) {
178 g_autoptr(FlBinaryMessengerResponseHandleImpl) handle =
181 FL_BINARY_MESSENGER_RESPONSE_HANDLE(handle),
188 FlBinaryMessengerImpl*
self = FL_BINARY_MESSENGER_IMPL(
object);
191 g_autoptr(FlEngine)
engine = FL_ENGINE(g_weak_ref_get(&
self->engine));
197 g_weak_ref_clear(&
self->engine);
199 g_clear_pointer(&
self->platform_message_handlers, g_hash_table_unref);
201 G_OBJECT_CLASS(fl_binary_messenger_impl_parent_class)->dispose(
object);
205 FlBinaryMessenger* messenger,
206 const gchar* channel,
209 GDestroyNotify destroy_notify) {
210 FlBinaryMessengerImpl*
self = FL_BINARY_MESSENGER_IMPL(messenger);
213 g_autoptr(FlEngine)
engine = FL_ENGINE(g_weak_ref_get(&
self->engine));
215 if (handler !=
nullptr) {
217 "Attempted to set message handler on an FlBinaryMessenger without an "
220 if (destroy_notify !=
nullptr) {
226 if (handler !=
nullptr) {
227 g_hash_table_replace(
228 self->platform_message_handlers, g_strdup(channel),
231 g_hash_table_remove(
self->platform_message_handlers, channel);
236 g_object_unref(
value);
237 return G_SOURCE_REMOVE;
242 FlBinaryMessengerResponseHandle* response_handle_,
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_);
251 g_return_val_if_fail(response_handle->messenger ==
self,
FALSE);
252 g_return_val_if_fail(response_handle->response_handle !=
nullptr,
FALSE);
254 FlEngine*
engine = FL_ENGINE(g_weak_ref_get(&
self->engine));
260 if (response_handle->response_handle ==
nullptr) {
264 "Attempted to respond to a message that is already responded to");
268 engine, response_handle->response_handle, response,
error);
269 response_handle->response_handle =
nullptr;
283 g_task_return_pointer(task,
result, g_object_unref);
287 const gchar* channel,
289 GCancellable* cancellable,
292 FlBinaryMessengerImpl*
self = FL_BINARY_MESSENGER_IMPL(messenger);
294 g_autoptr(FlEngine)
engine = FL_ENGINE(g_weak_ref_get(&
self->engine));
309 FlBinaryMessengerImpl*
self = FL_BINARY_MESSENGER_IMPL(messenger);
312 g_autoptr(GTask) task = G_TASK(
result);
313 GAsyncResult* r = G_ASYNC_RESULT(g_task_propagate_pointer(task,
nullptr));
315 g_autoptr(FlEngine)
engine = FL_ENGINE(g_weak_ref_get(&
self->engine));
329 if (response ==
nullptr) {
341 g_autoptr(GError)
error =
nullptr;
343 g_warning(
"Failed to resize channel: %s",
error->message);
348 const gchar* channel,
366 g_autoptr(GError)
error =
nullptr;
368 g_warning(
"Failed to set warns on channel overflow: %s",
error->message);
373 const gchar* channel,
387 FlBinaryMessengerImplClass* klass) {
392 FlBinaryMessengerInterface* iface) {
402 self->platform_message_handlers = g_hash_table_new_full(
407 g_return_val_if_fail(FL_IS_ENGINE(
engine),
nullptr);
409 FlBinaryMessengerImpl*
self = FL_BINARY_MESSENGER_IMPL(
410 g_object_new(fl_binary_messenger_impl_get_type(),
nullptr));
413 FL_IS_BINARY_MESSENGER_IMPL(
self);
415 g_weak_ref_init(&
self->engine, G_OBJECT(
engine));
421 return FL_BINARY_MESSENGER(
self);
425 FlBinaryMessenger*
self,
426 const gchar* channel,
429 GDestroyNotify destroy_notify) {
430 g_return_if_fail(FL_IS_BINARY_MESSENGER(
self));
431 g_return_if_fail(channel !=
nullptr);
433 FL_BINARY_MESSENGER_GET_IFACE(
self)->set_message_handler_on_channel(
439 FlBinaryMessenger*
self,
440 FlBinaryMessengerResponseHandle* response_handle,
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),
447 return FL_BINARY_MESSENGER_GET_IFACE(
self)->send_response(
452 FlBinaryMessenger*
self,
453 const gchar* channel,
455 GCancellable* cancellable,
458 g_return_if_fail(FL_IS_BINARY_MESSENGER(
self));
459 g_return_if_fail(channel !=
nullptr);
461 FL_BINARY_MESSENGER_GET_IFACE(
self)->send_on_channel(
466 FlBinaryMessenger*
self,
469 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(
self),
FALSE);
471 return FL_BINARY_MESSENGER_GET_IFACE(
self)->send_on_channel_finish(
476 const gchar* channel,
478 g_return_if_fail(FL_IS_BINARY_MESSENGER(
self));
480 return FL_BINARY_MESSENGER_GET_IFACE(
self)->resize_channel(
self, channel,
485 FlBinaryMessenger*
self,
486 const gchar* channel,
488 g_return_if_fail(FL_IS_BINARY_MESSENGER(
self));
490 return FL_BINARY_MESSENGER_GET_IFACE(
self)->set_warns_on_channel_overflow(
491 self, channel, warns);
static void fl_binary_messenger_impl_class_init(FlBinaryMessengerImplClass *klass)
static void resize_channel(FlBinaryMessenger *messenger, const gchar *channel, int64_t new_size)
G_MODULE_EXPORT GBytes * fl_binary_messenger_send_on_channel_finish(FlBinaryMessenger *self, GAsyncResult *result, GError **error)
static void send_on_channel(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
static void fl_binary_messenger_response_handle_impl_dispose(GObject *object)
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) G_DECLARE_FINAL_TYPE(FlBinaryMessengerImpl
static void set_message_handler_on_channel(FlBinaryMessenger *messenger, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
static gboolean fl_binary_messenger_platform_message_cb(FlEngine *engine, const gchar *channel, GBytes *message, const FlutterPlatformMessageResponseHandle *response_handle, void *user_data)
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_message_handler_on_channel(FlBinaryMessenger *self, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
static void engine_weak_notify_cb(gpointer user_data, GObject *where_the_object_was)
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 void fl_binary_messenger_impl_dispose(GObject *object)
static void platform_message_ready_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static void fl_binary_messenger_response_handle_impl_init(FlBinaryMessengerResponseHandleImpl *self)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
static void fl_binary_messenger_impl_init(FlBinaryMessengerImpl *self)
GObject G_DECLARE_FINAL_TYPE(FlBinaryMessengerResponseHandleImpl, fl_binary_messenger_response_handle_impl, FL, BINARY_MESSENGER_RESPONSE_HANDLE_IMPL, FlBinaryMessengerResponseHandle) struct _FlBinaryMessengerImpl
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_set_warns_on_channel_overflow(FlBinaryMessenger *self, const gchar *channel, bool warns)
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 constexpr char kControlChannelName[]
static void fl_binary_messenger_impl_iface_init(FlBinaryMessengerInterface *iface)
static constexpr char kOverflowMethod[]
static void resize_channel_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static gboolean finish_method(GObject *object, GAsyncResult *result, GError **error)
static void set_warns_on_channel_overflow_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static FlBinaryMessengerResponseHandleImpl * fl_binary_messenger_response_handle_impl_new(FlBinaryMessengerImpl *messenger, const FlutterPlatformMessageResponseHandle *response_handle)
static void fl_binary_messenger_response_handle_impl_class_init(FlBinaryMessengerResponseHandleImplClass *klass)
static gboolean do_unref(gpointer value)
static constexpr char kResizeMethod[]
G_DEFINE_TYPE(FlBinaryMessengerResponseHandle, fl_binary_messenger_response_handle, G_TYPE_OBJECT) static void fl_binary_messenger_response_handle_init(FlBinaryMessengerResponseHandle *self)
static PlatformMessageHandler * platform_message_handler_new(FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
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)
static GBytes * send_on_channel_finish(FlBinaryMessenger *messenger, GAsyncResult *result, GError **error)
static void platform_message_handler_free(gpointer data)
G_MODULE_EXPORT GQuark fl_binary_messenger_codec_error_quark(void) G_GNUC_CONST
#define FL_BINARY_MESSENGER_ERROR
@ 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)
G_MODULE_EXPORT fl_binary_messenger_response_handle
void fl_engine_set_platform_message_handler(FlEngine *self, FlEnginePlatformMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
GBytes * fl_engine_send_platform_message_finish(FlEngine *self, GAsyncResult *result, GError **error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
G_DEFINE_INTERFACE(FlKeyboardViewDelegate, fl_keyboard_view_delegate, G_TYPE_OBJECT) static void fl_keyboard_view_delegate_default_init(FlKeyboardViewDelegateInterface *iface)
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
G_MODULE_EXPORT FlValue * fl_value_new_list()
typedefG_BEGIN_DECLS struct _FlValue FlValue
#define FML_DCHECK(condition)
FlBinaryMessengerResponseHandle parent_instance
const FlutterPlatformMessageResponseHandle * response_handle
FlBinaryMessengerImpl * messenger
std::shared_ptr< const fml::Mapping > data