| Flutter Linux Embedder |

Functions | Variables
fl_event_channel.h File Reference
`#include <gio/gio.h>`
`#include <glib-object.h>`
`#include <gmodule.h>`
`#include "fl_binary_messenger.h"`
`#include "fl_method_channel.h"`
`#include "fl_method_response.h"`

Go to the source code of this file.

## Functions
G_BEGIN_DECLS G_MODULE_EXPORT | G_DECLARE_FINAL_TYPE (FlEventChannel, fl_event_channel, FL, EVENT_CHANNEL, GObject) typedef FlMethodErrorResponse *(*FlEventChannelHandler)(FlEventChannel *channel
: a channel name.
fl_event_channel_new: @messenger: an #FlBinaryMessenger. @codec: the message codec. Creates an event channel. @codec must match the codec used on the Dart end of the channel. Returns: a new #FlEventChannel.
FlEventChannel * | fl_event_channel_new (FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
void | fl_event_channel_set_stream_handlers (FlEventChannel *channel, FlEventChannelHandler listen_handler, FlEventChannelHandler cancel_handler, gpointer user_data, GDestroyNotify destroy_notify)
gboolean | fl_event_channel_send (FlEventChannel *channel, FlValue *event, GCancellable *cancellable, GError **error)

## Variables
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * | args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer | user_data

## Function Documentation

## ◆ fl_event_channel_new()

FlEventChannel* fl_event_channel_new | ( | FlBinaryMessenger * | messenger,
|  | const gchar * | name,
|  | FlMethodCodec * | codec
| ) |  |

Definition at line 159 of file fl_event_channel.cc.

162 {
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);
166
167 FlEventChannel* self =
168 FL_EVENT_CHANNEL(g_object_new(fl_event_channel_get_type(), nullptr));
169
170 self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
171 self->name = g_strdup(name);
172 self->codec = FL_METHOD_CODEC(g_object_ref(codec));
173
174 fl_binary_messenger_set_message_handler_on_channel(
175 self->messenger, self->name, message_cb, g_object_ref(self),
176 channel_closed_cb);
177
178 return self;
179 }
fl_binary_messenger_set_message_handler_on_channel
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)
Definition: fl_binary_messenger.cc:408
message_cb
static void message_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
Definition: fl_event_channel.cc:69
channel_closed_cb
static void channel_closed_cb(gpointer user_data)
Definition: fl_event_channel.cc:130

References channel_closed_cb(), fl_binary_messenger_set_message_handler_on_channel(), and message_cb().

Referenced by TEST().

## ◆ fl_event_channel_send()

gboolean fl_event_channel_send | ( | FlEventChannel * | channel,
|  | FlValue * | event,
|  | GCancellable * | cancellable,
|  | GError ** | error
| ) |  |

fl_event_channel_send: @channel: an #FlEventChannel. @event: event to send, must match what the #FlMethodCodec supports. @cancellable: (allow-none): a #GCancellable or NULL. @error: (allow-none): #GError location to store the error occurring, or NULL to ignore.

Sends an event on the channel. Events should only be sent once the channel is being listened to.

Returns: TRUE if successful.

Definition at line 196 of file fl_event_channel.cc.

199 {
200 g_return_val_if_fail(FL_IS_EVENT_CHANNEL(self), FALSE);
201 g_return_val_if_fail(event != nullptr, FALSE);
202
203 g_autoptr(GBytes) data =
204 fl_method_codec_encode_success_envelope(self->codec, event, error);
205 if (data == nullptr) {
206 return FALSE;
207 }
208
209 fl_binary_messenger_send_on_channel(self->messenger, self->name, data,
210 cancellable, nullptr, nullptr);
211
212 return TRUE;
213 }
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
g_autoptr
g_autoptr(GMutexLocker) locker
TRUE
return TRUE
Definition: fl_compositor_software.cc:68
fl_method_codec_encode_success_envelope
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
Definition: fl_method_codec.cc:41
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40

