| Flutter macOS Embedder |

FlutterBinaryMessenger.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_FLUTTERBINARYMESSENGER_H_
6 #define FLUTTER_FLUTTERBINARYMESSENGER_H_
7
8 #import <Foundation/Foundation.h>
9
10 #import "FlutterMacros.h"
11
12 NS_ASSUME_NONNULL_BEGIN
13 /**
14 * A message reply callback.
15 *
16 * Used for submitting a binary reply back to a Flutter message sender. Also used
17 * in for handling a binary message reply received from Flutter.
18 *
19 * @param reply The reply.
20 */
21 typedef void (^FlutterBinaryReply)(NSData* _Nullable reply);
22
23 /**
24 * A strategy for handling incoming binary messages from Flutter and to send
25 * asynchronous replies back to Flutter.
26 *
27 * @param message The message.
28 * @param reply A callback for submitting an asynchronous reply to the sender.
29 */
30 typedef void (^FlutterBinaryMessageHandler)(NSData* _Nullable message, FlutterBinaryReply reply);
31
32 typedef int64_t FlutterBinaryMessengerConnection;
33
34 @protocol FlutterTaskQueue;
35
36 /**
37 * A facility for communicating with the Flutter side using asynchronous message
38 * passing with binary messages.
39 *
40 * Implementated by:
41 * - `FlutterBasicMessageChannel`, which supports communication using structured
42 * messages.
43 * - `FlutterMethodChannel`, which supports communication using asynchronous
44 * method calls.
45 * - `FlutterEventChannel`, which supports commuication using event streams.
46 */
47 FLUTTER_DARWIN_EXPORT
48 @protocol FlutterBinaryMessenger <NSObject>
49 /// TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.
50 @optional
51 - (NSObject<FlutterTaskQueue>*)makeBackgroundTaskQueue;
52
53 - (FlutterBinaryMessengerConnection)
54 setMessageHandlerOnChannel:(NSString*)channel
55 binaryMessageHandler:(FlutterBinaryMessageHandler _Nullable)handler
56 taskQueue:(NSObject<FlutterTaskQueue>* _Nullable)taskQueue;
57
58 @required
59 /**
60 * Sends a binary message to the Flutter side on the specified channel, expecting
61 * no reply.
62 *
63 * @param channel The channel name.
64 * @param message The message.
65 */
66 - (void)sendOnChannel:(NSString*)channel message:(NSData* _Nullable)message;
67
68 /**
69 * Sends a binary message to the Flutter side on the specified channel, expecting
70 * an asynchronous reply.
71 *
72 * @param channel The channel name.
73 * @param message The message.
74 * @param callback A callback for receiving a reply.
75 */
76 - (void)sendOnChannel:(NSString*)channel
77 message:(NSData* _Nullable)message
78 binaryReply:(FlutterBinaryReply _Nullable)callback;
79
80 /**
81 * Registers a message handler for incoming binary messages from the Flutter side
82 * on the specified channel.
83 *
84 * Replaces any existing handler. Use a `nil` handler for unregistering the
85 * existing handler.
86 *
87 * @param channel The channel name.
88 * @param handler The message handler.
89 * @return An identifier that represents the connection that was just created to the channel.
90 */
91 - (FlutterBinaryMessengerConnection)setMessageHandlerOnChannel:(NSString*)channel
92 binaryMessageHandler:
93 (FlutterBinaryMessageHandler _Nullable)handler;
94
95 /**
96 * Clears out a channel's message handler if that handler is still the one that
97 * was created as a result of
98 * `setMessageHandlerOnChannel:binaryMessageHandler:`.
99 *
100 * @param connection The result from `setMessageHandlerOnChannel:binaryMessageHandler:`.
101 */
102 - (void)cleanUpConnection:(FlutterBinaryMessengerConnection)connection;
103 @end
104 NS_ASSUME_NONNULL_END
105 #endif // FLUTTER_FLUTTERBINARYMESSENGER_H_
NS_ASSUME_NONNULL_END
#define NS_ASSUME_NONNULL_END
Definition: FlutterMacros.h:20
NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_BEGIN
Definition: FlutterMacros.h:19
FlutterMacros.h
FlutterBinaryMessageHandler
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
Definition: FlutterBinaryMessenger.h:30
-[FlutterBinaryMessenger-p makeBackgroundTaskQueue]
NSObject< FlutterTaskQueue > * makeBackgroundTaskQueue()
TODO(gaaclarke): Remove optional when macos supports Background Platform Channels.
FlutterTaskQueue-p
Definition: FlutterBinaryMessengerRelayTest.mm:16
FLUTTER_DARWIN_EXPORT
#define FLUTTER_DARWIN_EXPORT
Definition: FlutterMacros.h:14
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:48
FlutterBinaryMessengerConnection
int64_t FlutterBinaryMessengerConnection
Definition: FlutterBinaryMessenger.h:32
FlutterBinaryReply
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)