forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflutter_messenger.h
More file actions
94 lines (79 loc) · 3.24 KB
/
flutter_messenger.h
File metadata and controls
94 lines (79 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_MESSENGER_H_
#define FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_MESSENGER_H_
#include <stddef.h>
#include <stdint.h>
#include "flutter_export.h"
#if defined(__cplusplus)
extern "C" {
#endif // defined(__cplusplus)
// Opaque reference to a Flutter engine messenger.
typedef struct FlutterDesktopMessenger* FlutterDesktopMessengerRef;
// Opaque handle for tracking responses to messages.
typedef struct _FlutterPlatformMessageResponseHandle
FlutterDesktopMessageResponseHandle;
// The callback expected as a response of a binary message.
typedef void (*FlutterDesktopBinaryReply)(const uint8_t* data,
size_t data_size,
void* user_data);
// A message received from Flutter.
typedef struct {
// Size of this struct as created by Flutter.
size_t struct_size;
// The name of the channel used for this message.
const char* channel;
// The raw message data.
const uint8_t* message;
// The length of |message|.
size_t message_size;
// The response handle. If non-null, the receiver of this message must call
// FlutterDesktopSendMessageResponse exactly once with this handle.
const FlutterDesktopMessageResponseHandle* response_handle;
} FlutterDesktopMessage;
// Function pointer type for message handler callback registration.
//
// The user data will be whatever was passed to FlutterDesktopSetMessageHandler
// for the channel the message is received on.
typedef void (*FlutterDesktopMessageCallback)(
FlutterDesktopMessengerRef /* messenger */,
const FlutterDesktopMessage* /* message*/,
void* /* user data */);
// Sends a binary message to the Flutter side on the specified channel.
FLUTTER_EXPORT bool FlutterDesktopMessengerSend(
FlutterDesktopMessengerRef messenger,
const char* channel,
const uint8_t* message,
const size_t message_size);
FLUTTER_EXPORT bool FlutterDesktopMessengerSendWithReply(
FlutterDesktopMessengerRef messenger,
const char* channel,
const uint8_t* message,
const size_t message_size,
const FlutterDesktopBinaryReply reply,
void* user_data);
// Sends a reply to a FlutterDesktopMessage for the given response handle.
//
// Once this has been called, |handle| is invalid and must not be used again.
FLUTTER_EXPORT void FlutterDesktopMessengerSendResponse(
FlutterDesktopMessengerRef messenger,
const FlutterDesktopMessageResponseHandle* handle,
const uint8_t* data,
size_t data_length);
// Registers a callback function for incoming binary messages from the Flutter
// side on the specified channel.
//
// Replaces any existing callback. Provide a null handler to unregister the
// existing callback.
//
// If |user_data| is provided, it will be passed in |callback| calls.
FLUTTER_EXPORT void FlutterDesktopMessengerSetCallback(
FlutterDesktopMessengerRef messenger,
const char* channel,
FlutterDesktopMessageCallback callback,
void* user_data);
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_MESSENGER_H_