Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
fl_event_channel.cc File Reference
#include "flutter/shell/platform/linux/public/flutter_linux/fl_event_channel.h"
#include <gmodule.h>
#include "flutter/shell/platform/linux/fl_method_codec_private.h"

Go to the source code of this file.

Classes

struct  _FlEventChannel
 
struct  _FlEventChannelResponseHandle
 

Functions

static FlMethodErrorResponse * handle_method_call (FlEventChannel *self, const gchar *name, FlValue *args)
 
static void message_cb (FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
 
static void remove_handlers (FlEventChannel *self)
 
static void channel_closed_cb (gpointer user_data)
 
static void fl_event_channel_dispose (GObject *object)
 
static void fl_event_channel_class_init (FlEventChannelClass *klass)
 
static void fl_event_channel_init (FlEventChannel *self)
 
G_MODULE_EXPORT FlEventChannel * fl_event_channel_new (FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
 
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 gboolean fl_event_channel_send (FlEventChannel *self, FlValue *event, 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)
 
G_MODULE_EXPORT gboolean fl_event_channel_send_end_of_stream (FlEventChannel *self, GCancellable *cancellable, GError **error)
 

Variables

static constexpr char kListenMethod [] = "listen"
 
static constexpr char kCancelMethod [] = "cancel"
 
static constexpr char kEventRequestError [] = "error"
 

Function Documentation

◆ channel_closed_cb()

static void channel_closed_cb ( gpointer  user_data)
static

Definition at line 130 of file fl_event_channel.cc.

130 {
131 g_autoptr(FlEventChannel) self = FL_EVENT_CHANNEL(user_data);
132 self->channel_closed = TRUE;
134}
static void remove_handlers(FlEventChannel *self)

◆ fl_event_channel_class_init()

static void fl_event_channel_class_init ( FlEventChannelClass *  klass)
static

Definition at line 153 of file fl_event_channel.cc.

153 {
154 G_OBJECT_CLASS(klass)->dispose = fl_event_channel_dispose;
155}
static void fl_event_channel_dispose(GObject *object)

◆ fl_event_channel_dispose()

static void fl_event_channel_dispose ( GObject *  object)
static

Definition at line 136 of file fl_event_channel.cc.

136 {
137 FlEventChannel* self = FL_EVENT_CHANNEL(object);
138
139 if (!self->channel_closed) {
141 self->messenger, self->name, nullptr, nullptr, nullptr);
142 }
143
144 g_clear_object(&self->messenger);
145 g_clear_pointer(&self->name, g_free);
146 g_clear_object(&self->codec);
147
149
150 G_OBJECT_CLASS(fl_event_channel_parent_class)->dispose(object);
151}
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)

◆ fl_event_channel_init()

static void fl_event_channel_init ( FlEventChannel *  self)
static

Definition at line 157 of file fl_event_channel.cc.

157{}

◆ fl_event_channel_new()

G_MODULE_EXPORT 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
175 self->messenger, self->name, message_cb, g_object_ref(self),
177
178 return self;
179}
static void message_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
static void channel_closed_cb(gpointer user_data)
const char * name
Definition fuchsia.cc:50

◆ fl_event_channel_send()

G_MODULE_EXPORT 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 =
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}
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlKeyEvent * event
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
const uint8_t uint32_t uint32_t GError ** error
return FALSE
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ fl_event_channel_send_end_of_stream()

G_MODULE_EXPORT gboolean fl_event_channel_send_end_of_stream ( FlEventChannel *  self,
GCancellable *  cancellable,
GError **  error 
)

Definition at line 237 of file fl_event_channel.cc.

240 {
241 g_return_val_if_fail(FL_IS_EVENT_CHANNEL(self), FALSE);
242 fl_binary_messenger_send_on_channel(self->messenger, self->name, nullptr,
243 cancellable, nullptr, nullptr);
244 return TRUE;
245}

◆ fl_event_channel_send_error()

G_MODULE_EXPORT gboolean fl_event_channel_send_error ( FlEventChannel *  self,
const gchar *  code,
const gchar *  message,
FlValue details,
GCancellable *  cancellable,
GError **  error 
)

Definition at line 215 of file fl_event_channel.cc.

