| Flutter Linux Embedder |

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
5 #include "flutter/shell/platform/linux/fl_keyboard_channel.h"
6
7 #include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
8 #include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
9
10 static constexpr char kChannelName[] = "flutter/keyboard";
11
12 static constexpr char kGetKeyboardStateMethod[] = "getKeyboardState";
13
14 struct _FlKeyboardChannel {
15 GObject parent_instance;
16
17 FlMethodChannel* channel;
18
19 FlKeyboardChannelVTable* vtable;
20
21 gpointer user_data;
22 };
23
24 G_DEFINE_TYPE(FlKeyboardChannel, fl_keyboard_channel, G_TYPE_OBJECT)
25
26 static 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.
32 static 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
51 static 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
59 static void fl_keyboard_channel_class_init(FlKeyboardChannelClass* klass) {
60 G_OBJECT_CLASS(klass)->dispose = fl_keyboard_channel_dispose;
61 }
62
63 static void fl_keyboard_channel_init(FlKeyboardChannel* self) {}
64
65 FlKeyboardChannel* fl_keyboard_channel_new(FlBinaryMessenger* messenger,
66 FlKeyboardChannelVTable* vtable,
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));
80 fl_method_channel_set_method_call_handler(self->channel, method_call_cb, self,
81 nullptr);
82
83 return self;
84 }
G_DEFINE_TYPE
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
Definition: fl_basic_message_channel.cc:37
g_autoptr
g_autoptr(GMutexLocker) locker
self
g_cond_signal & self
Definition: fl_compositor_software.cc:67
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
method_call_cb
static void method_call_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
Definition: fl_keyboard_channel.cc:32
fl_keyboard_channel_new
FlKeyboardChannel * fl_keyboard_channel_new(FlBinaryMessenger *messenger, FlKeyboardChannelVTable *vtable, gpointer user_data)
Definition: fl_keyboard_channel.cc:65
get_keyboard_state
static FlMethodResponse * get_keyboard_state(FlKeyboardChannel *self)
Definition: fl_keyboard_channel.cc:26
fl_keyboard_channel_init
static void fl_keyboard_channel_init(FlKeyboardChannel *self)
Definition: fl_keyboard_channel.cc:63
kChannelName
static constexpr char kChannelName[]
Definition: fl_keyboard_channel.cc:10
fl_keyboard_channel_dispose
static void fl_keyboard_channel_dispose(GObject *object)
Definition: fl_keyboard_channel.cc:51
fl_keyboard_channel_class_init
static void fl_keyboard_channel_class_init(FlKeyboardChannelClass *klass)
Definition: fl_keyboard_channel.cc:59
kGetKeyboardStateMethod
static constexpr char kGetKeyboardStateMethod[]
Definition: fl_keyboard_channel.cc:12
fl_keyboard_channel.h
fl_method_call_respond
G_MODULE_EXPORT gboolean fl_method_call_respond(FlMethodCall *self, FlMethodResponse *response, GError **error)
Definition: fl_method_call.cc:77
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_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
fl_method_channel.h
method_call
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
Definition: fl_method_channel.h:120
fl_method_success_response_new
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
Definition: fl_method_response.cc:126
fl_method_not_implemented_response_new
G_MODULE_EXPORT FlMethodNotImplementedResponse * fl_method_not_implemented_response_new()
Definition: fl_method_response.cc:179
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_standard_method_codec_new
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
Definition: fl_standard_method_codec.cc:291
fl_standard_method_codec.h
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
_FlKeyboardChannel
Definition: fl_keyboard_channel.cc:14
_FlKeyboardChannel::user_data
gpointer user_data
Definition: fl_keyboard_channel.cc:21
_FlKeyboardChannel::channel
FlMethodChannel * channel
Definition: fl_keyboard_channel.cc:17
_FlKeyboardChannel::parent_instance
GObject parent_instance
Definition: fl_keyboard_channel.cc:15
_FlKeyboardChannel::vtable
FlKeyboardChannelVTable * vtable
Definition: fl_keyboard_channel.cc:19
FlKeyboardChannelVTable
Definition: fl_keyboard_channel.h:25