| Flutter Linux Embedder |

fl_method_codec.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/public/flutter_linux/fl_method_codec.h"
6 #include "flutter/shell/platform/linux/fl_method_codec_private.h"
7
8 #include <gmodule.h>
9
10 G_DEFINE_TYPE(FlMethodCodec, fl_method_codec, G_TYPE_OBJECT)
11
12 static void fl_method_codec_class_init(FlMethodCodecClass* klass) {}
13
14 static void fl_method_codec_init(FlMethodCodec* self) {}
15
16 GBytes* fl_method_codec_encode_method_call(FlMethodCodec* self,
17 const gchar* name,
18 FlValue* args,
19 GError** error) {
20 g_return_val_if_fail(FL_IS_METHOD_CODEC(self), nullptr);
21 g_return_val_if_fail(name != nullptr, nullptr);
22
23 return FL_METHOD_CODEC_GET_CLASS(self)->encode_method_call(self, name, args,
24 error);
25 }
26
27 gboolean fl_method_codec_decode_method_call(FlMethodCodec* self,
28 GBytes* message,
29 gchar** name,
30 FlValue** args,
31 GError** error) {
32 g_return_val_if_fail(FL_IS_METHOD_CODEC(self), FALSE);
33 g_return_val_if_fail(message != nullptr, FALSE);
34 g_return_val_if_fail(name != nullptr, FALSE);
35 g_return_val_if_fail(args != nullptr, FALSE);
36
37 return FL_METHOD_CODEC_GET_CLASS(self)->decode_method_call(self, message,
38 name, args, error);
39 }
40
41 GBytes* fl_method_codec_encode_success_envelope(FlMethodCodec* self,
42 FlValue* result,
43 GError** error) {
44 g_return_val_if_fail(FL_IS_METHOD_CODEC(self), nullptr);
45
46 return FL_METHOD_CODEC_GET_CLASS(self)->encode_success_envelope(self, result,
47 error);
48 }
49
50 GBytes* fl_method_codec_encode_error_envelope(FlMethodCodec* self,
51 const gchar* code,
52 const gchar* message,
53 FlValue* details,
54 GError** error) {
55 g_return_val_if_fail(FL_IS_METHOD_CODEC(self), nullptr);
56 g_return_val_if_fail(code != nullptr, nullptr);
57
58 return FL_METHOD_CODEC_GET_CLASS(self)->encode_error_envelope(
59 self, code, message, details, error);
60 }
61
62 GBytes* fl_method_codec_encode_response(FlMethodCodec* self,
63 FlMethodResponse* response,
64 GError** error) {
65 g_return_val_if_fail(FL_IS_METHOD_CODEC(self), nullptr);
66 g_return_val_if_fail(FL_IS_METHOD_SUCCESS_RESPONSE(response) ||
67 FL_IS_METHOD_ERROR_RESPONSE(response) ||
68 FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response),
69 nullptr);
70
71 if (FL_IS_METHOD_SUCCESS_RESPONSE(response)) {
72 FlMethodSuccessResponse* r = FL_METHOD_SUCCESS_RESPONSE(response);
73 return fl_method_codec_encode_success_envelope(
74 self, fl_method_success_response_get_result(r), error);
75 } else if (FL_IS_METHOD_ERROR_RESPONSE(response)) {
76 FlMethodErrorResponse* r = FL_METHOD_ERROR_RESPONSE(response);
77 return fl_method_codec_encode_error_envelope(
78 self, fl_method_error_response_get_code(r),
79 fl_method_error_response_get_message(r),
80 fl_method_error_response_get_details(r), error);
81 } else if (FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response)) {
82 return g_bytes_new(nullptr, 0);
83 } else {
84 g_assert_not_reached();
85 }
86 }
87
88 FlMethodResponse* fl_method_codec_decode_response(FlMethodCodec* self,
89 GBytes* message,
90 GError** error) {
91 g_return_val_if_fail(FL_IS_METHOD_CODEC(self), nullptr);
92 g_return_val_if_fail(message != nullptr, nullptr);
93
94 if (g_bytes_get_size(message) == 0) {
95 return FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
96 }
97
98 return FL_METHOD_CODEC_GET_CLASS(self)->decode_response(self, message, error);
99 }
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
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
fl_method_codec_encode_success_envelope
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
Definition: fl_method_codec.cc:41
fl_method_codec_encode_response
GBytes * fl_method_codec_encode_response(FlMethodCodec *self, FlMethodResponse *response, GError **error)
Definition: fl_method_codec.cc:62
fl_method_codec_encode_error_envelope
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
Definition: fl_method_codec.cc:50
fl_method_codec_init
static void fl_method_codec_init(FlMethodCodec *self)
Definition: fl_method_codec.cc:14
fl_method_codec_class_init
static void fl_method_codec_class_init(FlMethodCodecClass *klass)
Definition: fl_method_codec.cc:12
fl_method_codec_encode_method_call
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
Definition: fl_method_codec.cc:16
fl_method_codec_decode_method_call
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
Definition: fl_method_codec.cc:27
fl_method_codec_decode_response
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
Definition: fl_method_codec.cc:88
fl_method_codec.h
fl_method_codec_private.h
fl_method_error_response_get_code
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:160
fl_method_error_response_get_message
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:166
fl_method_success_response_get_result
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
Definition: fl_method_response.cc:138
fl_method_not_implemented_response_new
G_MODULE_EXPORT FlMethodNotImplementedResponse * fl_method_not_implemented_response_new()
Definition: fl_method_response.cc:179
fl_method_error_response_get_details
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)
Definition: fl_method_response.cc:172
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42