Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
flutter::PlatformMessageHandlerIos Class Reference

#include <platform_message_handler_ios.h>

Inheritance diagram for flutter::PlatformMessageHandlerIos:
flutter::PlatformMessageHandler

Classes

struct  HandlerInfo
 

Public Member Functions

 PlatformMessageHandlerIos (fml::RefPtr< fml::TaskRunner > platform_task_runner)
 
void HandlePlatformMessage (std::unique_ptr< PlatformMessage > message) override
 
bool DoesHandlePlatformMessageOnPlatformThread () const override
 
void InvokePlatformMessageResponseCallback (int response_id, std::unique_ptr< fml::Mapping > mapping) override
 
void InvokePlatformMessageEmptyResponseCallback (int response_id) override
 
void SetMessageHandler (const std::string &channel, FlutterBinaryMessageHandler handler, NSObject< FlutterTaskQueue > *task_queue)
 
- Public Member Functions inherited from flutter::PlatformMessageHandler
virtual ~PlatformMessageHandler ()=default
 

Static Public Member Functions

static NSObject< FlutterTaskQueue > * MakeBackgroundTaskQueue ()
 

Detailed Description

Definition at line 19 of file platform_message_handler_ios.h.

Constructor & Destructor Documentation

◆ PlatformMessageHandlerIos()

flutter::PlatformMessageHandlerIos::PlatformMessageHandlerIos ( fml::RefPtr< fml::TaskRunner platform_task_runner)
explicit

Definition at line 43 of file platform_message_handler_ios.mm.

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

Member Function Documentation

◆ DoesHandlePlatformMessageOnPlatformThread()

bool flutter::PlatformMessageHandlerIos::DoesHandlePlatformMessageOnPlatformThread ( ) const
overridevirtual

Returns true if the platform message will ALWAYS be dispatched to the platform thread.

Platforms that support Background Platform Channels will return false.

Implements flutter::PlatformMessageHandler.

Definition at line 99 of file platform_message_handler_ios.mm.

99 {
100 return false;
101}

◆ HandlePlatformMessage()

void flutter::PlatformMessageHandlerIos::HandlePlatformMessage ( std::unique_ptr< PlatformMessage message)
overridevirtual

Ultimately sends the PlatformMessage to the host platform. This method is invoked on the ui thread.

Implements flutter::PlatformMessageHandler.

Definition at line 47 of file platform_message_handler_ios.mm.

47 {
48 // This can be called from any isolate's thread.
49 @autoreleasepool {
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}
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
Win32Message message
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
std::unique_ptr< fml::Mapping > ConvertNSDataToMappingPtr(NSData *data)
NSData * ConvertMappingToNSData(fml::MallocMapping buffer)
static std::atomic< uint64_t > platform_message_counter
#define TRACE_EVENT_ASYNC_BEGIN1(category_group, name, id, arg1_name, arg1_val)
#define TRACE_EVENT_ASYNC_END0(category_group, name, id)

◆ InvokePlatformMessageEmptyResponseCallback()

void flutter::PlatformMessageHandlerIos::InvokePlatformMessageEmptyResponseCallback ( int  response_id)
overridevirtual

Performs the return procedure for an associated call to HandlePlatformMessage where there is no return value. This method should be thread-safe and able to be invoked on any thread.

Implements flutter::PlatformMessageHandler.

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 flutter::PlatformMessageHandlerIos::InvokePlatformMessageResponseCallback ( int  response_id,
std::unique_ptr< fml::Mapping mapping 
)
overridevirtual

Performs the return procedure for an associated call to HandlePlatformMessage. This method should be thread-safe and able to be invoked on any thread.

Implements flutter::PlatformMessageHandler.

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 > * flutter::PlatformMessageHandlerIos::MakeBackgroundTaskQueue ( )
static

Definition at line 39 of file platform_message_handler_ios.mm.

39 {
40 return [[[FLTSerialTaskQueue alloc] init] autorelease];
41}
init(device_serial, adb_binary)
Definition _adb_path.py:12

◆ SetMessageHandler()

void flutter::PlatformMessageHandlerIos::SetMessageHandler ( 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 // Use `respondsToSelector` instead of `conformsToProtocol` to accomodate
122 // injecting your own `FlutterTaskQueue`. This is not a supported usage but
123 // not one worth breaking.
124 FML_CHECK(!task_queue || [task_queue respondsToSelector:@selector(dispatch:)]);
125 /// TODO(gaaclarke): This should be migrated to a lockfree datastructure.
126 std::lock_guard lock(message_handlers_mutex_);
127 message_handlers_.erase(channel);
128 if (handler) {
129 message_handlers_[channel] = {
130 .task_queue = fml::scoped_nsprotocol(
131 [static_cast<NSObject<FlutterTaskQueueDispatch>*>(task_queue) retain]),
132 .handler =
135 };
136 }
137}
virtual bool RunsTasksOnCurrentThread()
#define FML_CHECK(condition)
Definition logging.h:85

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