References error, fl_binary_messenger_send_on_channel(), fl_method_codec_encode_success_envelope(), g_autoptr(), and TRUE.

Referenced by TEST().

## ◆ fl_event_channel_set_stream_handlers()

void fl_event_channel_set_stream_handlers | ( | FlEventChannel * | channel,
|  | FlEventChannelHandler | listen_handler,
|  | FlEventChannelHandler | cancel_handler,
|  | gpointer | user_data,
|  | GDestroyNotify | destroy_notify
| ) |  |

fl_event_channel_set_stream_handlers: @channel: an #FlEventChannel. @listen_handler: (allow-none): function to call when the Dart side of the channel starts listening to the stream. @cancel_handler: (allow-none): function to call when the Dart side of the channel cancels their subscription to the stream. @user_data: (closure): user data to pass to @listen_handler and @cancel_handler. @destroy_notify: (allow-none): a function which gets called to free @user_data, or NULL.

Sets the functions called when the Dart side requests the stream to start and finish.

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

Definition at line 181 of file fl_event_channel.cc.

186 {
187 g_return_if_fail(FL_IS_EVENT_CHANNEL(self));
188
189 remove_handlers(self);
190 self->listen_handler = listen_handler;
191 self->cancel_handler = cancel_handler;
192 self->handler_data = user_data;
193 self->handler_data_destroy_notify = destroy_notify;
194 }
remove_handlers
static void remove_handlers(FlEventChannel *self)
Definition: fl_event_channel.cc:119
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90

References remove_handlers(), and user_data.

Referenced by TEST().

## ◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_MODULE_EXPORT G_DECLARE_FINAL_TYPE | ( | FlEventChannel | ,
|  | fl_event_channel | ,
|  | FL | ,
|  | EVENT_CHANNEL | ,
|  | GObject |
| ) |  |

FlEventChannel:

#FlEventChannel is an object that allows sending an events stream to Dart code over platform channels.

The following example shows how to send events on a channel:

|[ static FlEventChannel *channel = NULL; static gboolean send_events = FALSE;

static void event_occurs_cb (FooEvent *event) { if (send_events) { g_autoptr(FlValue) message = foo_event_to_value (event); g_autoptr(GError) error = NULL; if (!fl_event_channel_send (channel, message, NULL, &error)) { g_warning ("Failed to send event: %s", error->message); } } }

static FlMethodErrorResponse* listen_cb (FlEventChannel* channel, FlValue *args, gpointer user_data) { send_events = TRUE; return NULL; }

static FlMethodErrorResponse* cancel_cb (GObject *object, FlValue *args, gpointer user_data) { send_events = FALSE; return NULL; }

static void setup_channel () { g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new (); channel = fl_event_channel_new (messenger, "flutter/foo", FL_METHOD_CODEC (codec)); fl_event_channel_set_stream_handlers (channel, listen_cb, cancel_cb, NULL, NULL); } ]|

#FlEventChannel matches the EventChannel class in the Flutter services library. FlEventChannelHandler: @channel: an #FlEventChannel. @args: arguments passed from the Dart end of the channel. @user_data: (closure): data provided when registering this handler.

Function called when the stream is listened to or cancelled.

Returns: (transfer full): an #FlMethodErrorResponse or NULL if no error.

## Variable Documentation

## ◆ args

G_BEGIN_DECLS G_MODULE_EXPORT FlValue* args

Definition at line 89 of file fl_event_channel.h.

