#include <gio/gio.h>
#include <glib-object.h>
#include <gmodule.h>
#include "fl_binary_messenger.h"
#include "fl_method_call.h"
#include "fl_method_codec.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 (FlMethodChannel, fl_method_channel, FL, METHOD_CHANNEL, GObject) typedef void(*FlMethodChannelMethodCallHandler)(FlMethodChannel *channel |
: a channel name. | |
fl_method_channel_new: @messenger: an #FlBinaryMessenger. @codec: the method codec. Creates a new method channel. @codec must match the codec used on the Dart end of the channel. Returns: a new #FlMethodChannel. | |
FlMethodChannel * | fl_method_channel_new (FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec) |
void | fl_method_channel_set_method_call_handler (FlMethodChannel *channel, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify) |
void | fl_method_channel_invoke_method (FlMethodChannel *channel, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) |
FlMethodResponse * | fl_method_channel_invoke_method_finish (FlMethodChannel *channel, GAsyncResult *result, GError **error) |
Variables | |
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * | method_call |
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall gpointer | user_data |
void fl_method_channel_invoke_method | ( | FlMethodChannel * | channel, |
const gchar * | method, | ||
FlValue * | args, | ||
GCancellable * | cancellable, | ||
GAsyncReadyCallback | callback, | ||
gpointer | user_data | ||
) |
fl_method_channel_invoke_method: @channel: an #FlMethodChannel. @method: the method to call. @args: (allow-none): arguments to the method, must match what the #FlMethodCodec supports. @cancellable: (allow-none): a #GCancellable or NULL. @callback: (scope async): (allow-none): a #GAsyncReadyCallback to call when the request is satisfied or NULL to ignore the response. @user_data: (closure): user data to pass to @callback.
Calls a method on this channel.
Definition at line 162 of file fl_method_channel.cc.
References args, callback, error, fl_binary_messenger_send_on_channel(), fl_method_codec_encode_method_call(), message_response_cb(), and user_data.
Referenced by cancel_channel(), listen_channel(), perform_action(), request_app_exit(), TEST(), update_editing_state(), and update_editing_state_with_delta().
FlMethodResponse* fl_method_channel_invoke_method_finish | ( | FlMethodChannel * | channel, |
GAsyncResult * | result, | ||
GError ** | error | ||
) |
fl_method_channel_invoke_method_finish: @channel: an #FlMethodChannel.
Completes request started with fl_method_channel_invoke_method().
Returns: (transfer full): an #FlMethodResponse or NULL on error.
Definition at line 192 of file fl_method_channel.cc.
References error, fl_binary_messenger_send_on_channel_finish(), fl_method_codec_decode_response(), and result.
Referenced by error_response_cb(), failure_response_cb(), method_response_cb(), not_implemented_response_cb(), nullptr_args_response_cb(), and request_app_exit_response_cb().
FlMethodChannel* fl_method_channel_new | ( | FlBinaryMessenger * | messenger, |
const gchar * | name, | ||
FlMethodCodec * | codec | ||
) |
Definition at line 112 of file fl_method_channel.cc.
References channel_closed_cb(), fl_binary_messenger_set_message_handler_on_channel(), and message_cb().
Referenced by cancel_channel(), fl_keyboard_handler_new(), fl_mouse_cursor_handler_new(), fl_platform_handler_new(), fl_text_input_handler_new(), listen_channel(), and TEST().
void fl_method_channel_set_method_call_handler | ( | FlMethodChannel * | channel, |
FlMethodChannelMethodCallHandler | handler, | ||
gpointer | user_data, | ||
GDestroyNotify | destroy_notify | ||
) |
fl_method_channel_set_method_call_handler: @channel: an #FlMethodChannel. @handler: function to call when a method call is received on this channel. @user_data: (closure): user data to pass to @handler. @destroy_notify: (allow-none): a function which gets called to free @user_data, or NULL.
Sets the function called when a method call is received from the Dart side of the channel. See #FlMethodChannelMethodCallHandler for details on how to respond to method calls.
The handler is removed if the channel is closed or is replaced by another handler, set @destroy_notify if you want to detect this.
Definition at line 134 of file fl_method_channel.cc.
References user_data.
Referenced by fl_keyboard_handler_new(), fl_mouse_cursor_handler_new(), fl_platform_handler_new(), fl_text_input_handler_new(), and TEST().
G_BEGIN_DECLS G_MODULE_EXPORT G_DECLARE_FINAL_TYPE | ( | FlMethodChannel | , |
fl_method_channel | , | ||
FL | , | ||
METHOD_CHANNEL | , | ||
GObject | |||
) |
FlMethodChannel:
#FlMethodChannel is an object that allows method calls to and from Dart code.
The following example shows how to call and handle methods on a channel. See #FlMethodResponse for how to handle errors in more detail.
|[ static FlMethodChannel *channel = NULL;
static void method_call_cb (FlMethodChannel* channel, FlMethodCall* method_call, gpointer user_data) { g_autoptr(FlMethodResponse) response = NULL; if (strcmp (fl_method_call_get_name (method_call), "Foo.bar") == 0) { g_autoptr(GError) bar_error = NULL; g_autoptr(FlValue) result = do_bar (fl_method_call_get_args (method_call), &bar_error); if (result == NULL) { response = FL_METHOD_RESPONSE (fl_method_error_response_new ("bar error", bar_error->message, nullptr); } else { response = FL_METHOD_RESPONSE (fl_method_success_response_new (result)); } } else { response = FL_METHOD_RESPONSE (fl_method_not_implemented_response_new ()); }
g_autoptr(GError) error = NULL; if (!fl_method_call_respond(method_call, response, &error)) g_warning ("Failed to send response: %s", error->message); }
static void method_response_cb(GObject *object, GAsyncResult *result, gpointer user_data) { g_autoptr(GError) error = NULL; g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish (FL_METHOD_CODEC (object), result, &error); if (response == NULL) { g_warning ("Failed to call method: %s", error->message); return; }
g_autoptr(FlValue) value = fl_method_response_get_result (response, &error); if (response == NULL) { g_warning ("Method returned error: %s", error->message); return; }
use_result (value); }
static void call_method () { g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new (); channel = fl_method_channel_new(messenger, "flutter/foo", FL_METHOD_CODEC (codec)); fl_method_channel_set_method_call_handler (channel, method_call_cb, NULL, NULL);
g_autoptr(FlValue) args = fl_value_new_string ("Hello World"); fl_method_channel_invoke_method (channel, "Foo.foo", args, cancellable, method_response_cb, NULL); } ]|
#FlMethodChannel matches the MethodChannel class in the Flutter services library. FlMethodChannelMethodCallHandler: @channel: an #FlMethodChannel. @method_call: an #FlMethodCall. @user_data: (closure): data provided when registering this handler.
Function called when a method call is received. Respond to the method call with fl_method_call_respond(). If the response is not occurring in this callback take a reference to @method_call and release that once it has been responded to. Failing to respond before the last reference to @method_call is dropped is a programming error.
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall* method_call |
Definition at line 120 of file fl_method_channel.h.
Referenced by clipboard_get_data_async(), clipboard_has_strings_async(), clipboard_text_cb(), clipboard_text_has_strings_cb(), flutter::MethodCodec< rapidjson::Document >::EncodeMethodCall(), flutter::JsonMethodCodec::EncodeMethodCallInternal(), flutter::StandardMethodCodec::EncodeMethodCallInternal(), flutter::MethodChannel< T >::InvokeMethod(), MethodCallMatcher::MatchAndExplain(), message_cb(), method_call_cb(), method_call_error_cb(), method_call_error_error_cb(), method_call_handler(), method_call_not_implemented_cb(), method_call_success_cb(), method_call_success_error_cb(), reassign_method_cb(), send_response(), flutter::MethodChannel< T >::SetMethodCallHandler(), flutter::EventChannel< T >::SetStreamHandler(), system_exit_application(), and flutter::TEST().
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall gpointer user_data |
Definition at line 121 of file fl_method_channel.h.