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