Flutter Engine
 
Loading...
Searching...
No Matches
fl_platform_channel.h File Reference

Go to the source code of this file.

Classes

struct  FlPlatformChannelVTable
 

Enumerations

enum  FlPlatformChannelExitType {
  FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE ,
  FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED
}
 
enum  FlPlatformChannelExitResponse {
  FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL ,
  FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT
}
 

Functions

 G_DECLARE_FINAL_TYPE (FlPlatformChannel, fl_platform_channel, FL, PLATFORM_CHANNEL, GObject)
 
FlPlatformChannel * fl_platform_channel_new (FlBinaryMessenger *messenger, FlPlatformChannelVTable *vtable, gpointer user_data)
 
void fl_platform_channel_system_request_app_exit (FlPlatformChannel *channel, FlPlatformChannelExitType type, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 
gboolean fl_platform_channel_system_request_app_exit_finish (GObject *object, GAsyncResult *result, FlPlatformChannelExitResponse *exit_response, GError **error)
 
void fl_platform_channel_respond_system_exit_application (FlMethodCall *method_call, FlPlatformChannelExitResponse exit_response)
 
void fl_platform_channel_respond_clipboard_get_data (FlMethodCall *method_call, const gchar *text)
 
void fl_platform_channel_respond_clipboard_has_strings (FlMethodCall *method_call, gboolean has_strings)
 
FlMethodResponse * fl_platform_channel_make_system_request_app_exit_response (FlPlatformChannelExitResponse exit_response)
 

Enumeration Type Documentation

◆ FlPlatformChannelExitResponse

Enumerator
FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL 
FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT 

Definition at line 18 of file fl_platform_channel.h.

◆ FlPlatformChannelExitType

Enumerator
FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE 
FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED 

Definition at line 13 of file fl_platform_channel.h.

Function Documentation

◆ fl_platform_channel_make_system_request_app_exit_response()

FlMethodResponse * fl_platform_channel_make_system_request_app_exit_response ( FlPlatformChannelExitResponse  exit_response)

Definition at line 330 of file fl_platform_channel.cc.

331 {
332 g_autoptr(FlValue) exit_result = fl_value_new_map();
333 const gchar* exit_response_string;
334 switch (exit_response) {
336 exit_response_string = kExitResponseCancel;
337 break;
339 exit_response_string = kExitResponseExit;
340 break;
341 default:
342 g_assert_not_reached();
343 }
345 fl_value_new_string(exit_response_string));
346 return FL_METHOD_RESPONSE(fl_method_success_response_new(exit_result));
347}
g_autoptr(GMutexLocker) locker
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
static constexpr char kExitResponseExit[]
static constexpr char kExitResponseKey[]
static constexpr char kExitResponseCancel[]
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition fl_value.cc:366
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition fl_value.cc:650
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition fl_value.cc:276
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42

References fl_method_success_response_new(), FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL, FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT, fl_value_new_map(), fl_value_new_string(), fl_value_set_string_take(), g_autoptr(), kExitResponseCancel, kExitResponseExit, and kExitResponseKey.

Referenced by fl_platform_channel_respond_system_exit_application(), and system_exit_application().

◆ fl_platform_channel_new()

FlPlatformChannel * fl_platform_channel_new ( FlBinaryMessenger *  messenger,
FlPlatformChannelVTable vtable,
gpointer  user_data 
)

fl_platform_channel_new: @messenger: an #FlBinaryMessenger @vtable: callbacks for incoming method calls. @user_data: data to pass in callbacks.

Creates a new channel that implements SystemChannels.platform from the Flutter services library.

Returns: a new #FlPlatformChannel

Definition at line 222 of file fl_platform_channel.cc.

224 {
225 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
226 g_return_val_if_fail(vtable != nullptr, nullptr);
227
228 FlPlatformChannel* self = FL_PLATFORM_CHANNEL(
229 g_object_new(fl_platform_channel_get_type(), nullptr));
230
231 self->vtable = vtable;
232 self->user_data = user_data;
233
234 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
235 self->channel =
236 fl_method_channel_new(messenger, kChannelName, FL_METHOD_CODEC(codec));
238 nullptr);
239
240 return self;
241}
G_MODULE_EXPORT FlJsonMethodCodec * fl_json_method_codec_new()
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
static void method_call_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static constexpr char kChannelName[]

References fl_json_method_codec_new(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), g_autoptr(), kChannelName, method_call_cb(), self, and user_data.

Referenced by fl_platform_handler_new(), and TEST().

◆ fl_platform_channel_respond_clipboard_get_data()

void fl_platform_channel_respond_clipboard_get_data ( FlMethodCall *  method_call,
const gchar *  text 
)

Definition at line 284 of file fl_platform_channel.cc.

285 {
286 g_autoptr(FlValue) result = nullptr;
287 if (text != nullptr) {
288 result = fl_value_new_map();
290 }
291
292 g_autoptr(FlMethodResponse) response =
293 FL_METHOD_RESPONSE(fl_method_success_response_new(result));
294
295 g_autoptr(GError) error = nullptr;
296 if (!fl_method_call_respond(method_call, response, &error)) {
297 g_warning("Failed to send response to %s: %s", kGetClipboardDataMethod,
298 error->message);
299 }
300}
G_MODULE_EXPORT gboolean fl_method_call_respond(FlMethodCall *self, FlMethodResponse *response, GError **error)
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
const uint8_t uint32_t uint32_t GError ** error
static constexpr char kGetClipboardDataMethod[]
static constexpr char kTextKey[]
std::u16string text

References error, fl_method_call_respond(), fl_method_success_response_new(), fl_value_new_map(), fl_value_new_string(), fl_value_set_string_take(), g_autoptr(), kGetClipboardDataMethod, kTextKey, method_call, and text.

Referenced by clipboard_text_cb().

◆ fl_platform_channel_respond_clipboard_has_strings()

void fl_platform_channel_respond_clipboard_has_strings ( FlMethodCall *  method_call,
gboolean  has_strings 
)

Definition at line 302 of file fl_platform_channel.cc.

304 {
307
308 g_autoptr(FlMethodResponse) response =
309 FL_METHOD_RESPONSE(fl_method_success_response_new(result));
310
311 g_autoptr(GError) error = nullptr;
312 if (!fl_method_call_respond(method_call, response, &error)) {
313 g_warning("Failed to send response to %s: %s", kClipboardHasStringsMethod,
314 error->message);
315 }
316}
static constexpr char kValueKey[]
static constexpr char kClipboardHasStringsMethod[]
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition fl_value.cc:255

References error, fl_method_call_respond(), fl_method_success_response_new(), fl_value_new_bool(), fl_value_new_map(), fl_value_set_string_take(), g_autoptr(), kClipboardHasStringsMethod, kValueKey, and method_call.

Referenced by clipboard_text_has_strings_cb().

◆ fl_platform_channel_respond_system_exit_application()

void fl_platform_channel_respond_system_exit_application ( FlMethodCall *  method_call,
FlPlatformChannelExitResponse  exit_response 
)

Definition at line 318 of file fl_platform_channel.cc.

320 {
321 g_autoptr(FlMethodResponse) response =
323 g_autoptr(GError) error = nullptr;
324 if (!fl_method_call_respond(method_call, response, &error)) {
325 g_warning("Failed to send response to System.exitApplication: %s",
326 error->message);
327 }
328}
FlMethodResponse * fl_platform_channel_make_system_request_app_exit_response(FlPlatformChannelExitResponse exit_response)

References error, fl_method_call_respond(), fl_platform_channel_make_system_request_app_exit_response(), g_autoptr(), and method_call.

Referenced by request_app_exit_response_cb().

◆ fl_platform_channel_system_request_app_exit()

void fl_platform_channel_system_request_app_exit ( FlPlatformChannel *  channel,
FlPlatformChannelExitType  type,
GCancellable *  cancellable,
GAsyncReadyCallback  callback,
gpointer  user_data 
)

fl_platform_channel_system_request_app_exit: @channel: an #FlPlatformChannel

Request the application exits (i.e. due to the window being requested to be closed).

Calling this will only send an exit request to the framework if the framework has already indicated that it is ready to receive requests by sending a "System.initializationComplete" method call on the platform channel. Calls before initialization is complete will result in an immediate exit.

Definition at line 243 of file fl_platform_channel.cc.

247 {
248 g_return_if_fail(FL_IS_PLATFORM_CHANNEL(self));
249
251 const gchar* type_string;
252 switch (type) {
254 type_string = kExitTypeCancelable;
255 break;
257 type_string = kExitTypeRequired;
258 break;
259 default:
260 g_assert_not_reached();
261 }
263 fl_value_new_string(type_string));
265 cancellable, callback, user_data);
266}
GLenum type
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
static constexpr char kExitTypeCancelable[]
static constexpr char kRequestAppExitMethod[]
static constexpr char kExitTypeRequired[]
static constexpr char kExitTypeKey[]
FlutterDesktopBinaryReply callback

References args, callback, fl_method_channel_invoke_method(), FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE, FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED, fl_value_new_map(), fl_value_new_string(), fl_value_set_string_take(), g_autoptr(), kExitTypeCancelable, kExitTypeKey, kExitTypeRequired, kRequestAppExitMethod, self, type, and user_data.

Referenced by request_app_exit(), and TEST().

◆ fl_platform_channel_system_request_app_exit_finish()

gboolean fl_platform_channel_system_request_app_exit_finish ( GObject *  object,
GAsyncResult *  result,
FlPlatformChannelExitResponse exit_response,
GError **  error 
)

Definition at line 268 of file fl_platform_channel.cc.

272 {
273 g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
274 FL_METHOD_CHANNEL(object), result, error);
275 if (response == nullptr) {
276 return FALSE;
277 }
278
279 *exit_response = get_exit_response(response);
280
281 return TRUE;
282}
return TRUE
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
FlPlatformChannelExitResponse get_exit_response(FlMethodResponse *response)

References error, fl_method_channel_invoke_method_finish(), g_autoptr(), get_exit_response(), and TRUE.

Referenced by request_app_exit_response_cb(), and TEST().

◆ G_DECLARE_FINAL_TYPE()

G_DECLARE_FINAL_TYPE ( FlPlatformChannel  ,
fl_platform_channel  ,
FL  ,
PLATFORM_CHANNEL  ,
GObject   
)