Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
io.flutter.plugin.common.BasicMessageChannel< T > Class Template Reference

Classes

interface  MessageHandler
 
interface  Reply
 

Public Member Functions

 BasicMessageChannel ( @NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MessageCodec< T > codec)
 
 BasicMessageChannel ( @NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MessageCodec< T > codec, BinaryMessenger.TaskQueue taskQueue)
 
void send (@Nullable T message)
 
void send (@Nullable T message, @Nullable final Reply< T > callback)
 
void setMessageHandler (@Nullable final MessageHandler< T > handler)
 
void resizeChannelBuffer (int newSize)
 
void setWarnsOnChannelOverflow (boolean warns)
 

Static Public Member Functions

static void resizeChannelBuffer ( @NonNull BinaryMessenger messenger, @NonNull String channel, int newSize)
 
static void setWarnsOnChannelOverflow ( @NonNull BinaryMessenger messenger, @NonNull String channel, boolean warns)
 

Static Public Attributes

static final String CHANNEL_BUFFERS_CHANNEL = "dev.flutter/channel-buffers"
 

Detailed Description

A named channel for communicating with the Flutter application using basic, asynchronous message passing.

Messages are encoded into binary before being sent, and binary messages received are decoded into Java objects. The MessageCodec used must be compatible with the one used by the Flutter application. This can be achieved by creating a BasicMessageChannel counterpart of this channel on the Dart side. The static Java type of messages sent and received is Object, but only values supported by the specified MessageCodec can be used.

The logical identity of the channel is given by its name. Identically named channels will interfere with each other's communication.

Definition at line 31 of file BasicMessageChannel.java.

Constructor & Destructor Documentation

◆ BasicMessageChannel() [1/2]

io.flutter.plugin.common.BasicMessageChannel< T >.BasicMessageChannel ( @NonNull BinaryMessenger  messenger,
@NonNull String  name,
@NonNull MessageCodec< T codec 
)
inline

Creates a new channel associated with the specified BinaryMessenger and with the specified name and MessageCodec.

Parameters
messengera BinaryMessenger.
namea channel name String.
codeca MessageCodec.

Definition at line 48 of file BasicMessageChannel.java.

49 {
50 this(messenger, name, codec, null);
51 }

◆ BasicMessageChannel() [2/2]

io.flutter.plugin.common.BasicMessageChannel< T >.BasicMessageChannel ( @NonNull BinaryMessenger  messenger,
@NonNull String  name,
@NonNull MessageCodec< T codec,
BinaryMessenger.TaskQueue  taskQueue 
)
inline

Creates a new channel associated with the specified BinaryMessenger and with the specified name and MessageCodec.

Parameters
messengera BinaryMessenger.
namea channel name String.
codeca MessageCodec.
taskQueuea BinaryMessenger.TaskQueue that specifies what thread will execute the handler. Specifying null means execute on the platform thread. See also BinaryMessenger#makeBackgroundTaskQueue().

Definition at line 64 of file BasicMessageChannel.java.

68 {
69 if (BuildConfig.DEBUG) {
70 if (messenger == null) {
71 Log.e(TAG, "Parameter messenger must not be null.");
72 }
73 if (name == null) {
74 Log.e(TAG, "Parameter name must not be null.");
75 }
76 if (codec == null) {
77 Log.e(TAG, "Parameter codec must not be null.");
78 }
79 }
80 this.messenger = messenger;
81 this.name = name;
82 this.codec = codec;
83 this.taskQueue = taskQueue;
84 }
void Log(const char *format,...) SK_PRINTF_LIKE(1

Member Function Documentation

◆ resizeChannelBuffer() [1/2]

static void io.flutter.plugin.common.BasicMessageChannel< T >.resizeChannelBuffer ( @NonNull BinaryMessenger  messenger,
@NonNull String  channel,
int  newSize 
)
inlinestatic

Adjusts the number of messages that will get buffered when sending messages to channels that aren't fully set up yet. For example, the engine isn't running yet or the channel's message handler isn't set up on the Dart side yet.

Definition at line 173 of file BasicMessageChannel.java.

174 {
175 final StandardMethodCodec codec = StandardMethodCodec.INSTANCE;
176 Object[] arguments = {channel, newSize};
177 MethodCall methodCall = new MethodCall("resize", Arrays.asList(arguments));
178 ByteBuffer message = codec.encodeMethodCall(methodCall);
179 ByteBuffer packet = packetFromEncodedMessage(message);
180 messenger.send(BasicMessageChannel.CHANNEL_BUFFERS_CHANNEL, packet);
181 }
BasicMessageChannel( @NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MessageCodec< T > codec)
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)
void send(@NonNull String channel, @Nullable ByteBuffer message)
Win32Message message

