5#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
9#pragma mark - Basic message channel
18 NSCAssert(newSize >= 0,
@"Channel buffer size must be non-negative");
22 NSArray*
args = @[ channel, @(
static_cast<int>(newSize)) ];
26 NSData*
message = [codec encodeMethodCall:resizeMethodCall];
44 arguments:@[ channel, @(!warns) ]];
46 NSData*
message = [codec encodeMethodCall:overflowMethodCall];
51 NSObject<FlutterBinaryMessenger>* messenger,
54 NSObject<FlutterTaskQueue>* taskQueue) {
56 NSCAssert([messenger respondsToSelector:
@selector(setMessageHandlerOnChannel:
57 binaryMessageHandler:taskQueue:)],
59 return [messenger setMessageHandlerOnChannel:
name
60 binaryMessageHandler:handler
63 return [messenger setMessageHandlerOnChannel:
name binaryMessageHandler:handler];
69 NSObject<FlutterBinaryMessenger>* _messenger;
71 NSObject<FlutterMessageCodec>*
_codec;
75+ (instancetype)messageChannelWithName:(NSString*)name
82+ (instancetype)messageChannelWithName:(NSString*)name
86 binaryMessenger:messenger
90- (instancetype)initWithName:(NSString*)name
93 self = [
self initWithName:name binaryMessenger:messenger codec:codec taskQueue:nil];
97- (instancetype)initWithName:(NSString*)name
102 NSAssert(
self,
@"Super init cannot be nil");
104 _messenger = messenger;
110- (void)sendMessage:(
id)message {
111 [_messenger sendOnChannel:_name message:[_codec encode:message]];
114- (void)sendMessage:(
id)message reply:(
FlutterReply)callback {
120 [_messenger sendOnChannel:_name message:[_codec encode:message] binaryReply:reply];
126 [_messenger cleanUpConnection:_connection];
129 [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:nil];
137 NSObject<FlutterMessageCodec>* codec =
_codec;
146+ (void)resizeChannelWithName:(NSString*)name
148 size:(NSInteger)newSize {
152- (void)resizeChannelBuffer:(NSInteger)newSize {
156+ (void)setWarnsOnOverflow:(
BOOL)warns
157 forChannelWithName:(NSString*)name
162- (void)setWarnsOnOverflow:(
BOOL)warns {
168#pragma mark - Method channel
172+ (instancetype)errorWithCode:(NSString*)code message:(NSString*)message details:(
id)details {
173 return [[
FlutterError alloc] initWithCode:code message:message details:details];
176- (instancetype)initWithCode:(NSString*)code message:(NSString*)message details:(
id)details {
177 NSAssert(
code,
@"Code cannot be nil");
179 NSAssert(
self,
@"Super init cannot be nil");
181 _message = [message copy];
186- (
BOOL)isEqual:(
id)object {
187 if (
self ==
object) {
194 return [
self.code isEqual:other.code] &&
200 return [
self.code hash] ^ [
self.message hash] ^ [
self.details hash];
206+ (instancetype)methodCallWithMethodName:(NSString*)method arguments:(
id)arguments {
207 return [[
FlutterMethodCall alloc] initWithMethodName:method arguments:arguments];
210- (instancetype)initWithMethodName:(NSString*)method arguments:(
id)arguments {
211 NSAssert(
method,
@"Method name cannot be nil");
213 NSAssert(
self,
@"Super init cannot be nil");
214 _method = [method copy];
219- (
BOOL)isEqual:(
id)object {
220 if (
self ==
object) {
227 return [
self.method isEqual:[other
method]] &&
232 return [
self.method hash] ^ [
self.arguments hash];
240 NSObject<FlutterBinaryMessenger>* _messenger;
242 NSObject<FlutterMethodCodec>*
_codec;
247+ (instancetype)methodChannelWithName:(NSString*)name
253+ (instancetype)methodChannelWithName:(NSString*)name
255 codec:(NSObject<FlutterMethodCodec>*)codec {
259- (instancetype)initWithName:(NSString*)name
261 codec:(NSObject<FlutterMethodCodec>*)codec {
262 self = [
self initWithName:name binaryMessenger:messenger codec:codec taskQueue:nil];
265- (instancetype)initWithName:(NSString*)name
267 codec:(NSObject<FlutterMethodCodec>*)codec
270 NSAssert(
self,
@"Super init cannot be nil");
272 _messenger = messenger;
278- (void)invokeMethod:(NSString*)method arguments:(
id)arguments {
281 NSData*
message = [_codec encodeMethodCall:methodCall];
282 [_messenger sendOnChannel:_name message:message];
285- (void)invokeMethod:(NSString*)method arguments:(
id)arguments result:(
FlutterResult)callback {
288 NSData*
message = [_codec encodeMethodCall:methodCall];
294 [_messenger sendOnChannel:_name message:message binaryReply:reply];
300 [_messenger cleanUpConnection:_connection];
303 [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:nil];
310 NSObject<FlutterMethodCodec>* codec =
_codec;
326- (void)resizeChannelBuffer:(NSInteger)newSize {
332#pragma mark - Event channel
338 NSObject<FlutterBinaryMessenger>* _messenger;
340 NSObject<FlutterMethodCodec>*
_codec;
344+ (instancetype)eventChannelWithName:(NSString*)name
350+ (instancetype)eventChannelWithName:(NSString*)name
352 codec:(NSObject<FlutterMethodCodec>*)codec {
353 return [[
FlutterEventChannel alloc] initWithName:name binaryMessenger:messenger codec:codec];
356- (instancetype)initWithName:(NSString*)name
358 codec:(NSObject<FlutterMethodCodec>*)codec {
359 return [
self initWithName:name binaryMessenger:messenger codec:codec taskQueue:nil];
362- (instancetype)initWithName:(NSString*)name
364 codec:(NSObject<FlutterMethodCodec>*)codec
367 NSAssert(
self,
@"Super init cannot be nil");
369 _messenger = messenger;
376 NSObject<FlutterStreamHandler>* handler,
378 NSObject<FlutterBinaryMessenger>* messenger,
379 NSObject<FlutterMethodCodec>* codec,
380 NSObject<FlutterTaskQueue>* taskQueue) {
384 if ([
call.method isEqual:
@"listen"]) {
388 NSLog(
@"Failed to cancel existing stream: %@. %@ (%@)",
error.code,
error.message,
392 currentSink = ^(
id event) {
394 [messenger sendOnChannel:name message:nil];
396 [messenger sendOnChannel:name message:[codec encodeErrorEnvelope:(FlutterError*)event]];
398 [messenger sendOnChannel:name message:[codec encodeSuccessEnvelope:event]];
401 FlutterError*
error = [handler onListenWithArguments:call.arguments eventSink:currentSink];
405 callback([codec encodeSuccessEnvelope:nil]);
407 }
else if ([
call.method isEqual:
@"cancel"]) {
410 [codec encodeErrorEnvelope:[
FlutterError errorWithCode:
@"error"
411 message:
@"No active stream to cancel"
420 callback([codec encodeSuccessEnvelope:nil]);
431 [_messenger cleanUpConnection:_connection];
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
void(^ FlutterBinaryMessageHandler)(NSData *_Nullable message, FlutterBinaryReply reply)
int64_t FlutterBinaryMessengerConnection
void(^ FlutterResult)(id _Nullable result)
void(^ FlutterMethodCallHandler)(FlutterMethodCall *call, FlutterResult result)
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented
void(^ FlutterMessageHandler)(id _Nullable message, FlutterReply callback)
FLUTTER_DARWIN_EXPORT NSObject const * FlutterEndOfEventStream
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterReply)(id _Nullable reply)
void(^ FlutterEventSink)(id _Nullable event)
static NSString *const kOverflowMethod
FlutterBinaryMessengerConnection _connection
static void SetWarnsOnOverflow(NSObject< FlutterBinaryMessenger > *binaryMessenger, NSString *channel, BOOL warns)
static FlutterBinaryMessengerConnection SetMessageHandler(NSObject< FlutterBinaryMessenger > *messenger, NSString *name, FlutterBinaryMessageHandler handler, NSObject< FlutterTaskQueue > *taskQueue)
NSObject< FlutterMessageCodec > * _codec
NSObject< FlutterTaskQueue > * _taskQueue
static void ResizeChannelBuffer(NSObject< FlutterBinaryMessenger > *binaryMessenger, NSString *channel, NSInteger newSize)
static NSString *const kResizeMethod
static FLUTTER_ASSERT_ARC NSString *const kFlutterChannelBuffersChannel
static void encode(uint8_t output[16], const uint32_t input[4])
static uint32_t hash(const SkShaderBase::GradientInfo &v)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
const uint8_t uint32_t uint32_t GError ** error
instancetype messageChannelWithName:binaryMessenger:codec:(NSString *name,[binaryMessenger] NSObject< FlutterBinaryMessenger > *messenger,[codec] NSObject< FlutterMessageCodec > *codec)
instancetype eventChannelWithName:binaryMessenger:codec:(NSString *name,[binaryMessenger] NSObject< FlutterBinaryMessenger > *messenger,[codec] NSObject< FlutterMethodCodec > *codec)
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
instancetype methodChannelWithName:binaryMessenger:codec:(NSString *name,[binaryMessenger] NSObject< FlutterBinaryMessenger > *messenger,[codec] NSObject< FlutterMethodCodec > *codec)
instancetype sharedInstance()
instancetype sharedInstance()
DEF_SWITCHES_START aot vmservice shared library name
static DecodeResult decode(std::string path)
std::shared_ptr< const fml::Mapping > data