| Flutter Linux Embedder |

Classes | Functions | Variables
fl_platform_channel.cc File Reference
`#include "flutter/shell/platform/linux/fl_platform_channel.h"`
`#include <cstring>`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"`

Go to the source code of this file.

## Classes
struct | _FlPlatformChannel

## Functions
static FlMethodResponse * | clipboard_set_data (FlPlatformChannel *self, FlMethodCall *method_call)
static FlMethodResponse * | clipboard_get_data (FlPlatformChannel *self, FlMethodCall *method_call)
static FlMethodResponse * | clipboard_has_strings (FlPlatformChannel *self, FlMethodCall *method_call)
FlPlatformChannelExitResponse | get_exit_response (FlMethodResponse *response)
static FlMethodResponse * | system_exit_application (FlPlatformChannel *self, FlMethodCall *method_call)
static FlMethodResponse * | system_initialization_complete (FlPlatformChannel *self)
static FlMethodResponse * | system_sound_play (FlPlatformChannel *self, FlValue *args)
static FlMethodResponse * | system_navigator_pop (FlPlatformChannel *self)
static void | method_call_cb (FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static void | fl_platform_channel_dispose (GObject *object)
static void | fl_platform_channel_class_init (FlPlatformChannelClass *klass)
static void | fl_platform_channel_init (FlPlatformChannel *self)
FlPlatformChannel * | fl_platform_channel_new (FlBinaryMessenger *messenger, FlPlatformChannelVTable *vtable, gpointer user_data)
void | fl_platform_channel_system_request_app_exit (FlPlatformChannel *self, 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_clipboard_get_data (FlMethodCall *method_call, const gchar *text)
void | fl_platform_channel_respond_clipboard_has_strings (FlMethodCall *method_call, gboolean has_strings)
void | fl_platform_channel_respond_system_exit_application (FlMethodCall *method_call, FlPlatformChannelExitResponse exit_response)
FlMethodResponse * | fl_platform_channel_make_system_request_app_exit_response (FlPlatformChannelExitResponse exit_response)

## Variables
static constexpr char | kChannelName [] = "flutter/platform"
static constexpr char | kBadArgumentsError [] = "Bad Arguments"
static constexpr char | kGetClipboardDataMethod [] = "Clipboard.getData"
static constexpr char | kSetClipboardDataMethod [] = "Clipboard.setData"
static constexpr char | kClipboardHasStringsMethod [] = "Clipboard.hasStrings"
static constexpr char | kExitApplicationMethod [] = "System.exitApplication"
static constexpr char | kRequestAppExitMethod [] = "System.requestAppExit"
static constexpr char | kInitializationCompleteMethod []
static constexpr char | kPlaySoundMethod [] = "SystemSound.play"
static constexpr char | kSystemNavigatorPopMethod [] = "SystemNavigator.pop"
static constexpr char | kTextKey [] = "text"
static constexpr char | kValueKey [] = "value"
static constexpr char | kExitTypeKey [] = "type"
static constexpr char | kExitTypeCancelable [] = "cancelable"
static constexpr char | kExitTypeRequired [] = "required"
static constexpr char | kExitResponseKey [] = "response"
static constexpr char | kExitResponseCancel [] = "cancel"
static constexpr char | kExitResponseExit [] = "exit"

## Function Documentation

## ◆ clipboard_get_data()

static FlMethodResponse* clipboard_get_data | ( | FlPlatformChannel * | self,
|  | FlMethodCall * | method_call
| ) |  |
| static

Definition at line 68 of file fl_platform_channel.cc.

69 {
70 FlValue* args = fl_method_call_get_args(method_call);
71
72 if (fl_value_get_type(args) != FL_VALUE_TYPE_STRING) {
73 return FL_METHOD_RESPONSE(fl_method_error_response_new(
74 kBadArgumentsError, "Expected string", nullptr));
75 }
76 const gchar* format = fl_value_get_string(args);
77
78 return self->vtable->clipboard_get_data(method_call, format, self->user_data);
79 }
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
fl_method_call_get_args
G_MODULE_EXPORT FlValue * fl_method_call_get_args(FlMethodCall *self)
Definition: fl_method_call.cc:72
method_call
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
Definition: fl_method_channel.h:120
fl_method_error_response_new
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
Definition: fl_method_response.cc:144
kBadArgumentsError
static constexpr char kBadArgumentsError[]
Definition: fl_platform_channel.cc:13
format
uint32_t uint32_t * format
Definition: fl_texture_registrar_test.cc:42
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:68

References args, fl_method_call_get_args(), fl_method_error_response_new(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, format, kBadArgumentsError, and method_call.

Referenced by method_call_cb().

## ◆ clipboard_has_strings()

static FlMethodResponse* clipboard_has_strings | ( | FlPlatformChannel * | self,
|  | FlMethodCall * | method_call
| ) |  |
| static

Definition at line 81 of file fl_platform_channel.cc.

82 {
83 return self->vtable->clipboard_has_strings(method_call, self->user_data);
84 }

References method_call.

Referenced by method_call_cb().

## ◆ clipboard_set_data()

static FlMethodResponse* clipboard_set_data | ( | FlPlatformChannel * | self,
|  | FlMethodCall * | method_call
| ) |  |
| static

Definition at line 48 of file fl_platform_channel.cc.

49 {
50 FlValue* args = fl_method_call_get_args(method_call);
51
52 if (fl_value_get_type(args) != FL_VALUE_TYPE_MAP) {
53 return FL_METHOD_RESPONSE(fl_method_error_response_new(
54 kBadArgumentsError, "Argument map missing or malformed", nullptr));
55 }
56
57 FlValue* text_value = fl_value_lookup_string(args, kTextKey);
58 if (text_value == nullptr ||
59 fl_value_get_type(text_value) != FL_VALUE_TYPE_STRING) {
60 return FL_METHOD_RESPONSE(fl_method_error_response_new(
61 kBadArgumentsError, "Missing clipboard text", nullptr));
62 }
63 const gchar* text = fl_value_get_string(text_value);
64
65 return self->vtable->clipboard_set_data(method_call, text, self->user_data);
66 }
kTextKey
static constexpr char kTextKey[]
Definition: fl_platform_channel.cc:23
fl_value_lookup_string
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
FL_VALUE_TYPE_MAP
@ FL_VALUE_TYPE_MAP
Definition: fl_value.h:74

References args, fl_method_call_get_args(), fl_method_error_response_new(), fl_value_get_string(), fl_value_get_type(), fl_value_lookup_string(), FL_VALUE_TYPE_MAP, FL_VALUE_TYPE_STRING, kBadArgumentsError, kTextKey, and method_call.

Referenced by method_call_cb().

## ◆ fl_platform_channel_class_init()

static void fl_platform_channel_class_init | ( | FlPlatformChannelClass * | klass | ) |
| static

Definition at line 216 of file fl_platform_channel.cc.

216 {
217 G_OBJECT_CLASS(klass)->dispose = fl_platform_channel_dispose;
218 }
fl_platform_channel_dispose
static void fl_platform_channel_dispose(GObject *object)
Definition: fl_platform_channel.cc:208

References fl_platform_channel_dispose().

## ◆ fl_platform_channel_dispose()

static void fl_platform_channel_dispose | ( | GObject * | object | ) |
| static

Definition at line 208 of file fl_platform_channel.cc.

208 {
209 FlPlatformChannel* self = FL_PLATFORM_CHANNEL(object);
210
211 g_clear_object(&self->channel);
212
213 G_OBJECT_CLASS(fl_platform_channel_parent_class)->dispose(object);
214 }

Referenced by fl_platform_channel_class_init().

## ◆ fl_platform_channel_init()

static void fl_platform_channel_init | ( | FlPlatformChannel * | self | ) |
| static

Definition at line 220 of file fl_platform_channel.cc.

220 {}

## ◆ 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) {
335 case FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL:
336 exit_response_string = kExitResponseCancel;
337 break;
338 case FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT:
339 exit_response_string = kExitResponseExit;
340 break;
341 default:
342 g_assert_not_reached();
343 }
344 fl_value_set_string_take(exit_result, kExitResponseKey,
345 fl_value_new_string(exit_response_string));
346 return FL_METHOD_RESPONSE(fl_method_success_response_new(exit_result));
347 }
fl_method_success_response_new
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
Definition: fl_method_response.cc:126
kExitResponseExit
static constexpr char kExitResponseExit[]
Definition: fl_platform_channel.cc:32
kExitResponseKey
static constexpr char kExitResponseKey[]
Definition: fl_platform_channel.cc:30
kExitResponseCancel
static constexpr char kExitResponseCancel[]
Definition: fl_platform_channel.cc:31
FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT
@ FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT
Definition: fl_platform_channel.h:20
FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL
@ FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL
Definition: fl_platform_channel.h:19
fl_value_set_string_take
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:650
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366

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(), 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));
237 fl_method_channel_set_method_call_handler(self->channel, method_call_cb, self,
238 nullptr);
239
240 return self;
241 }
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
fl_json_method_codec_new
G_MODULE_EXPORT FlJsonMethodCodec * fl_json_method_codec_new()
Definition: fl_json_method_codec.cc:205
fl_method_channel_new
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
Definition: fl_method_channel.cc:112
fl_method_channel_set_method_call_handler
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_method_channel.cc:134
method_call_cb
static void method_call_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
Definition: fl_platform_channel.cc:173
kChannelName
static constexpr char kChannelName[]
Definition: fl_platform_channel.cc:12

References fl_json_method_codec_new(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), kChannelName, method_call_cb(), 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();
289 fl_value_set_string_take(result, kTextKey, fl_value_new_string(text));
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 }
fl_method_call_respond
G_MODULE_EXPORT gboolean fl_method_call_respond(FlMethodCall *self, FlMethodResponse *response, GError **error)
Definition: fl_method_call.cc:77
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
kGetClipboardDataMethod
static constexpr char kGetClipboardDataMethod[]
Definition: fl_platform_channel.cc:14

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

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 {
305 g_autoptr(FlValue) result = fl_value_new_map();
306 fl_value_set_string_take(result, kValueKey, fl_value_new_bool(has_strings));
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 }
kValueKey
static constexpr char kValueKey[]
Definition: fl_platform_channel.cc:24
kClipboardHasStringsMethod
static constexpr char kClipboardHasStringsMethod[]
Definition: fl_platform_channel.cc:16
fl_value_new_bool
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(), 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 =
322 fl_platform_channel_make_system_request_app_exit_response(exit_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 }
fl_platform_channel_make_system_request_app_exit_response
FlMethodResponse * fl_platform_channel_make_system_request_app_exit_response(FlPlatformChannelExitResponse exit_response)
Definition: fl_platform_channel.cc:330

References error, fl_method_call_respond(), fl_platform_channel_make_system_request_app_exit_response(), 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
250 g_autoptr(FlValue) args = fl_value_new_map();
251 const gchar* type_string;
252 switch (type) {
253 case FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE:
254 type_string = kExitTypeCancelable;
255 break;
256 case FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED:
257 type_string = kExitTypeRequired;
258 break;
259 default:
260 g_assert_not_reached();
261 }
262 fl_value_set_string_take(args, kExitTypeKey,
263 fl_value_new_string(type_string));
264 fl_method_channel_invoke_method(self->channel, kRequestAppExitMethod, args,
265 cancellable, callback, user_data);
266 }
fl_method_channel_invoke_method
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_method_channel.cc:162
kExitTypeCancelable
static constexpr char kExitTypeCancelable[]
Definition: fl_platform_channel.cc:27
kRequestAppExitMethod
static constexpr char kRequestAppExitMethod[]
Definition: fl_platform_channel.cc:18
kExitTypeRequired
static constexpr char kExitTypeRequired[]
Definition: fl_platform_channel.cc:28
kExitTypeKey
static constexpr char kExitTypeKey[]
Definition: fl_platform_channel.cc:26
FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE
@ FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE
Definition: fl_platform_channel.h:14
FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED
@ FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED
Definition: fl_platform_channel.h:15
type
uint8_t type
Definition: fl_standard_message_codec_test.cc:1115

