5#include "flutter/shell/platform/linux/public/flutter_linux/fl_event_channel.h"
9#include "flutter/shell/platform/linux/fl_method_codec_private.h"
49 FlEventChannelHandler handler;
51 handler =
self->listen_handler;
53 handler =
self->cancel_handler;
56 g_strdup_printf(
"Unknown event channel request '%s'",
name);
61 if (handler ==
nullptr) {
72 FlBinaryMessengerResponseHandle* response_handle,
76 g_autofree gchar*
name =
nullptr;
77 g_autoptr(GError)
error =
nullptr;
81 g_warning(
"Failed to decode message on event channel %s: %s",
self->name,
88 g_autoptr(FlMethodErrorResponse) response =
91 g_autoptr(GBytes)
data =
nullptr;
92 if (response ==
nullptr) {
93 g_autoptr(GError) codec_error =
nullptr;
96 if (
data ==
nullptr) {
97 g_warning(
"Failed to encode event channel %s success response: %s",
98 self->name, codec_error->message);
101 g_autoptr(GError) codec_error =
nullptr;
106 if (
data ==
nullptr) {
107 g_warning(
"Failed to encode event channel %s error response: %s",
108 self->name, codec_error->message);
114 g_warning(
"Failed to send event channel response: %s",
error->message);
120 if (
self->handler_data_destroy_notify !=
nullptr) {
121 self->handler_data_destroy_notify(
self->handler_data);
123 self->listen_handler =
nullptr;
124 self->cancel_handler =
nullptr;
125 self->handler_data =
nullptr;
126 self->handler_data_destroy_notify =
nullptr;
131 g_autoptr(FlEventChannel)
self = FL_EVENT_CHANNEL(
user_data);
137 FlEventChannel*
self = FL_EVENT_CHANNEL(
object);
139 if (!
self->channel_closed) {
141 self->messenger,
self->name,
nullptr,
nullptr,
nullptr);
144 g_clear_object(&
self->messenger);
145 g_clear_pointer(&
self->name, g_free);
146 g_clear_object(&
self->codec);
150 G_OBJECT_CLASS(fl_event_channel_parent_class)->dispose(
object);
160 FlBinaryMessenger* messenger,
162 FlMethodCodec* codec) {
163 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger),
nullptr);
164 g_return_val_if_fail(
name !=
nullptr,
nullptr);
165 g_return_val_if_fail(FL_IS_METHOD_CODEC(codec),
nullptr);
167 FlEventChannel*
self =
168 FL_EVENT_CHANNEL(g_object_new(fl_event_channel_get_type(),
nullptr));
170 self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
172 self->codec = FL_METHOD_CODEC(g_object_ref(codec));
182 FlEventChannel*
self,
183 FlEventChannelHandler listen_handler,
184 FlEventChannelHandler cancel_handler,
186 GDestroyNotify destroy_notify) {
187 g_return_if_fail(FL_IS_EVENT_CHANNEL(
self));
190 self->listen_handler = listen_handler;
191 self->cancel_handler = cancel_handler;
193 self->handler_data_destroy_notify = destroy_notify;
198 GCancellable* cancellable,
200 g_return_val_if_fail(FL_IS_EVENT_CHANNEL(
self),
FALSE);
201 g_return_val_if_fail(
event !=
nullptr,
FALSE);
203 g_autoptr(GBytes)
data =
205 if (
data ==
nullptr) {
210 cancellable,
nullptr,
nullptr);
219 GCancellable* cancellable,
221 g_return_val_if_fail(FL_IS_EVENT_CHANNEL(
self),
FALSE);
222 g_return_val_if_fail(
code !=
nullptr,
FALSE);
227 if (
data ==
nullptr) {
232 cancellable,
nullptr,
nullptr);
238 FlEventChannel*
self,
239 GCancellable* cancellable,
241 g_return_val_if_fail(FL_IS_EVENT_CHANNEL(
self),
FALSE);
243 cancellable,
nullptr,
nullptr);
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
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 void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
G_MODULE_EXPORT gboolean fl_event_channel_send(FlEventChannel *self, FlValue *event, GCancellable *cancellable, GError **error)
static void message_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
G_MODULE_EXPORT gboolean fl_event_channel_send_end_of_stream(FlEventChannel *self, GCancellable *cancellable, GError **error)
G_MODULE_EXPORT gboolean fl_event_channel_send_error(FlEventChannel *self, const gchar *code, const gchar *message, FlValue *details, GCancellable *cancellable, GError **error)
static void fl_event_channel_dispose(GObject *object)
static void fl_event_channel_class_init(FlEventChannelClass *klass)
static constexpr char kListenMethod[]
G_MODULE_EXPORT void fl_event_channel_set_stream_handlers(FlEventChannel *self, FlEventChannelHandler listen_handler, FlEventChannelHandler cancel_handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT FlEventChannel * fl_event_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
static void fl_event_channel_init(FlEventChannel *self)
static constexpr char kEventRequestError[]
static FlMethodErrorResponse * handle_method_call(FlEventChannel *self, const gchar *name, FlValue *args)
static void remove_handlers(FlEventChannel *self)
static void channel_closed_cb(gpointer user_data)
static constexpr char kCancelMethod[]
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
const uint8_t uint32_t uint32_t GError ** error
typedefG_BEGIN_DECLS struct _FlValue FlValue
DEF_SWITCHES_START aot vmservice shared library name
FlBinaryMessengerResponseHandle * response_handle
GDestroyNotify handler_data_destroy_notify
FlEventChannelHandler cancel_handler
FlBinaryMessenger * messenger
FlEventChannelHandler listen_handler
std::shared_ptr< const fml::Mapping > data