Flutter Engine
fl_binary_messenger.h File Reference
#include <gio/gio.h>
#include <glib-object.h>

Go to the source code of this file.

Macros

#define FL_BINARY_MESSENGER_ERROR   fl_binary_messenger_codec_error_quark()
 

Enumerations

enum  FlBinaryMessengerError { FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED }
 

Functions

GQuark fl_binary_messenger_codec_error_quark (void) G_GNUC_CONST
 
 G_DECLARE_FINAL_TYPE (FlBinaryMessenger, fl_binary_messenger, FL, BINARY_MESSENGER, GObject) G_DECLARE_FINAL_TYPE(FlBinaryMessengerResponseHandle
 
void fl_binary_messenger_set_message_handler_on_channel (FlBinaryMessenger *messenger, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
 
gboolean fl_binary_messenger_send_response (FlBinaryMessenger *messenger, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
 
void fl_binary_messenger_send_on_channel (FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 
GBytes * fl_binary_messenger_send_on_channel_finish (FlBinaryMessenger *messenger, GAsyncResult *result, GError **error)
 

Variables

GObject typedef void(* FlBinaryMessengerMessageHandler )(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
 
 fl_binary_messenger_response_handle
 
 FL
 
 BINARY_MESSENGER_RESPONSE_HANDLE
 

Macro Definition Documentation

◆ FL_BINARY_MESSENGER_ERROR

#define FL_BINARY_MESSENGER_ERROR   fl_binary_messenger_codec_error_quark()

FlBinaryMessengerError: : unable to send response, this message has already been responded to.

Errors for #FlBinaryMessenger objects to set on failures.

Definition at line 24 of file fl_binary_messenger.h.

Referenced by fl_binary_messenger_send_response().

Enumeration Type Documentation

◆ FlBinaryMessengerError

Enumerator
FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED 

Definition at line 26 of file fl_binary_messenger.h.

Function Documentation

◆ fl_binary_messenger_codec_error_quark()

GQuark fl_binary_messenger_codec_error_quark ( void  )

◆ fl_binary_messenger_send_on_channel()

void fl_binary_messenger_send_on_channel ( FlBinaryMessenger *  messenger,
const gchar *  channel,
GBytes *  message,
GCancellable *  cancellable,
GAsyncReadyCallback  callback,
gpointer  user_data 
)

fl_binary_messenger_send_on_channel: : an #FlBinaryMessenger. : channel to send to. : (allow-none): message buffer to send or NULL for an empty message. : (allow-none): a #GCancellable or NULL. : (scope async): a #GAsyncReadyCallback to call when the request is satisfied. : (closure): user data to pass to .

Asynchronously sends a platform message.

Definition at line 238 of file fl_binary_messenger.cc.

References fl_engine_send_platform_message(), and platform_message_ready_cb().

Referenced by fl_basic_message_channel_send(), fl_event_channel_send(), fl_event_channel_send_end_of_stream(), fl_event_channel_send_error(), fl_method_channel_invoke_method(), and TEST().

244  {
245  g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
246  g_return_if_fail(channel != nullptr);
247 
248  if (self->engine == nullptr) {
249  return;
250  }
251 
253  self->engine, channel, message, cancellable,
254  callback != nullptr ? platform_message_ready_cb : nullptr,
255  callback != nullptr ? g_task_new(self, cancellable, callback, user_data)
256  : nullptr);
257 }
G_BEGIN_DECLS FlValue gpointer user_data
void fl_engine_send_platform_message(FlEngine *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:485
static void platform_message_ready_cb(GObject *object, GAsyncResult *result, gpointer user_data)

◆ fl_binary_messenger_send_on_channel_finish()

GBytes* fl_binary_messenger_send_on_channel_finish ( FlBinaryMessenger *  messenger,
GAsyncResult *  result,
GError **  error 
)

fl_binary_messenger_send_on_channel_finish: : an #FlBinaryMessenger.

Returns
: a #GAsyncResult. : (allow-none): #GError location to store the error occurring, or NULL to ignore.

Completes request started with fl_binary_messenger_send_on_channel().

Returns: (transfer full): message response on success or NULL on error.

Definition at line 259 of file fl_binary_messenger.cc.

References fl_engine_send_platform_message_finish().

Referenced by echo_response_cb(), failure_response_cb(), fl_basic_message_channel_send_finish(), fl_method_channel_invoke_method_finish(), and nullptr_response_cb().

262  {
263  g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
264  g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
265 
266  g_autoptr(GTask) task = G_TASK(result);
267  GAsyncResult* r = G_ASYNC_RESULT(g_task_propagate_pointer(task, nullptr));
268 
269  if (self->engine == nullptr) {
270  return nullptr;
271  }
272 
273  return fl_engine_send_platform_message_finish(self->engine, r, error);
274 }
FlMethodResponse GError ** error
GBytes * fl_engine_send_platform_message_finish(FlEngine *self, GAsyncResult *result, GError **error)
Definition: fl_engine.cc:542

◆ fl_binary_messenger_send_response()

gboolean fl_binary_messenger_send_response ( FlBinaryMessenger *  messenger,
FlBinaryMessengerResponseHandle *  response_handle,
GBytes *  response,
GError **  error 
)

fl_binary_messenger_send_response: : an #FlBinaryMessenger. : handle that was provided in a FlBinaryMessengerMessageHandler. : (allow-none): response to send or NULL for an empty response. : (allow-none): #GError location to store the error occurring, or NULL to ignore.

Responds to a platform message.

Returns: TRUE on success.

Definition at line 202 of file fl_binary_messenger.cc.

References FL_BINARY_MESSENGER_ERROR, FL_BINARY_MESSENGER_ERROR_ALREADY_RESPONDED, fl_engine_send_platform_message_response(), and TRUE.

Referenced by cancel_exception_response_cb(), fl_basic_message_channel_respond(), fl_method_channel_respond(), listen_exception_response_cb(), message_cb(), method_call_error_response_cb(), method_call_not_implemented_response_cb(), method_call_success_response_cb(), response_cb(), and send_events_events_cb().

206  {
207  g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
208  g_return_val_if_fail(response_handle != nullptr, FALSE);
209  g_return_val_if_fail(response_handle->messenger == self, FALSE);
210  g_return_val_if_fail(response_handle->response_handle != nullptr, FALSE);
211 
212  if (self->engine == nullptr) {
213  return TRUE;
214  }
215 
216  if (response_handle->response_handle == nullptr) {
217  g_set_error(
220  "Attempted to respond to a message that is already responded to");
221  return FALSE;
222  }
223 
225  self->engine, response_handle->response_handle, response, error);
226  response_handle->response_handle = nullptr;
227 
228  return result;
229 }
FlMethodResponse GError ** error
return TRUE
Definition: fl_view.cc:107
gboolean fl_engine_send_platform_message_response(FlEngine *self, const FlutterPlatformMessageResponseHandle *handle, GBytes *response, GError **error)
Definition: fl_engine.cc:453
#define FL_BINARY_MESSENGER_ERROR

◆ fl_binary_messenger_set_message_handler_on_channel()

void fl_binary_messenger_set_message_handler_on_channel ( FlBinaryMessenger *  messenger,
const gchar *  channel,
FlBinaryMessengerMessageHandler  handler,
gpointer  user_data,
GDestroyNotify  destroy_notify 
)

fl_binary_messenger_set_platform_message_handler: : an #FlBinaryMessenger. : channel to listen on. : (allow-none): function to call when a message is received on this channel or NULL to disable a handler : (closure): user data to pass to . : (allow-none): a function which gets called to free , or NULL.

Sets the function called when a platform message is received on the given channel. See FlBinaryMessengerMessageHandler for details on how to respond to messages.

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

Definition at line 171 of file fl_binary_messenger.cc.

References platform_message_handler_new().

Referenced by fl_basic_message_channel_dispose(), fl_basic_message_channel_new(), fl_event_channel_dispose(), fl_event_channel_new(), fl_method_channel_dispose(), fl_method_channel_new(), and TEST().

176  {
177  g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
178  g_return_if_fail(channel != nullptr);
179 
180  // Don't set handlers if engine already gone.
181  if (self->engine == nullptr) {
182  if (handler != nullptr) {
183  g_warning(
184  "Attempted to set message handler on an FlBinaryMessenger without an "
185  "engine");
186  }
187  if (destroy_notify != nullptr) {
188  destroy_notify(user_data);
189  }
190  return;
191  }
192 
193  if (handler != nullptr) {
194  g_hash_table_replace(
195  self->platform_message_handlers, g_strdup(channel),
196  platform_message_handler_new(handler, user_data, destroy_notify));
197  } else {
198  g_hash_table_remove(self->platform_message_handlers, channel);
199  }
200 }
static PlatformMessageHandler * platform_message_handler_new(FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_BEGIN_DECLS FlValue gpointer user_data

◆ G_DECLARE_FINAL_TYPE()

G_DECLARE_FINAL_TYPE ( FlBinaryMessenger  ,
fl_binary_messenger  ,
FL  ,
BINARY_MESSENGER  ,
GObject   
)

Variable Documentation

◆ BINARY_MESSENGER_RESPONSE_HANDLE

BINARY_MESSENGER_RESPONSE_HANDLE

Definition at line 39 of file fl_binary_messenger.h.

◆ FL

FL

Definition at line 39 of file fl_binary_messenger.h.

◆ fl_binary_messenger_response_handle

fl_binary_messenger_response_handle

Definition at line 39 of file fl_binary_messenger.h.

◆ FlBinaryMessengerMessageHandler

GObject typedef void(* FlBinaryMessengerMessageHandler) (FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)

FlBinaryMessenger:

#FlBinaryMessenger is an object that allows sending and receiving of platform messages with an #FlEngine. FlBinaryMessengerResponseHandle:

#FlBinaryMessengerResponseHandle is an object used to send responses with. FlBinaryMessengerMessageHandler: : an #FlBinaryMessenger. : channel message received on. : message content received from Dart. : a handle to respond to the message with. : (closure): data provided when registering this handler.

Function called when platform messages are received. Call fl_binary_messenger_send_response() to respond to this message. If the response is not occurring in this callback take a reference to and release that once it has been responded to. Failing to respond before the last reference to is dropped is a programming error.

Definition at line 72 of file fl_binary_messenger.h.