References args, 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(), kExitTypeCancelable, kExitTypeKey, kExitTypeRequired, kRequestAppExitMethod, 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 }
fl_method_channel_invoke_method_finish
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
Definition: fl_method_channel.cc:192
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
get_exit_response
FlPlatformChannelExitResponse get_exit_response(FlMethodResponse *response)
Definition: fl_platform_channel.cc:87

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

Referenced by request_app_exit_response_cb(), and TEST().

## ◆ get_exit_response()

FlPlatformChannelExitResponse get_exit_response | ( | FlMethodResponse * | response | ) |

Definition at line 87 of file fl_platform_channel.cc.

87 {
88 if (response == nullptr) {
89 return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT;
90 }
91
92 g_autoptr(GError) error = nullptr;
93 FlValue* result = fl_method_response_get_result(response, &error);
94 if (result == nullptr) {
95 g_warning("Error returned from System.requestAppExit: %s", error->message);
96 return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT;
97 }
98 if (fl_value_get_type(result) != FL_VALUE_TYPE_MAP) {
99 g_warning("System.requestAppExit result argument map missing or malformed");
100 return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT;
101 }
102
103 FlValue* response_value = fl_value_lookup_string(result, kExitResponseKey);
104 if (fl_value_get_type(response_value) != FL_VALUE_TYPE_STRING) {
105 g_warning("Invalid response from System.requestAppExit");
106 return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT;
107 }
108 const char* response_string = fl_value_get_string(response_value);
109
110 if (strcmp(response_string, kExitResponseCancel) == 0) {
111 return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL;
112 } else if (strcmp(response_string, kExitResponseExit) == 0) {
113 return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT;
114 }
115
116 // If something went wrong, then just exit.
117 return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT;
118 }
fl_method_response_get_result
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)
Definition: fl_method_response.cc:82