220 {
221 g_return_val_if_fail(FL_IS_EVENT_CHANNEL(self), FALSE);
222 g_return_val_if_fail(code != nullptr, FALSE);
223 g_return_val_if_fail(message != nullptr, FALSE);
224
226 self->codec, code, message, details, error);
227 if (data == nullptr) {
228 return FALSE;
229 }
230
231 fl_binary_messenger_send_on_channel(self->messenger, self->name, data,
232 cancellable, nullptr, nullptr);
233
234 return TRUE;
235}
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
Win32Message message

◆ fl_event_channel_set_stream_handlers()

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

◆ handle_method_call()

static FlMethodErrorResponse * handle_method_call ( FlEventChannel *  self,
const gchar *  name,
FlValue args 
)
static

Definition at line 46 of file fl_event_channel.cc.

48 {
49 FlEventChannelHandler handler;
50 if (g_strcmp0(name, kListenMethod) == 0) {
51 handler = self->listen_handler;
52 } else if (g_strcmp0(name, kCancelMethod) == 0) {
53 handler = self->cancel_handler;
54 } else {
55 g_autofree gchar* message =
56 g_strdup_printf("Unknown event channel request '%s'", name);
58 }
59
60 // If not handled, just accept requests.
61 if (handler == nullptr) {
62 return nullptr;
63 }
64
65 return handler(self, args, self->handler_data);
66}
static constexpr char kListenMethod[]
static constexpr char kEventRequestError[]
static constexpr char kCancelMethod[]
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)

◆ message_cb()

static void message_cb ( FlBinaryMessenger *  messenger,
const gchar *  channel,
GBytes *  message,
FlBinaryMessengerResponseHandle *  response_handle,
gpointer  user_data 
)
static

Definition at line 69 of file fl_event_channel.cc.

73 {
74 FlEventChannel* self = FL_EVENT_CHANNEL(user_data);
75
76 g_autofree gchar* name = nullptr;
77 g_autoptr(GError) error = nullptr;
78 g_autoptr(FlValue) args = nullptr;
80 &error)) {
81 g_warning("Failed to decode message on event channel %s: %s", self->name,
82 error->message);
83 fl_binary_messenger_send_response(messenger, response_handle, nullptr,
84 nullptr);
85 return;
86 }
87
88 g_autoptr(FlMethodErrorResponse) response =
90
91 g_autoptr(GBytes) data = nullptr;
92 if (response == nullptr) {
93 g_autoptr(GError) codec_error = nullptr;
95 &codec_error);
96 if (data == nullptr) {
97 g_warning("Failed to encode event channel %s success response: %s",
98 self->name, codec_error->message);
99 }
100 } else {
101 g_autoptr(GError) codec_error = nullptr;
103 self->codec, fl_method_error_response_get_code(response),
105 fl_method_error_response_get_details(response), &codec_error);
106 if (data == nullptr) {
107 g_warning("Failed to encode event channel %s error response: %s",
108 self->name, codec_error->message);
109 }
110 }
111
112 if (!fl_binary_messenger_send_response(messenger, response_handle, data,
113 &error)) {
114 g_warning("Failed to send event channel response: %s", error->message);
115 }
116}
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
static FlMethodErrorResponse * handle_method_call(FlEventChannel *self, const gchar *name, FlValue *args)
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
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)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42

◆ remove_handlers()

static void remove_handlers ( FlEventChannel *  self)
static

Definition at line 119 of file fl_event_channel.cc.

119 {
120 if (self->handler_data_destroy_notify != nullptr) {
121 self->handler_data_destroy_notify(self->handler_data);
122 }
123 self->listen_handler = nullptr;
124 self->cancel_handler = nullptr;
125 self->handler_data = nullptr;
126 self->handler_data_destroy_notify = nullptr;
127}

Variable Documentation

◆ kCancelMethod

constexpr char kCancelMethod[] = "cancel"
staticconstexpr

Definition at line 12 of file fl_event_channel.cc.

◆ kEventRequestError

constexpr char kEventRequestError[] = "error"
staticconstexpr

Definition at line 13 of file fl_event_channel.cc.

◆ kListenMethod

constexpr char kListenMethod[] = "listen"
staticconstexpr

Definition at line 11 of file fl_event_channel.cc.