Flutter Engine
flutter::BasicMessageChannel< T > Class Template Reference

#include <basic_message_channel.h>

Public Member Functions

 BasicMessageChannel (BinaryMessenger *messenger, const std::string &name, const MessageCodec< T > *codec)
 
 ~BasicMessageChannel ()=default
 
 BasicMessageChannel (BasicMessageChannel const &)=delete
 
BasicMessageChanneloperator= (BasicMessageChannel const &)=delete
 
void Send (const T &message)
 
void Send (const T &message, BinaryReply reply)
 
void SetMessageHandler (const MessageHandler< T > &handler) const
 

Detailed Description

template<typename T = EncodableValue>
class flutter::BasicMessageChannel< T >

Definition at line 35 of file basic_message_channel.h.

Constructor & Destructor Documentation

◆ BasicMessageChannel() [1/2]

template<typename T = EncodableValue>
flutter::BasicMessageChannel< T >::BasicMessageChannel ( BinaryMessenger messenger,
const std::string &  name,
const MessageCodec< T > *  codec 
)
inline

Definition at line 39 of file basic_message_channel.h.

References flutter::BasicMessageChannel< T >::operator=(), and flutter::BasicMessageChannel< T >::~BasicMessageChannel().

42  : messenger_(messenger), name_(name), codec_(codec) {}
const char * name
Definition: fuchsia.cc:50

◆ ~BasicMessageChannel()

template<typename T = EncodableValue>
flutter::BasicMessageChannel< T >::~BasicMessageChannel ( )
default

◆ BasicMessageChannel() [2/2]

template<typename T = EncodableValue>
flutter::BasicMessageChannel< T >::BasicMessageChannel ( BasicMessageChannel< T > const &  )
delete

Member Function Documentation

◆ operator=()

template<typename T = EncodableValue>
BasicMessageChannel& flutter::BasicMessageChannel< T >::operator= ( BasicMessageChannel< T > const &  )
delete

◆ Send() [1/2]

template<typename T = EncodableValue>
void flutter::BasicMessageChannel< T >::Send ( const T &  message)
inline

Definition at line 51 of file basic_message_channel.h.

References flutter::BinaryMessenger::Send().

51  {
52  std::unique_ptr<std::vector<uint8_t>> raw_message =
53  codec_->EncodeMessage(message);
54  messenger_->Send(name_, raw_message->data(), raw_message->size());
55  }
virtual void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply=nullptr) const =0

◆ Send() [2/2]

template<typename T = EncodableValue>
void flutter::BasicMessageChannel< T >::Send ( const T &  message,
BinaryReply  reply 
)
inline

Definition at line 58 of file basic_message_channel.h.

References flutter::BinaryMessenger::Send().

58  {
59  std::unique_ptr<std::vector<uint8_t>> raw_message =
60  codec_->EncodeMessage(message);
61  messenger_->Send(name_, raw_message->data(), raw_message->size(), reply);
62  }
virtual void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply=nullptr) const =0

◆ SetMessageHandler()

template<typename T = EncodableValue>
void flutter::BasicMessageChannel< T >::SetMessageHandler ( const MessageHandler< T > &  handler) const
inline

Definition at line 70 of file basic_message_channel.h.

References flutter::BinaryMessenger::SetMessageHandler().

Referenced by flutter::TEST().

70  {
71  if (!handler) {
72  messenger_->SetMessageHandler(name_, nullptr);
73  return;
74  }
75  const auto* codec = codec_;
76  std::string channel_name = name_;
77  BinaryMessageHandler binary_handler = [handler, codec, channel_name](
78  const uint8_t* binary_message,
79  const size_t binary_message_size,
80  BinaryReply binary_reply) {
81  // Use this channel's codec to decode the message and build a reply
82  // handler.
83  std::unique_ptr<T> message =
84  codec->DecodeMessage(binary_message, binary_message_size);
85  if (!message) {
86  std::cerr << "Unable to decode message on channel " << channel_name
87  << std::endl;
88  binary_reply(nullptr, 0);
89  return;
90  }
91 
92  MessageReply<T> unencoded_reply = [binary_reply,
93  codec](const T& unencoded_response) {
94  auto binary_response = codec->EncodeMessage(unencoded_response);
95  binary_reply(binary_response->data(), binary_response->size());
96  };
97  handler(*message, std::move(unencoded_reply));
98  };
99  messenger_->SetMessageHandler(name_, std::move(binary_handler));
100  }
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
virtual void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler)=0
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler

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