Flutter Engine
flutter::PlatformMessageRouter Class Reference

#include <platform_message_router.h>

Public Member Functions

 PlatformMessageRouter ()
 
 ~PlatformMessageRouter ()
 
void HandlePlatformMessage (fml::RefPtr< flutter::PlatformMessage > message) const
 
void SetMessageHandler (const std::string &channel, FlutterBinaryMessageHandler handler)
 

Detailed Description

Definition at line 17 of file platform_message_router.h.

Constructor & Destructor Documentation

◆ PlatformMessageRouter()

flutter::PlatformMessageRouter::PlatformMessageRouter ( )
default

◆ ~PlatformMessageRouter()

flutter::PlatformMessageRouter::~PlatformMessageRouter ( )
default

Member Function Documentation

◆ HandlePlatformMessage()

void flutter::PlatformMessageRouter::HandlePlatformMessage ( fml::RefPtr< flutter::PlatformMessage message) const

Definition at line 17 of file platform_message_router.mm.

References flutter::PlatformMessage::channel(), flutter::PlatformMessageResponse::Complete(), flutter::PlatformMessageResponse::CompleteEmpty(), flutter::PlatformMessage::data(), flutter::GetMappingFromNSData(), flutter::GetNSDataFromVector(), flutter::PlatformMessage::hasData(), and flutter::PlatformMessage::response().

Referenced by flutter::PlatformViewIOS::GetPlatformMessageRouter().

18  {
20  auto it = message_handlers_.find(message->channel());
21  if (it != message_handlers_.end()) {
22  FlutterBinaryMessageHandler handler = it->second;
23  NSData* data = nil;
24  if (message->hasData()) {
25  data = GetNSDataFromVector(message->data());
26  }
27  handler(data, ^(NSData* reply) {
28  if (completer) {
29  if (reply) {
30  completer->Complete(GetMappingFromNSData(reply));
31  } else {
32  completer->CompleteEmpty();
33  }
34  }
35  });
36  } else {
37  if (completer) {
38  completer->CompleteEmpty();
39  }
40  }
41 }
virtual void Complete(std::unique_ptr< fml::Mapping > data)=0
std::unique_ptr< fml::Mapping > GetMappingFromNSData(NSData *data)
const std::vector< uint8_t > & data() const
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
const std::string & channel() const
const fml::RefPtr< PlatformMessageResponse > & response() const
NSData * GetNSDataFromVector(const std::vector< uint8_t > &buffer)

◆ SetMessageHandler()

void flutter::PlatformMessageRouter::SetMessageHandler ( const std::string &  channel,
FlutterBinaryMessageHandler  handler 
)

Definition at line 43 of file platform_message_router.mm.

References fml::Retain.

44  {
45  message_handlers_.erase(channel);
46  if (handler) {
47  message_handlers_[channel] =
49  }
50 }

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