◆ resizeChannelBuffer() [2/2]

void io.flutter.plugin.common.BasicMessageChannel< T >.resizeChannelBuffer ( int  newSize)
inline

Adjusts the number of messages that will get buffered when sending messages to channels that aren't fully set up yet. For example, the engine isn't running yet or the channel's message handler isn't set up on the Dart side yet.

Definition at line 141 of file BasicMessageChannel.java.

141 {
142 resizeChannelBuffer(messenger, name, newSize);
143 }

◆ send() [1/2]

void io.flutter.plugin.common.BasicMessageChannel< T >.send ( @Nullable T  message)
inline

Sends the specified message to the Flutter application on this channel.

Parameters
messagethe message, possibly null.

Definition at line 91 of file BasicMessageChannel.java.

91 {
92 send(message, null);
93 }

◆ send() [2/2]

void io.flutter.plugin.common.BasicMessageChannel< T >.send ( @Nullable T  message,
@Nullable final Reply< T callback 
)
inline

Sends the specified message to the Flutter application, optionally expecting a reply.

Any uncaught exception thrown by the reply callback will be caught and logged.

Parameters
messagethe message, possibly null.
callbacka Reply callback, possibly null.

Definition at line 104 of file BasicMessageChannel.java.

104 {
105 messenger.send(
106 name,
107 codec.encodeMessage(message),
108 callback == null ? null : new IncomingReplyHandler(callback));
109 }
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ setMessageHandler()

void io.flutter.plugin.common.BasicMessageChannel< T >.setMessageHandler ( @Nullable final MessageHandler< T handler)
inline

Registers a message handler on this channel for receiving messages sent from the Flutter application.

Overrides any existing handler registration for (the name of) this channel.

If no handler has been registered, any incoming message on this channel will be handled silently by sending a null reply.

Parameters
handlera MessageHandler, or null to deregister.

Definition at line 123 of file BasicMessageChannel.java.

123 {
124 // We call the 2 parameter variant specifically to avoid breaking changes in
125 // mock verify calls.
126 // See https://github.com/flutter/flutter/issues/92582.
127 if (taskQueue != null) {
128 messenger.setMessageHandler(
129 name, handler == null ? null : new IncomingMessageHandler(handler), taskQueue);
130 } else {
131 messenger.setMessageHandler(
132 name, handler == null ? null : new IncomingMessageHandler(handler));
133 }
134 }
void setMessageHandler(@NonNull String channel, @Nullable BinaryMessageHandler handler)

◆ setWarnsOnChannelOverflow() [1/2]

static void io.flutter.plugin.common.BasicMessageChannel< T >.setWarnsOnChannelOverflow ( @NonNull BinaryMessenger  messenger,
@NonNull String  channel,
boolean  warns 
)
inlinestatic

Toggles whether the channel should show warning messages when discarding messages due to overflow. When 'warns' is false the channel is expected to overflow and warning messages will not be shown.

Definition at line 188 of file BasicMessageChannel.java.

189 {
190 final StandardMethodCodec codec = StandardMethodCodec.INSTANCE;
191 Object[] arguments = {channel, !warns};
192 MethodCall methodCall = new MethodCall("overflow", Arrays.asList(arguments));
193 ByteBuffer message = codec.encodeMethodCall(methodCall);
194 ByteBuffer packet = packetFromEncodedMessage(message);
195 messenger.send(BasicMessageChannel.CHANNEL_BUFFERS_CHANNEL, packet);
196 }

◆ setWarnsOnChannelOverflow() [2/2]

void io.flutter.plugin.common.BasicMessageChannel< T >.setWarnsOnChannelOverflow ( boolean  warns)
inline

Toggles whether the channel should show warning messages when discarding messages due to overflow. When 'warns' is false the channel is expected to overflow and warning messages will not be shown.

Definition at line 150 of file BasicMessageChannel.java.

150 {
151 setWarnsOnChannelOverflow(messenger, name, warns);
152 }

Member Data Documentation

◆ CHANNEL_BUFFERS_CHANNEL

final String io.flutter.plugin.common.BasicMessageChannel< T >.CHANNEL_BUFFERS_CHANNEL = "dev.flutter/channel-buffers"
static

Definition at line 33 of file BasicMessageChannel.java.


The documentation for this class was generated from the following file: