Flutter iOS Embedder
platform_message_handler_ios.h
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 #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_MESSAGE_HANDLER_IOS_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_MESSAGE_HANDLER_IOS_H_
7 
8 #include <unordered_map>
9 
10 #include "flutter/common/task_runners.h"
11 #include "flutter/fml/platform/darwin/scoped_block.h"
12 #include "flutter/fml/platform/darwin/scoped_nsobject.h"
13 #include "flutter/shell/common/platform_message_handler.h"
15 
17 - (void)dispatch:(dispatch_block_t)block;
18 @end
19 
20 namespace flutter {
21 
22 class PlatformMessageHandlerIos : public PlatformMessageHandler {
23  public:
24  static NSObject<FlutterTaskQueue>* MakeBackgroundTaskQueue();
25 
26  PlatformMessageHandlerIos(fml::RefPtr<fml::TaskRunner> platform_task_runner);
27 
28  void HandlePlatformMessage(std::unique_ptr<PlatformMessage> message) override;
29 
30  bool DoesHandlePlatformMessageOnPlatformThread() const override;
31 
32  void InvokePlatformMessageResponseCallback(int response_id,
33  std::unique_ptr<fml::Mapping> mapping) override;
34 
35  void InvokePlatformMessageEmptyResponseCallback(int response_id) override;
36 
37  void SetMessageHandler(const std::string& channel,
39  NSObject<FlutterTaskQueue>* task_queue);
40 
41  struct HandlerInfo {
42  fml::scoped_nsprotocol<NSObject<FlutterTaskQueue>*> task_queue;
43  fml::ScopedBlock<FlutterBinaryMessageHandler> handler;
44  };
45 
46  private:
47  std::unordered_map<std::string, HandlerInfo> message_handlers_;
48  const fml::RefPtr<fml::TaskRunner> platform_task_runner_;
49  std::mutex message_handlers_mutex_;
50  FML_DISALLOW_COPY_AND_ASSIGN(PlatformMessageHandlerIos);
51 };
52 
53 } // namespace flutter
54 
55 #endif
flutter::PlatformMessageHandlerIos::HandlerInfo::handler
fml::ScopedBlock< FlutterBinaryMessageHandler > handler
Definition: platform_message_handler_ios.h:43
-[flutter::PlatformMessageHandlerIos InvokePlatformMessageResponseCallback]
void InvokePlatformMessageResponseCallback(int response_id, std::unique_ptr< fml::Mapping > mapping) override
Definition: platform_message_handler_ios.mm:103
flutter::PlatformMessageHandlerIos
Definition: platform_message_handler_ios.h:22
+[flutter::PlatformMessageHandlerIos MakeBackgroundTaskQueue]
static NSObject< FlutterTaskQueue > * MakeBackgroundTaskQueue()
Definition: platform_message_handler_ios.mm:39
-[flutter::PlatformMessageHandlerIos DoesHandlePlatformMessageOnPlatformThread]
bool DoesHandlePlatformMessageOnPlatformThread() const override
Definition: platform_message_handler_ios.mm:99
flutter::PlatformMessageHandlerIos::HandlerInfo
Definition: platform_message_handler_ios.h:41
-[flutter::PlatformMessageHandlerIos HandlePlatformMessage]
void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message) override
Definition: platform_message_handler_ios.mm:47
-[flutter::PlatformMessageHandlerIos InvokePlatformMessageEmptyResponseCallback]
void InvokePlatformMessageEmptyResponseCallback(int response_id) override
Definition: platform_message_handler_ios.mm:111
FlutterBinaryMessageHandler
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
Definition: FlutterBinaryMessenger.h:30
flutter::PlatformMessageHandlerIos::HandlerInfo::task_queue
fml::scoped_nsprotocol< NSObject< FlutterTaskQueue > * > task_queue
Definition: platform_message_handler_ios.h:42
flutter
Definition: accessibility_bridge.h:28
FlutterBinaryMessenger.h
FlutterTaskQueue-p
Definition: platform_message_handler_ios.h:16
-[flutter::PlatformMessageHandlerIos SetMessageHandler]
void SetMessageHandler(const std::string &channel, FlutterBinaryMessageHandler handler, NSObject< FlutterTaskQueue > *task_queue)
Definition: platform_message_handler_ios.mm:117
-[flutter::PlatformMessageHandlerIos PlatformMessageHandlerIos]
PlatformMessageHandlerIos(fml::RefPtr< fml::TaskRunner > platform_task_runner)
Definition: platform_message_handler_ios.mm:43