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 
18  std::unique_ptr<flutter::PlatformMessage> message) const {
19  fml::RefPtr<flutter::PlatformMessageResponse> completer = message->response();
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 = ConvertMappingToNSData(message->releaseData());
26  }
27  handler(data, ^(NSData* reply) {
28  if (completer) {
29  if (reply) {
30  completer->Complete(ConvertNSDataToMappingPtr(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
void HandlePlatformMessage(std::unique_ptr< flutter::PlatformMessage > message) const
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
std::unique_ptr< fml::Mapping > ConvertNSDataToMappingPtr(NSData *data)
void SetMessageHandler(const std::string &channel, FlutterBinaryMessageHandler handler)
NSData * ConvertMappingToNSData(fml::MallocMapping buffer)