| Flutter Linux Embedder |

Public Member Functions | List of all members
flutter::MethodChannel< T > Class Template Reference

`#include <method_channel.h>`

## Public Member Functions
| MethodChannel (BinaryMessenger *messenger, const std::string &name, const MethodCodec< T > *codec)
| ~MethodChannel ()=default
| MethodChannel (MethodChannel const &)=delete
MethodChannel & | operator= (MethodChannel const &)=delete
void | InvokeMethod (const std::string &method, std::unique_ptr< T > arguments, std::unique_ptr< MethodResult< T >> result=nullptr)
void | SetMethodCallHandler (MethodCallHandler< T > handler) const

## Detailed Description

### template<typename T = EncodableValue>
class flutter::MethodChannel< T >

Definition at line 33 of file method_channel.h.

## Constructor & Destructor Documentation

## ◆ MethodChannel() [1/2]

template<typename T = EncodableValue>

flutter::MethodChannel< T >::MethodChannel | ( | BinaryMessenger * | messenger,
|  | const std::string & | name,
|  | const MethodCodec< T > * | codec
| ) |  |
| inline

Definition at line 37 of file method_channel.h.

40 : messenger_(messenger), name_(name), codec_(codec) {}

## ◆ ~MethodChannel()

template<typename T = EncodableValue>

flutter::MethodChannel< T >::~MethodChannel | ( |  | ) |
| default

## ◆ MethodChannel() [2/2]

template<typename T = EncodableValue>

flutter::MethodChannel< T >::MethodChannel | ( | MethodChannel< T > const & |  | ) |
| delete

## Member Function Documentation

## ◆ InvokeMethod()

template<typename T = EncodableValue>

void flutter::MethodChannel< T >::InvokeMethod | ( | const std::string & | method,
|  | std::unique_ptr< T > | arguments,
|  | std::unique_ptr< MethodResult< T >> | result = `nullptr`
| ) |  |
| inline

Definition at line 52 of file method_channel.h.

54 {
55 MethodCall<T> method_call(method, std::move(arguments));
56 std::unique_ptr<std::vector<uint8_t>> message =
57 codec_->EncodeMethodCall(method_call);
58 if (!result) {
59 messenger_->Send(name_, message->data(), message->size(), nullptr);
60 return;
61 }
62
63 // std::function requires a copyable lambda, so convert to a shared pointer.
64 // This is safe since only one copy of the shared_pointer will ever be
65 // accessed.
66 std::shared_ptr<MethodResult<T>> shared_result(result.release());
67 const auto* codec = codec_;
68 std::string channel_name = name_;
69 BinaryReply reply_handler = [shared_result, codec, channel_name](
70 const uint8_t* reply, size_t reply_size) {
71 if (reply_size == 0) {
72 shared_result->NotImplemented();
73 return;
74 }
75 // Use this channel's codec to decode and handle the
76 // reply.
77 bool decoded = codec->DecodeAndProcessResponseEnvelope(
78 reply, reply_size, shared_result.get());
79 if (!decoded) {
80 std::cerr << "Unable to decode reply to method "
81 "invocation on channel "
82 << channel_name << std::endl;
83 shared_result->NotImplemented();
84 }
85 };
86
87 messenger_->Send(name_, message->data(), message->size(),
88 std::move(reply_handler));
89 }

References method_call, result, and flutter::BinaryMessenger::Send().

Referenced by flutter::TEST().

## ◆ operator=()

template<typename T = EncodableValue>

MethodChannel& flutter::MethodChannel< T >::operator= | ( | MethodChannel< T > const & |  | ) |
| delete

## ◆ SetMethodCallHandler()

template<typename T = EncodableValue>

void flutter::MethodChannel< T >::SetMethodCallHandler | ( | MethodCallHandler< T > | handler | ) | const
| inline

Definition at line 98 of file method_channel.h.

98 {
99 if (!handler) {
100 messenger_->SetMessageHandler(name_, nullptr);
101 return;
102 }
103 const auto* codec = codec_;
104 std::string channel_name = name_;
105 BinaryMessageHandler binary_handler = [handler, codec, channel_name](
106 const uint8_t* message,
107 size_t message_size,
108 BinaryReply reply) {
109 // Use this channel's codec to decode the call and build a result handler.
110 auto result =
111 std::make_unique<EngineMethodResult<T>>(std::move(reply), codec);
112 std::unique_ptr<MethodCall<T>> method_call =
113 codec->DecodeMethodCall(message, message_size);
114 if (!method_call) {
115 std::cerr << "Unable to construct method call from message on channel "
116 << channel_name << std::endl;
117 result->NotImplemented();
118 return;
119 }
120 handler(*method_call, std::move(result));
121 };
122 messenger_->SetMessageHandler(name_, std::move(binary_handler));
123 }

References method_call, result, and flutter::BinaryMessenger::SetMessageHandler().

Referenced by flutter::TEST().

The documentation for this class was generated from the following file:

- shell/platform/common/client_wrapper/include/flutter/method_channel.h

flutter::BinaryMessenger::SetMessageHandler
virtual void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler)=0
method_call
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
Definition: fl_method_channel.h:120
flutter::BinaryReply
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
Definition: binary_messenger.h:17
result
GAsyncResult * result
Definition: fl_text_input_plugin.cc:106
flutter::BinaryMessenger::Send
virtual void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply=nullptr) const =0
flutter::BinaryMessageHandler
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
Definition: binary_messenger.h:24