Flutter Engine
 
Loading...
Searching...
No Matches
fl_keyboard_channel.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
9
10static constexpr char kChannelName[] = "flutter/keyboard";
11
12static constexpr char kGetKeyboardStateMethod[] = "getKeyboardState";
13
16
17 FlMethodChannel* channel;
18
20
21 gpointer user_data;
22};
23
24G_DEFINE_TYPE(FlKeyboardChannel, fl_keyboard_channel, G_TYPE_OBJECT)
25
26static FlMethodResponse* get_keyboard_state(FlKeyboardChannel* self) {
27 g_autoptr(FlValue) result = self->vtable->get_keyboard_state(self->user_data);
28 return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
29}
30
31// Called when a method call is received from Flutter.
32static void method_call_cb(FlMethodChannel* channel,
33 FlMethodCall* method_call,
34 gpointer user_data) {
35 FlKeyboardChannel* self = FL_KEYBOARD_CHANNEL(user_data);
36
37 const gchar* method = fl_method_call_get_name(method_call);
38 g_autoptr(FlMethodResponse) response = nullptr;
39 if (strcmp(method, kGetKeyboardStateMethod) == 0) {
40 response = get_keyboard_state(self);
41 } else {
42 response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
43 }
44
45 g_autoptr(GError) error = nullptr;
46 if (!fl_method_call_respond(method_call, response, &error)) {
47 g_warning("Failed to send method call response: %s", error->message);
48 }
49}
50
51static void fl_keyboard_channel_dispose(GObject* object) {
52 FlKeyboardChannel* self = FL_KEYBOARD_CHANNEL(object);
53
54 g_clear_object(&self->channel);
55
56 G_OBJECT_CLASS(fl_keyboard_channel_parent_class)->dispose(object);
57}
58
59static void fl_keyboard_channel_class_init(FlKeyboardChannelClass* klass) {
60 G_OBJECT_CLASS(klass)->dispose = fl_keyboard_channel_dispose;
61}
62
63static void fl_keyboard_channel_init(FlKeyboardChannel* self) {}
64
65FlKeyboardChannel* fl_keyboard_channel_new(FlBinaryMessenger* messenger,
67 gpointer user_data) {
68 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
69 g_return_val_if_fail(vtable != nullptr, nullptr);
70
71 FlKeyboardChannel* self = FL_KEYBOARD_CHANNEL(
72 g_object_new(fl_keyboard_channel_get_type(), nullptr));
73
74 self->vtable = vtable;
75 self->user_data = user_data;
76
77 g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
78 self->channel =
79 fl_method_channel_new(messenger, kChannelName, FL_METHOD_CODEC(codec));
81 nullptr);
82
83 return self;
84}
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
g_autoptr(GMutexLocker) locker
static void method_call_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static void fl_keyboard_channel_init(FlKeyboardChannel *self)
static constexpr char kChannelName[]
static void fl_keyboard_channel_dispose(GObject *object)
FlKeyboardChannel * fl_keyboard_channel_new(FlBinaryMessenger *messenger, FlKeyboardChannelVTable *vtable, gpointer user_data)
static void fl_keyboard_channel_class_init(FlKeyboardChannelClass *klass)
static constexpr char kGetKeyboardStateMethod[]
static FlMethodResponse * get_keyboard_state(FlKeyboardChannel *self)
G_MODULE_EXPORT const gchar * fl_method_call_get_name(FlMethodCall *self)
G_MODULE_EXPORT gboolean fl_method_call_respond(FlMethodCall *self, FlMethodResponse *response, GError **error)
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)
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
G_MODULE_EXPORT FlMethodNotImplementedResponse * fl_method_not_implemented_response_new()
const gchar * channel
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42
FlMethodChannel * channel
FlKeyboardChannelVTable * vtable