References error, fl_method_response_get_result(), FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL, FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT, fl_value_get_string(), fl_value_get_type(), fl_value_lookup_string(), FL_VALUE_TYPE_MAP, FL_VALUE_TYPE_STRING, kExitResponseCancel, kExitResponseExit, and kExitResponseKey.

Referenced by fl_platform_channel_system_request_app_exit_finish().

## ◆ method_call_cb()

static void method_call_cb | ( | FlMethodChannel * | channel,
|  | FlMethodCall * | method_call,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 173 of file fl_platform_channel.cc.

175 {
176 FlPlatformChannel* self = FL_PLATFORM_CHANNEL(user_data);
177
178 const gchar* method = fl_method_call_get_name(method_call);
179 FlValue* args = fl_method_call_get_args(method_call);
180
181 g_autoptr(FlMethodResponse) response = nullptr;
182 if (strcmp(method, kSetClipboardDataMethod) == 0) {
183 response = clipboard_set_data(self, method_call);
184 } else if (strcmp(method, kGetClipboardDataMethod) == 0) {
185 response = clipboard_get_data(self, method_call);
186 } else if (strcmp(method, kClipboardHasStringsMethod) == 0) {
187 response = clipboard_has_strings(self, method_call);
188 } else if (strcmp(method, kExitApplicationMethod) == 0) {
189 response = system_exit_application(self, method_call);
190 } else if (strcmp(method, kInitializationCompleteMethod) == 0) {
191 response = system_initialization_complete(self);
192 } else if (strcmp(method, kPlaySoundMethod) == 0) {
193 response = system_sound_play(self, args);
194 } else if (strcmp(method, kSystemNavigatorPopMethod) == 0) {
195 response = system_navigator_pop(self);
196 } else {
197 response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
198 }
199
200 if (response != nullptr) {
201 g_autoptr(GError) error = nullptr;
202 if (!fl_method_call_respond(method_call, response, &error)) {
203 g_warning("Failed to send method call response: %s", error->message);
204 }
205 }
206 }
fl_method_call_get_name
G_MODULE_EXPORT const gchar * fl_method_call_get_name(FlMethodCall *self)
Definition: fl_method_call.cc:67
fl_method_not_implemented_response_new
G_MODULE_EXPORT FlMethodNotImplementedResponse * fl_method_not_implemented_response_new()
Definition: fl_method_response.cc:179
system_initialization_complete
static FlMethodResponse * system_initialization_complete(FlPlatformChannel *self)
Definition: fl_platform_channel.cc:149
kSystemNavigatorPopMethod
static constexpr char kSystemNavigatorPopMethod[]
Definition: fl_platform_channel.cc:22
kInitializationCompleteMethod
static constexpr char kInitializationCompleteMethod[]
Definition: fl_platform_channel.cc:19
clipboard_get_data
static FlMethodResponse * clipboard_get_data(FlPlatformChannel *self, FlMethodCall *method_call)
Definition: fl_platform_channel.cc:68
system_sound_play
static FlMethodResponse * system_sound_play(FlPlatformChannel *self, FlValue *args)
Definition: fl_platform_channel.cc:155
kExitApplicationMethod
static constexpr char kExitApplicationMethod[]
Definition: fl_platform_channel.cc:17
system_exit_application
static FlMethodResponse * system_exit_application(FlPlatformChannel *self, FlMethodCall *method_call)
Definition: fl_platform_channel.cc:120
kPlaySoundMethod
static constexpr char kPlaySoundMethod[]
Definition: fl_platform_channel.cc:21
system_navigator_pop
static FlMethodResponse * system_navigator_pop(FlPlatformChannel *self)
Definition: fl_platform_channel.cc:168
clipboard_has_strings
static FlMethodResponse * clipboard_has_strings(FlPlatformChannel *self, FlMethodCall *method_call)
Definition: fl_platform_channel.cc:81
clipboard_set_data
static FlMethodResponse * clipboard_set_data(FlPlatformChannel *self, FlMethodCall *method_call)
Definition: fl_platform_channel.cc:48
kSetClipboardDataMethod
static constexpr char kSetClipboardDataMethod[]
Definition: fl_platform_channel.cc:15

References args, clipboard_get_data(), clipboard_has_strings(), clipboard_set_data(), error, fl_method_call_get_args(), fl_method_call_get_name(), fl_method_call_respond(), fl_method_not_implemented_response_new(), kClipboardHasStringsMethod, kExitApplicationMethod, kGetClipboardDataMethod, kInitializationCompleteMethod, kPlaySoundMethod, kSetClipboardDataMethod, kSystemNavigatorPopMethod, method_call, system_exit_application(), system_initialization_complete(), system_navigator_pop(), system_sound_play(), and user_data.

Referenced by fl_platform_channel_new().

## ◆ system_exit_application()

static FlMethodResponse* system_exit_application | ( | FlPlatformChannel * | self,
|  | FlMethodCall * | method_call
| ) |  |
| static

Definition at line 120 of file fl_platform_channel.cc.

121 {
122 FlValue* args = fl_method_call_get_args(method_call);
123 if (fl_value_get_type(args) != FL_VALUE_TYPE_MAP) {
124 return FL_METHOD_RESPONSE(fl_method_error_response_new(
125 kBadArgumentsError, "Argument map missing or malformed", nullptr));
126 }
127
128 FlValue* type_value = fl_value_lookup_string(args, kExitTypeKey);
129 if (type_value == nullptr ||
130 fl_value_get_type(type_value) != FL_VALUE_TYPE_STRING) {
131 return FL_METHOD_RESPONSE(fl_method_error_response_new(
132 kBadArgumentsError, "Missing type argument", nullptr));
133 }
134 const char* type_string = fl_value_get_string(type_value);
135 FlPlatformChannelExitType type;
136 if (strcmp(type_string, kExitTypeCancelable) == 0) {
137 type = FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE;
138 } else if (strcmp(type_string, kExitTypeRequired) == 0) {
139 type = FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED;
140 } else {
141 return FL_METHOD_RESPONSE(fl_method_error_response_new(
142 kBadArgumentsError, "Invalid exit type", nullptr));
143 }
144
145 return self->vtable->system_exit_application(method_call, type,
146 self->user_data);
147 }
FlPlatformChannelExitType
FlPlatformChannelExitType
Definition: fl_platform_channel.h:13

References args, fl_method_call_get_args(), fl_method_error_response_new(), FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE, FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED, fl_value_get_string(), fl_value_get_type(), fl_value_lookup_string(), FL_VALUE_TYPE_MAP, FL_VALUE_TYPE_STRING, kBadArgumentsError, kExitTypeCancelable, kExitTypeKey, kExitTypeRequired, method_call, and type.

Referenced by method_call_cb().

## ◆ system_initialization_complete()

static FlMethodResponse* system_initialization_complete | ( | FlPlatformChannel * | self | ) |
| static

Definition at line 149 of file fl_platform_channel.cc.

150 {
151 self->vtable->system_initialization_complete(self->user_data);
152 return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
153 }

References fl_method_success_response_new().

Referenced by method_call_cb().

## ◆ system_navigator_pop()

static FlMethodResponse* system_navigator_pop | ( | FlPlatformChannel * | self | ) |
| static

Definition at line 168 of file fl_platform_channel.cc.

168 {
169 self->vtable->system_navigator_pop(self->user_data);
170 return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
171 }

References fl_method_success_response_new().

Referenced by method_call_cb().

## ◆ system_sound_play()

static FlMethodResponse* system_sound_play | ( | FlPlatformChannel * | self,
|  | FlValue * | args
| ) |  |
| static

Definition at line 155 of file fl_platform_channel.cc.

156 {
157 if (fl_value_get_type(args) != FL_VALUE_TYPE_STRING) {
158 return FL_METHOD_RESPONSE(fl_method_error_response_new(
159 kBadArgumentsError, "Expected string", nullptr));
160 }
161 const gchar* type = fl_value_get_string(args);
162
163 self->vtable->system_sound_play(type, self->user_data);
164
165 return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
166 }

References args, fl_method_error_response_new(), fl_method_success_response_new(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, kBadArgumentsError, and type.

Referenced by method_call_cb().

## Variable Documentation

## ◆ kBadArgumentsError

constexpr char kBadArgumentsError[] = "Bad Arguments"
| static constexpr

Definition at line 13 of file fl_platform_channel.cc.

Referenced by clipboard_get_data(), clipboard_set_data(), system_exit_application(), and system_sound_play().

## ◆ kChannelName

constexpr char kChannelName[] = "flutter/platform"
| static constexpr

Definition at line 12 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_new().

## ◆ kClipboardHasStringsMethod

constexpr char kClipboardHasStringsMethod[] = "Clipboard.hasStrings"
| static constexpr

Definition at line 16 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_respond_clipboard_has_strings(), and method_call_cb().

## ◆ kExitApplicationMethod

constexpr char kExitApplicationMethod[] = "System.exitApplication"
| static constexpr

Definition at line 17 of file fl_platform_channel.cc.

Referenced by method_call_cb().

## ◆ kExitResponseCancel

constexpr char kExitResponseCancel[] = "cancel"
| static constexpr

Definition at line 31 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_make_system_request_app_exit_response(), and get_exit_response().

## ◆ kExitResponseExit

constexpr char kExitResponseExit[] = "exit"
| static constexpr

Definition at line 32 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_make_system_request_app_exit_response(), and get_exit_response().

## ◆ kExitResponseKey

constexpr char kExitResponseKey[] = "response"
| static constexpr

Definition at line 30 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_make_system_request_app_exit_response(), and get_exit_response().

## ◆ kExitTypeCancelable

constexpr char kExitTypeCancelable[] = "cancelable"
| static constexpr

Definition at line 27 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_system_request_app_exit(), and system_exit_application().

## ◆ kExitTypeKey

constexpr char kExitTypeKey[] = "type"
| static constexpr

Definition at line 26 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_system_request_app_exit(), and system_exit_application().

## ◆ kExitTypeRequired

constexpr char kExitTypeRequired[] = "required"
| static constexpr

Definition at line 28 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_system_request_app_exit(), and system_exit_application().

## ◆ kGetClipboardDataMethod

constexpr char kGetClipboardDataMethod[] = "Clipboard.getData"
| static constexpr

Definition at line 14 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_respond_clipboard_get_data(), and method_call_cb().

## ◆ kInitializationCompleteMethod

constexpr char kInitializationCompleteMethod[]
| static constexpr

Initial value:
=
"System.initializationComplete"

Definition at line 19 of file fl_platform_channel.cc.

Referenced by method_call_cb().

## ◆ kPlaySoundMethod

constexpr char kPlaySoundMethod[] = "SystemSound.play"
| static constexpr

Definition at line 21 of file fl_platform_channel.cc.

Referenced by method_call_cb().

## ◆ kRequestAppExitMethod

constexpr char kRequestAppExitMethod[] = "System.requestAppExit"
| static constexpr

Definition at line 18 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_system_request_app_exit().

## ◆ kSetClipboardDataMethod

constexpr char kSetClipboardDataMethod[] = "Clipboard.setData"
| static constexpr

Definition at line 15 of file fl_platform_channel.cc.

Referenced by method_call_cb().

## ◆ kSystemNavigatorPopMethod

constexpr char kSystemNavigatorPopMethod[] = "SystemNavigator.pop"
| static constexpr

Definition at line 22 of file fl_platform_channel.cc.

Referenced by method_call_cb().

## ◆ kTextKey

constexpr char kTextKey[] = "text"
| static constexpr

Definition at line 23 of file fl_platform_channel.cc.

Referenced by clipboard_set_data(), and fl_platform_channel_respond_clipboard_get_data().

## ◆ kValueKey

constexpr char kValueKey[] = "value"
| static constexpr

Definition at line 24 of file fl_platform_channel.cc.

Referenced by fl_platform_channel_respond_clipboard_has_strings().