Flutter Engine
fl_event_channel.h File Reference
#include <gio/gio.h>
#include <glib-object.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_DECLARE_FINAL_TYPE (FlEventChannel, fl_event_channel, FL, EVENT_CHANNEL, GObject) typedef FlMethodErrorResponse *(*FlEventChannelHandler)(FlEventChannel *channel
 
: a channel name.

fl_event_channel_new: : an #FlBinaryMessenger.

: the message codec.

Creates an event channel. 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 FlValueargs
 
G_BEGIN_DECLS 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 158 of file fl_event_channel.cc.

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

Referenced by TEST().

161  {
162  g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
163  g_return_val_if_fail(name != nullptr, nullptr);
164  g_return_val_if_fail(FL_IS_METHOD_CODEC(codec), nullptr);
165 
166  FlEventChannel* self =
167  FL_EVENT_CHANNEL(g_object_new(fl_event_channel_get_type(), nullptr));
168 
169  self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
170  self->name = g_strdup(name);
171  self->codec = FL_METHOD_CODEC(g_object_ref(codec));
172 
174  self->messenger, self->name, message_cb, g_object_ref(self),
176 
177  return self;
178 }
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 channel_closed_cb(gpointer user_data)
G_MODULE_EXPORT GType fl_event_channel_get_type()
static void message_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
const char * name
Definition: fuchsia.cc:50

◆ fl_event_channel_send()

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

fl_event_channel_send: : an #FlEventChannel. : event to send, must match what the #FlMethodCodec supports. : (allow-none): a #GCancellable or NULL. : (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 195 of file fl_event_channel.cc.

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

Referenced by send_events_listen_cb().

198  {
199  g_return_val_if_fail(FL_IS_EVENT_CHANNEL(self), FALSE);
200  g_return_val_if_fail(event != nullptr, FALSE);
201 
202  g_autoptr(GBytes) data =
204  if (data == nullptr) {
205  return FALSE;
206  }
207 
208  fl_binary_messenger_send_on_channel(self->messenger, self->name, data,
209  cancellable, nullptr, nullptr);
210 
211  return TRUE;
212 }
FlMethodResponse 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)
GdkEventButton * event
Definition: fl_view.cc:62
return TRUE
Definition: fl_view.cc:107
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)

◆ 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: : an #FlEventChannel. : (allow-none): function to call when the Dart side of the channel starts listening to the stream. : (allow-none): function to call when the Dart side of the channel cancels their subscription to the stream. : (closure): user data to pass to and . : (allow-none): a function which gets called to free , 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 if you want to detect this.

Definition at line 180 of file fl_event_channel.cc.

References _FlEventChannel::cancel_handler, _FlEventChannel::listen_handler, remove_handlers(), and user_data.

Referenced by TEST().

185  {
186  g_return_if_fail(FL_IS_EVENT_CHANNEL(self));
187 
188  remove_handlers(self);
189  self->listen_handler = listen_handler;
190  self->cancel_handler = cancel_handler;
191  self->handler_data = user_data;
192  self->handler_data_destroy_notify = destroy_notify;
193 }
static void remove_handlers(FlEventChannel *self)
G_BEGIN_DECLS FlValue gpointer user_data

◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS 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: : an #FlEventChannel. : arguments passed from the Dart end of the channel. : (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 FlValue* args

Definition at line 87 of file fl_event_channel.h.

