Flutter Engine
flutter::BinaryMessengerImpl Class Reference

#include <binary_messenger_impl.h>

Inheritance diagram for flutter::BinaryMessengerImpl:
flutter::BinaryMessenger

Public Member Functions

 BinaryMessengerImpl (FlutterDesktopMessengerRef core_messenger)
 
virtual ~BinaryMessengerImpl ()
 
 BinaryMessengerImpl (BinaryMessengerImpl const &)=delete
 
BinaryMessengerImploperator= (BinaryMessengerImpl const &)=delete
 
void Send (const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply) const override
 
void SetMessageHandler (const std::string &channel, BinaryMessageHandler handler) override
 
- Public Member Functions inherited from flutter::BinaryMessenger
virtual ~BinaryMessenger ()=default
 

Detailed Description

Definition at line 19 of file binary_messenger_impl.h.

Constructor & Destructor Documentation

◆ BinaryMessengerImpl() [1/2]

flutter::BinaryMessengerImpl::BinaryMessengerImpl ( FlutterDesktopMessengerRef  core_messenger)
explicit

Definition at line 63 of file core_implementations.cc.

References ~BinaryMessengerImpl().

65  : messenger_(core_messenger) {}

◆ ~BinaryMessengerImpl()

flutter::BinaryMessengerImpl::~BinaryMessengerImpl ( )
virtualdefault

Referenced by BinaryMessengerImpl().

◆ BinaryMessengerImpl() [2/2]

flutter::BinaryMessengerImpl::BinaryMessengerImpl ( BinaryMessengerImpl const &  )
delete

Member Function Documentation

◆ operator=()

BinaryMessengerImpl& flutter::BinaryMessengerImpl::operator= ( BinaryMessengerImpl const &  )
delete

◆ Send()

void flutter::BinaryMessengerImpl::Send ( const std::string &  channel,
const uint8_t *  message,
size_t  message_size,
BinaryReply  reply 
) const
overridevirtual

Implements flutter::BinaryMessenger.

Definition at line 69 of file core_implementations.cc.

References FlutterDesktopMessengerSend(), FlutterDesktopMessengerSendWithReply(), result, and user_data.

72  {
73  if (reply == nullptr) {
74  FlutterDesktopMessengerSend(messenger_, channel.c_str(), message,
75  message_size);
76  return;
77  }
78  struct Captures {
79  BinaryReply reply;
80  };
81  auto captures = new Captures();
82  captures->reply = reply;
83 
84  auto message_reply = [](const uint8_t* data, size_t data_size,
85  void* user_data) {
86  auto captures = reinterpret_cast<Captures*>(user_data);
87  captures->reply(data, data_size);
88  delete captures;
89  };
91  messenger_, channel.c_str(), message, message_size, message_reply,
92  captures);
93  if (!result) {
94  delete captures;
95  }
96 }
void * user_data
GAsyncResult * result
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size)

◆ SetMessageHandler()

void flutter::BinaryMessengerImpl::SetMessageHandler ( const std::string &  channel,
BinaryMessageHandler  handler 
)
overridevirtual

Implements flutter::BinaryMessenger.

Definition at line 98 of file core_implementations.cc.

References FlutterDesktopMessengerSetCallback().

99  {
100  if (!handler) {
101  handlers_.erase(channel);
102  FlutterDesktopMessengerSetCallback(messenger_, channel.c_str(), nullptr,
103  nullptr);
104  return;
105  }
106  // Save the handler, to keep it alive.
107  handlers_[channel] = std::move(handler);
108  BinaryMessageHandler* message_handler = &handlers_[channel];
109  // Set an adaptor callback that will invoke the handler.
110  FlutterDesktopMessengerSetCallback(messenger_, channel.c_str(),
111  ForwardToHandler, message_handler);
112 }
void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, const char *channel, FlutterDesktopMessageCallback callback, void *user_data)
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler

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