Flutter Engine
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 // Added here to stop the compiler from optimising this function away.
11 G_MODULE_EXPORT GType fl_method_codec_get_type();
12 
13 G_DEFINE_TYPE(FlMethodCodec, fl_method_codec, G_TYPE_OBJECT)
14 
15 static void fl_method_codec_class_init(FlMethodCodecClass* klass) {}
16 
17 static void fl_method_codec_init(FlMethodCodec* self) {}
18 
19 GBytes* fl_method_codec_encode_method_call(FlMethodCodec* self,
20  const gchar* name,
21  FlValue* args,
22  GError** error) {
23  g_return_val_if_fail(FL_IS_METHOD_CODEC(self), nullptr);
24  g_return_val_if_fail(name != nullptr, nullptr);
25 
26  return FL_METHOD_CODEC_GET_CLASS(self)->encode_method_call(self, name, args,
27  error);
28 }
29 
30 gboolean fl_method_codec_decode_method_call(FlMethodCodec* self,
31  GBytes* message,
32  gchar** name,
33  FlValue** args,
34  GError** error) {
35  g_return_val_if_fail(FL_IS_METHOD_CODEC(self), FALSE);
36  g_return_val_if_fail(message != nullptr, FALSE);
37  g_return_val_if_fail(name != nullptr, FALSE);
38  g_return_val_if_fail(args != nullptr, FALSE);
39 
40  return FL_METHOD_CODEC_GET_CLASS(self)->decode_method_call(self, message,
41  name, args, error);
42 }
43 
44 GBytes* fl_method_codec_encode_success_envelope(FlMethodCodec* self,
45  FlValue* result,
46  GError** error) {
47  g_return_val_if_fail(FL_IS_METHOD_CODEC(self), nullptr);
48 
49  return FL_METHOD_CODEC_GET_CLASS(self)->encode_success_envelope(self, result,
50  error);
51 }
52 
53 GBytes* fl_method_codec_encode_error_envelope(FlMethodCodec* self,
54  const gchar* code,
55  const gchar* message,
56  FlValue* details,
57  GError** error) {
58  g_return_val_if_fail(FL_IS_METHOD_CODEC(self), nullptr);
59  g_return_val_if_fail(code != nullptr, nullptr);
60 
61  return FL_METHOD_CODEC_GET_CLASS(self)->encode_error_envelope(
62  self, code, message, details, error);
63 }
64 
65 FlMethodResponse* fl_method_codec_decode_response(FlMethodCodec* self,
66  GBytes* message,
67  GError** error) {
68  g_return_val_if_fail(FL_IS_METHOD_CODEC(self), nullptr);
69  g_return_val_if_fail(message != nullptr, nullptr);
70 
71  if (g_bytes_get_size(message) == 0) {
72  return FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
73  }
74 
75  return FL_METHOD_CODEC_GET_CLASS(self)->decode_response(self, message, error);
76 }
G_BEGIN_DECLS FlValue * args
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
static void fl_method_codec_class_init(FlMethodCodecClass *klass)
static void fl_method_codec_init(FlMethodCodec *self)
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
const char * name
Definition: fuchsia.cc:50
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_MODULE_EXPORT FlMethodNotImplementedResponse * fl_method_not_implemented_response_new()
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
G_MODULE_EXPORT GType fl_method_codec_get_type()
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)