Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 97d5bcc

Browse files
committed
Add FlMethodChannel
1 parent 833cc7b commit 97d5bcc

23 files changed

+4147
-0
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,17 +1174,35 @@ FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.cc
11741174
FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.h
11751175
FILE: ../../../flutter/shell/platform/linux/fl_binary_messenger.cc
11761176
FILE: ../../../flutter/shell/platform/linux/fl_binary_messenger_private.h
1177+
FILE: ../../../flutter/shell/platform/linux/fl_codec.cc
11771178
FILE: ../../../flutter/shell/platform/linux/fl_dart_project.cc
11781179
FILE: ../../../flutter/shell/platform/linux/fl_engine.cc
11791180
FILE: ../../../flutter/shell/platform/linux/fl_engine_private.h
1181+
FILE: ../../../flutter/shell/platform/linux/fl_json_codec.cc
1182+
FILE: ../../../flutter/shell/platform/linux/fl_json_codec_test.cc
1183+
FILE: ../../../flutter/shell/platform/linux/fl_json_method_codec.cc
1184+
FILE: ../../../flutter/shell/platform/linux/fl_method_channel.cc
1185+
FILE: ../../../flutter/shell/platform/linux/fl_method_codec.cc
11801186
FILE: ../../../flutter/shell/platform/linux/fl_renderer.cc
11811187
FILE: ../../../flutter/shell/platform/linux/fl_renderer.h
11821188
FILE: ../../../flutter/shell/platform/linux/fl_renderer_x11.cc
11831189
FILE: ../../../flutter/shell/platform/linux/fl_renderer_x11.h
1190+
FILE: ../../../flutter/shell/platform/linux/fl_standard_codec.cc
1191+
FILE: ../../../flutter/shell/platform/linux/fl_standard_codec_test.cc
1192+
FILE: ../../../flutter/shell/platform/linux/fl_standard_method_codec.cc
1193+
FILE: ../../../flutter/shell/platform/linux/fl_test.cc
11841194
FILE: ../../../flutter/shell/platform/linux/fl_view.cc
11851195
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h
1196+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_codec.h
11861197
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h
11871198
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_engine.h
1199+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_json_codec.h
1200+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h
1201+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h
1202+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h
1203+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_standard_codec.h
1204+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h
1205+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_value.h
11881206
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_view.h
11891207
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/flutter_linux.h
11901208
FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.cc

shell/platform/linux/BUILD.gn

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
assert(is_linux)
66

77
import("//flutter/shell/platform/glfw/config.gni")
8+
import("//flutter/testing/testing.gni")
89

910
group("linux") {
1011
deps = [
@@ -45,7 +46,15 @@ if (build_glfw_shell) {
4546
_public_headers = [
4647
"public/flutter_linux/fl_binary_messenger.h",
4748
"public/flutter_linux/fl_dart_project.h",
49+
"public/flutter_linux/fl_codec.h",
4850
"public/flutter_linux/fl_engine.h",
51+
"public/flutter_linux/fl_json_codec.h",
52+
"public/flutter_linux/fl_json_method_codec.h",
53+
"public/flutter_linux/fl_method_channel.h",
54+
"public/flutter_linux/fl_method_codec.h",
55+
"public/flutter_linux/fl_standard_codec.h",
56+
"public/flutter_linux/fl_standard_method_codec.h",
57+
"public/flutter_linux/fl_value.h",
4958
"public/flutter_linux/fl_view.h",
5059
"public/flutter_linux/flutter_linux.h",
5160
]
@@ -59,10 +68,18 @@ source_set("flutter_linux") {
5968

6069
sources = [
6170
"fl_binary_messenger.cc",
71+
"fl_codec.cc",
6272
"fl_dart_project.cc",
6373
"fl_engine.cc",
74+
"fl_json_codec.cc",
75+
"fl_json_method_codec.cc",
76+
"fl_method_channel.cc",
77+
"fl_method_codec.cc",
6478
"fl_renderer.cc",
6579
"fl_renderer_x11.cc",
80+
"fl_standard_codec.cc",
81+
"fl_standard_method_codec.cc",
82+
"fl_value.cc",
6683
"fl_view.cc",
6784
]
6885

@@ -80,6 +97,23 @@ source_set("flutter_linux") {
8097
]
8198
}
8299

100+
executable("flutter_linux_unittests") {
101+
testonly = true
102+
103+
sources = [
104+
"fl_json_codec_test.cc",
105+
"fl_standard_codec_test.cc",
106+
"fl_test.cc",
107+
]
108+
109+
public_configs = [ "//flutter:config" ]
110+
111+
deps = [
112+
":flutter_linux",
113+
"//flutter/testing",
114+
]
115+
}
116+
83117
shared_library("flutter_linux_gtk") {
84118
deps = [
85119
":flutter_linux",

shell/platform/linux/fl_codec.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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/public/flutter_linux/fl_codec.h"
6+
7+
#include <gmodule.h>
8+
9+
G_DEFINE_QUARK(fl_codec_error_quark, fl_codec_error)
10+
11+
// Added here to stop the compiler from optimising this function away
12+
G_MODULE_EXPORT GType fl_codec_get_type();
13+
14+
G_DEFINE_TYPE(FlCodec, fl_codec, G_TYPE_OBJECT)
15+
16+
static void fl_codec_class_init(FlCodecClass* klass) {}
17+
18+
static void fl_codec_init(FlCodec* self) {}
19+
20+
G_MODULE_EXPORT gboolean fl_codec_write_value(FlCodec* self,
21+
GByteArray* buffer,
22+
FlValue* value,
23+
GError** error) {
24+
g_return_val_if_fail(FL_IS_CODEC(self), FALSE);
25+
g_return_val_if_fail(buffer != nullptr, FALSE);
26+
27+
g_autoptr(FlValue) null_value = NULL;
28+
if (value == nullptr)
29+
value = null_value = fl_value_null_new();
30+
31+
return FL_CODEC_GET_CLASS(self)->write_value(self, buffer, value, error);
32+
}
33+
34+
G_MODULE_EXPORT FlValue* fl_codec_read_value(FlCodec* self,
35+
GBytes* buffer,
36+
size_t* offset,
37+
GError** error) {
38+
g_return_val_if_fail(FL_IS_CODEC(self), nullptr);
39+
g_return_val_if_fail(buffer != nullptr, nullptr);
40+
41+
size_t o = offset != nullptr ? *offset : 0;
42+
FlValue* value =
43+
FL_CODEC_GET_CLASS(self)->read_value(self, buffer, &o, error);
44+
if (value != nullptr && offset != nullptr)
45+
*offset = o;
46+
return value;
47+
}

0 commit comments

Comments
 (0)