Referenced by fml::jni::AttachCurrentThread(), flutter::PlatformConfiguration::client(), clipboard_get_data_async(), decode_error_method_call(), flutter::Engine::DispatchPlatformMessage(), flutter_runner::PlatformView::DispatchSemanticsAction(), fl_engine_start(), fl_json_method_codec_decode_response(), FlutterEngineUpdateLocales(), flutter::testing::AutoIsolateShutdown::get(), flutter::Shell::GetDartVM(), flutter::FlutterMain::GetSettings(), flutter::DartVM::GetVMLaunchCount(), FlutterTextInputPlugin::handleMethodCall:result:, FlutterPlatformPlugin::handleMethodCall:result:, fml::HashCombine(), flutter::testing::EmbedderConfigBuilder::InitializeEngine(), TextPlatformView::initWithFrame:viewIdentifier:arguments:binaryMessenger:, TextPlatformViewFactory::initWithMessenger:, flutter::TextInputPlugin::KeyboardHook(), flutter_runner::MakeLocalizationPlatformMessageData(), fml::internal::MakeRefCountedHelper< T >::MakeRefCounted(), fml::MakeRefCounted(), message_cb(), method_call_cb(), SemanticsObject::onCustomAccessibilityAction:, flutter::FlutterPlatformViewsController::OnMethodCall, fml::internal::CopyableLambda< T >::operator()(), perform_action(), flutter_runner::PlatformView::PlatformView(), flutter::testing::RunDartCodeInIsolateOnUITaskRunner(), RunFlutter(), RunFlutterEngine(), flutter::FlutterWindowsEngine::RunWithEntrypoint(), fml::tracing::SplitArguments(), fml::tracing::SplitArgumentsCollect(), flutter::testing::TEST(), TEST(), flutter::testing::TEST_F(), flutter::testing::TestSimulatedInputEvents(), flutter::TextInputPlugin::TextInputPlugin(), fml::tracing::TraceCounter(), fml::tracing::TraceEvent(), fml::tracing::TraceEventAsyncComplete(), update_editing_state(), and _FlutterTaskRunner::~_FlutterTaskRunner().

◆ user_data

G_BEGIN_DECLS FlValue gpointer user_data

Definition at line 87 of file fl_event_channel.h.

Referenced by cancel_exception_response_cb(), flutter::testing::EmbedderTestBackingStoreProducer::Create(), CreateEmbedderRenderTarget(), flutter::CreateEmbedderTaskRunner(), flutter::testing::EmbedderTestTaskRunner::EmbedderTestTaskRunner(), flutter::enableSkiaTracingCallback(), engine_weak_notify_cb(), EngineClearContext(), EngineMakeContextCurrent(), EngineMakeResourceContextCurrent(), EngineOnFlutterPlatformMessage(), EnginePresent(), fl_basic_message_channel_set_message_handler(), fl_engine_gl_clear_current(), fl_engine_gl_get_fbo(), fl_engine_gl_make_current(), fl_engine_gl_make_resource_current(), fl_engine_gl_present(), fl_engine_gl_proc_resolver(), fl_engine_post_task(), fl_engine_runs_task_on_current_thread(), fl_engine_set_platform_message_handler(), fl_event_channel_set_stream_handlers(), fl_method_channel_set_method_call_handler(), FlutterEngineInitialize(), FlutterEnginePostDartObject(), FlutterPlatformMessageCreateResponseHandle(), flutter::testing::EmbedderTestContext::GetIsolateCreateCallbackHook(), flutter::testing::EmbedderTestContext::GetUpdateSemanticsCustomActionCallbackHook(), flutter::testing::EmbedderTestContext::GetUpdateSemanticsNodeCallbackHook(), InferExternalViewEmbedderFromArgs(), InferOpenGLPlatformViewCreationCallback(), InferSoftwarePlatformViewCreationCallback(), MakeSkSurfaceFromBackingStore(), flutter::Win32WindowProcDelegateManager::OnTopLevelWindowProc(), platform_message_handler_new(), flutter::Win32WindowProcDelegateManager::RegisterTopLevelWindowProcDelegate(), flutter::FlutterWindowsEngine::RunWithEntrypoint(), flutter::BinaryMessengerImpl::Send(), send_events_events_cb(), flutter::testing::EmbedderConfigBuilder::SetCompositor(), FlutterEngine::shutDownEngine, flutter::testing::TEST(), flutter::testing::TEST_F(), flutter::PluginRegistrarWindows::UnregisterTopLevelWindowProcDelegate(), flutter::FlutterWindowsEngine::window_proc_delegate_manager(), and flutter::WriteServerErrorResponse().