Flutter Engine
platform_message_router.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_router.h"
6 
7 #include <vector>
8 
9 #import "flutter/shell/platform/darwin/common/buffer_conversions.h"
10 
11 namespace flutter {
12 
14 
16 
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 }
42 
43 void PlatformMessageRouter::SetMessageHandler(const std::string& channel,
45  message_handlers_.erase(channel);
46  if (handler) {
47  message_handlers_[channel] =
49  }
50 }
51 
52 } // namespace flutter
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 HandlePlatformMessage(fml::RefPtr< flutter::PlatformMessage > message) const
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
const std::string & channel() const
void SetMessageHandler(const std::string &channel, FlutterBinaryMessageHandler handler)
const fml::RefPtr< PlatformMessageResponse > & response() const
NSData * GetNSDataFromVector(const std::vector< uint8_t > &buffer)