| Flutter iOS Embedder |

Classes | Instance Methods | Class Methods | List of all members
flutter::PlatformMessageHandlerIos Class Reference

`#import <platform_message_handler_ios.h>`

Inheritance diagram for flutter::PlatformMessageHandlerIos:

## Classes
struct | HandlerInfo

## Instance Methods
() | - PlatformMessageHandlerIos
(void) | - HandlePlatformMessage
(bool) | - DoesHandlePlatformMessageOnPlatformThread
(void) | - InvokePlatformMessageResponseCallback
(void) | - InvokePlatformMessageEmptyResponseCallback
(void) | - SetMessageHandler

## Class Methods
(static NSObject< FlutterTaskQueue > *) | + MakeBackgroundTaskQueue

## Detailed Description

Definition at line 22 of file platform_message_handler_ios.h.

## Constructor & Destructor Documentation

## ◆ PlatformMessageHandlerIos

- PlatformMessageHandlerIos: |  | (fml::RefPtr< fml::TaskRunner >) | platform_task_runner |

Definition at line 43 of file platform_message_handler_ios.mm.

45 : platform_task_runner_(std::move(platform_task_runner)) {}

## Method Documentation

## ◆ DoesHandlePlatformMessageOnPlatformThread

- (bool) PlatformMessageHandlerIos: |  |  | const

Definition at line 99 of file platform_message_handler_ios.mm.

99 {
100 return false;
101 }

## ◆ HandlePlatformMessage

- (void) PlatformMessageHandlerIos: |  | (std::unique_ptr< PlatformMessage >) | message |

Definition at line 47 of file platform_message_handler_ios.mm.

47 {
48 // This can be called from any isolate's thread.
49 @autoreleasepool {
50 fml::RefPtr<flutter::PlatformMessageResponse> completer = message->response();
51 HandlerInfo handler_info;
52 {
53 // TODO(gaaclarke): This mutex is a bottleneck for multiple isolates sending
54 // messages at the same time. This could be potentially changed to a
55 // read-write lock.
56 std::lock_guard lock(message_handlers_mutex_);
57 auto it = message_handlers_.find(message->channel());
58 if (it != message_handlers_.end()) {
59 handler_info = it->second;
60 }
61 }
62 if (handler_info.handler) {
63 FlutterBinaryMessageHandler handler = handler_info.handler;
64 NSData* data = nil;
65 if (message->hasData()) {
66 data = ConvertMappingToNSData(message->releaseData());
67 }
68
69 uint64_t platform_message_id = platform_message_counter++;
70 TRACE_EVENT_ASYNC_BEGIN1("flutter", "PlatformChannel ScheduleHandler", platform_message_id,
71 "channel", message->channel().c_str());
72 dispatch_block_t run_handler = ^{
73 handler(data, ^(NSData* reply) {
74 TRACE_EVENT_ASYNC_END0("flutter", "PlatformChannel ScheduleHandler", platform_message_id);
75 // Called from any thread.
76 if (completer) {
77 if (reply) {
78 completer->Complete(ConvertNSDataToMappingPtr(reply));
79 } else {
80 completer->CompleteEmpty();
81 }
82 }
83 });
84 };
85
86 if (handler_info.task_queue.get()) {
87 [handler_info.task_queue.get() dispatch:run_handler];
88 } else {
89 dispatch_async(dispatch_get_main_queue(), run_handler);
90 }
91 } else {
92 if (completer) {
93 completer->CompleteEmpty();
94 }
95 }
96 }
97 }

References flutter::ConvertMappingToNSData(), flutter::ConvertNSDataToMappingPtr(), flutter::PlatformMessageHandlerIos::HandlerInfo::handler, platform_message_counter, and flutter::PlatformMessageHandlerIos::HandlerInfo::task_queue.

## ◆ InvokePlatformMessageEmptyResponseCallback

- (void) PlatformMessageHandlerIos: |  | (int) | response_id |

Definition at line 111 of file platform_message_handler_ios.mm.

111 {
112 // Called from any thread.
113 // TODO(gaaclarke): This vestigal from the Android implementation, find a way
114 // to migrate this to PlatformMessageHandlerAndroid.
115 }

## ◆ InvokePlatformMessageResponseCallback

- (void) PlatformMessageHandlerIos: |  | (int) | response_id
|  | (std::unique_ptr< fml::Mapping >) | mapping

Definition at line 103 of file platform_message_handler_ios.mm.

105 {
106 // Called from any thread.
107 // TODO(gaaclarke): This vestigal from the Android implementation, find a way
108 // to migrate this to PlatformMessageHandlerAndroid.
109 }

## ◆ MakeBackgroundTaskQueue

+ (NSObject< FlutterTaskQueue > *) PlatformMessageHandlerIos: |  |  |

Definition at line 39 of file platform_message_handler_ios.mm.

39 {
40 return [[[FLTSerialTaskQueue alloc] init] autorelease];
41 }

## ◆ SetMessageHandler

- (void) PlatformMessageHandlerIos: |  | (const std::string &) | channel
|  | (FlutterBinaryMessageHandler) | handler
|  | (NSObject< FlutterTaskQueue > *) | task_queue

TODO(gaaclarke): This should be migrated to a lockfree datastructure.

Definition at line 117 of file platform_message_handler_ios.mm.

119 {
120 FML_CHECK(platform_task_runner_->RunsTasksOnCurrentThread());
121 /// TODO(gaaclarke): This should be migrated to a lockfree datastructure.
122 std::lock_guard lock(message_handlers_mutex_);
123 message_handlers_.erase(channel);
124 if (handler) {
125 message_handlers_[channel] = {
126 .task_queue = fml::scoped_nsprotocol([task_queue retain]),
127 .handler =
128 fml::ScopedBlock<FlutterBinaryMessageHandler>{handler, fml::OwnershipPolicy::kRetain},
129 };
130 }
131 }

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

- shell/platform/darwin/ios/platform_message_handler_ios.h
- shell/platform/darwin/ios/platform_message_handler_ios.mm

flutter::ConvertMappingToNSData
NSData * ConvertMappingToNSData(fml::MallocMapping buffer)
Definition: buffer_conversions.mm:35
platform_message_counter
static uint64_t platform_message_counter
Definition: platform_message_handler_ios.mm:12
FlutterBinaryMessageHandler
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
Definition: FlutterBinaryMessenger.h:30
flutter::ConvertNSDataToMappingPtr
std::unique_ptr< fml::Mapping > ConvertNSDataToMappingPtr(NSData *data)
Definition: buffer_conversions.mm:40
FLTSerialTaskQueue
Definition: platform_message_handler_ios.mm:14