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 61 of file core_implementations.cc.

References ~BinaryMessengerImpl().

63  : 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 67 of file core_implementations.cc.

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

70  {
71  if (reply == nullptr) {
72  FlutterDesktopMessengerSend(messenger_, channel.c_str(), message,
73  message_size);
74  return;
75  }
76  struct Captures {
77  BinaryReply reply;
78  };
79  auto captures = new Captures();
80  captures->reply = reply;
81 
82  auto message_reply = [](const uint8_t* data, size_t data_size,
83  void* user_data) {
84  auto captures = reinterpret_cast<Captures*>(user_data);
85  captures->reply(data, data_size);
86  delete captures;
87  };
89  messenger_, channel.c_str(), message, message_size, message_reply,
90  captures);
91  if (!result) {
92  delete captures;
93  }
94 }
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)
G_BEGIN_DECLS FlValue gpointer 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 96 of file core_implementations.cc.

References FlutterDesktopMessengerSetCallback().

97  {
98  if (!handler) {
99  handlers_.erase(channel);
100  FlutterDesktopMessengerSetCallback(messenger_, channel.c_str(), nullptr,
101  nullptr);
102  return;
103  }
104  // Save the handler, to keep it alive.
105  handlers_[channel] = std::move(handler);
106  BinaryMessageHandler* message_handler = &handlers_[channel];
107  // Set an adaptor callback that will invoke the handler.
108  FlutterDesktopMessengerSetCallback(messenger_, channel.c_str(),
109  ForwardToHandler, message_handler);
110 }
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: