| Flutter macOS Embedder |

binary_messenger.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_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BINARY_MESSENGER_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BINARY_MESSENGER_H_
7
8 #include <functional>
9 #include <string>
10
11 namespace flutter {
12
13 // A binary message reply callback.
14 //
15 // Used for submitting a binary reply back to a Flutter message sender.
16 typedef std::function<void(const uint8_t* reply, size_t reply_size)>
17 BinaryReply;
18
19 // A message handler callback.
20 //
21 // Used for receiving messages from Flutter and providing an asynchronous reply.
22 typedef std::function<
23 void(const uint8_t* message, size_t message_size, BinaryReply reply)>
24 BinaryMessageHandler;
25
26 // A protocol for a class that handles communication of binary data on named
27 // channels to and from the Flutter engine.
28 class BinaryMessenger {
29 public:
30 virtual ~BinaryMessenger() = default;
31
32 // Sends a binary message to the Flutter engine on the specified channel.
33 //
34 // If |reply| is provided, it will be called back with the response from the
35 // engine.
36 virtual void Send(const std::string& channel,
37 const uint8_t* message,
38 size_t message_size,
39 BinaryReply reply = nullptr) const = 0;
40
41 // Registers a message handler for incoming binary messages from the Flutter
42 // side on the specified channel.
43 //
44 // Replaces any existing handler. Provide a null handler to unregister the
45 // existing handler.
46 virtual void SetMessageHandler(const std::string& channel,
47 BinaryMessageHandler handler) = 0;
48 };
49
50 } // namespace flutter
51
52 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BINARY_MESSENGER_H_
flutter::BinaryMessenger
Definition: binary_messenger.h:28
flutter::BinaryMessenger::~BinaryMessenger
virtual ~BinaryMessenger()=default
flutter::BinaryMessenger::Send
virtual void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply=nullptr) const =0
flutter::BinaryMessenger::SetMessageHandler
virtual void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler)=0
flutter
Definition: AccessibilityBridgeMac.h:16
flutter::BinaryMessageHandler
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
Definition: binary_messenger.h:24
flutter::BinaryReply
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
Definition: binary_messenger.h:17