Referenced by activate_system_cursor(), build_list(), build_map(), clipboard_get_data(), clipboard_set_data(), create_regular(), decode_error_method_call(), decode_method_call(), destroy_window(), encode_method_call(), fl_engine_start(), fl_json_method_codec_decode_method_call(), fl_json_method_codec_decode_response(), fl_json_method_codec_encode_method_call(), fl_method_call_new(), fl_method_channel_invoke_method(), fl_method_codec_decode_method_call(), fl_method_codec_encode_method_call(), fl_platform_channel_system_request_app_exit(), fl_standard_method_codec_decode_method_call(), fl_standard_method_codec_encode_method_call(), fl_test_application_activate(), fl_test_codec_decode_method_call(), fl_test_codec_encode_method_call(), fl_text_input_channel_perform_action(), fl_text_input_channel_update_editing_state(), fl_text_input_channel_update_editing_state_with_deltas(), handle_method_call(), make_create_regular_args(), make_destroy_window_args(), make_modify_regular_args(), message_cb(), method_call_cb(), modify_regular(), resize_channel(), set_client(), set_editable_size_and_transform(), set_editing_state(), set_marked_text_rect(), set_size_arg(), set_warns_on_channel_overflow(), system_exit_application(), system_sound_play(), TEST(), test_method_codec_decode_method_call(), and test_method_codec_encode_method_call().

## ◆ user_data

G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data

Definition at line 90 of file fl_event_channel.h.

Referenced by activate_system_cursor(), add_view_cb(), add_view_engine_error_cb(), add_view_error_cb(), channel_closed_cb(), clear_client(), clipboard_text_cb(), clipboard_text_has_strings_cb(), compositor_collect_backing_store_callback(), compositor_create_backing_store_callback(), create_regular(), destroy_window(), fl_basic_message_channel_send(), fl_basic_message_channel_set_message_handler(), fl_binary_messenger_platform_message_cb(), fl_binary_messenger_send_on_channel(), fl_binary_messenger_set_message_handler_on_channel(), fl_engine_add_view(), fl_engine_gl_clear_current(), fl_engine_gl_external_texture_frame_callback(), fl_engine_gl_make_current(), fl_engine_gl_make_resource_current(), fl_engine_on_pre_engine_restart_cb(), fl_engine_platform_message_cb(), fl_engine_platform_message_response_cb(), fl_engine_post_task(), fl_engine_remove_view(), fl_engine_runs_task_on_current_thread(), fl_engine_send_key_event(), fl_engine_send_platform_message(), fl_engine_set_platform_message_handler(), fl_engine_start(), fl_engine_update_semantics_cb(), fl_event_channel_set_stream_handlers(), fl_key_channel_responder_handle_event(), fl_key_embedder_call_record_new(), fl_key_embedder_responder_handle_event(), fl_key_embedder_responder_handle_event_impl(), fl_key_event_channel_send(), fl_keyboard_channel_new(), fl_keyboard_manager_handle_event(), fl_keyboard_manager_set_lookup_key_handler(), fl_method_channel_invoke_method(), fl_method_channel_set_method_call_handler(), fl_mouse_cursor_channel_new(), fl_platform_channel_new(), fl_platform_channel_system_request_app_exit(), fl_test_application_activate(), fl_text_input_channel_new(), fl_text_input_channel_perform_action(), fl_text_input_channel_update_editing_state(), fl_text_input_channel_update_editing_state_with_deltas(), fl_view_accessible_handle_update_semantics(), fl_windowing_channel_new(), G_DEFINE_TYPE_WITH_CODE(), get_keyboard_state(), handle_key_event(), handle_response(), hash_table_find_equal_value(), hide(), message_cb(), message_response_cb(), method_call_cb(), modify_regular(), on_pre_engine_restart_cb(), platform_message_handler_new(), platform_message_ready_cb(), flutter::TextureRegistrarImpl::RegisterTexture(), remove_view_cb(), remove_view_engine_error_cb(), remove_view_error_cb(), request_app_exit_response_cb(), responder_handle_channel_event_cb(), responder_handle_embedder_event_cb(), flutter::BinaryMessengerImpl::Send(), send_key_event_cb(), send_on_channel(), set_client(), set_editable_size_and_transform(), set_editing_state(), set_key_event_channel(), set_marked_text_rect(), set_message_handler_on_channel(), flutter::IncomingMessageDispatcher::SetMessageCallback(), settings_portal_changed_cb(), show(), system_exit_application(), system_initialization_complete(), TEST(), flutter::TEST(), test_lock_event(), and view_added_cb().