From e429317d54fc6f71eda944fbcfd9bbab5947310f Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 4 Dec 2018 17:09:11 -0800 Subject: [PATCH 1/4] [macos] Add MessageChannel/MessageCodec Further API alignment (issue #102). Adds support for communicating with a BasicMessageChannel on the Flutter side. --- library/macos/FLEChannels.h | 60 +++++++++++++++++++++++++++++++--- library/macos/FLEChannels.m | 65 ++++++++++++++++++++++++++++++++----- library/macos/FLECodecs.h | 27 +++++++++++++++ library/macos/FLECodecs.m | 56 +++++++++++++++++++++++++++++++- 4 files changed, 195 insertions(+), 13 deletions(-) diff --git a/library/macos/FLEChannels.h b/library/macos/FLEChannels.h index 641229699..672733360 100644 --- a/library/macos/FLEChannels.h +++ b/library/macos/FLEChannels.h @@ -18,6 +18,57 @@ #import "FLECodecs.h" #import "FLEMethods.h" +/** + * A message response callback. Used for sending a message's reply back to the Flutter engine. + * The reply must be serializable by the codec used to encode the message. + */ +typedef void (^FLEMessageReply)(id _Nullable reply); + +/** + * A handler for receiving a message. Implementations should asynchronously call |callback| + * exactly once with the reply to the message (or nil if there is none). + */ +typedef void (^FLEMessageHandler)(id _Nullable message, FLEMessageReply _Nonnull callback); + +@interface FLEBasicMessageChannel : NSObject + +// TODO: support +messageChannelWithName:binaryMessenger: once the standard codec is supported +// (Issue #67). + +/** + * Returns a new channel that sends and receives messages on the channel named |name|, encoded + * with |codec| and dispatched via |messenger|. + */ ++ (nonnull instancetype)messageChannelWithName:(nonnull NSString *)name + binaryMessenger:(nonnull NSObject *)messenger + codec:(nonnull NSObject *)codec; + +/** + * Initializes a channel to send and receive messages on the channel named |name|, encoded + * with |codec| and dispatched via |messenger|. + */ +- (nonnull instancetype)initWithName:(nonnull NSString *)name + binaryMessenger:(nonnull NSObject *)messenger + codec:(nonnull NSObject *)codec; + +/** + * Sends a message to the Flutter engine on this channel. + * + * The message must be encodable using this channel's codec. + */ +- (void)sendMessage:(nullable id)message; + +// TODO: Support sendMessage:result: once +// https://github.com/flutter/flutter/issues/18852 is resolved + +/** + * Registers a handler that should be called any time a message is received on this channel. + */ +- (void)setMessageHandler:(nullable FLEMessageHandler)handler; +@end + +#pragma mark - + /** * A method call result callback. Used for sending a method call's response back to the * Flutter engine. The result must be serializable by the codec used to encode the message. @@ -50,14 +101,15 @@ extern NSString const *_Nonnull FLEMethodNotImplemented; // (Issue #67). /** - * Returns a new channel that sends and receives method calls on the channel name |name|, encoded + * Returns a new channel that sends and receives method calls on the channel named |name|, encoded * with |codec| and dispatched via |messenger|. */ + (nonnull instancetype)methodChannelWithName:(nonnull NSString *)name binaryMessenger:(nonnull id)messenger codec:(nonnull id)codec; + /** - * Initializes a channel to send and receive method calls on the channel name |name|, encoded + * Initializes a channel to send and receive method calls on the channel named |name|, encoded * with |codec| and dispatched via |messenger|. */ - (nonnull instancetype)initWithName:(nonnull NSString *)name @@ -69,7 +121,7 @@ extern NSString const *_Nonnull FLEMethodNotImplemented; * * The arguments, if any, must be encodable using this channel's codec. */ -- (void)invokeMethod:(nonnull NSString *)method arguments:(id _Nullable)arguments; +- (void)invokeMethod:(nonnull NSString *)method arguments:(nullable id)arguments; // TODO: Support invokeMethod:arguments:result: once // https://github.com/flutter/flutter/issues/18852 is resolved @@ -77,6 +129,6 @@ extern NSString const *_Nonnull FLEMethodNotImplemented; /** * Registers a handler that should be called any time a method call is received on this channel. */ -- (void)setMethodCallHandler:(FLEMethodCallHandler _Nullable)handler; +- (void)setMethodCallHandler:(nullable FLEMethodCallHandler)handler; @end diff --git a/library/macos/FLEChannels.m b/library/macos/FLEChannels.m index 6708da9d8..119575670 100644 --- a/library/macos/FLEChannels.m +++ b/library/macos/FLEChannels.m @@ -14,6 +14,55 @@ #import "FLEChannels.h" +@implementation FLEBasicMessageChannel { + NSString *_name; + __weak id _messenger; + id _codec; +} ++ (instancetype)messageChannelWithName:(NSString *)name + binaryMessenger:(NSObject *)messenger + codec:(NSObject *)codec { + return [[[self class] alloc] initWithName:name binaryMessenger:messenger codec:codec]; +} + +- (instancetype)initWithName:(NSString *)name + binaryMessenger:(NSObject *)messenger + codec:(NSObject *)codec { + self = [super init]; + if (self) { + _name = [name copy]; + _messenger = messenger; + _codec = codec; + } + return self; +} + +- (void)sendMessage:(id)message { + [_messenger sendOnChannel:_name message:[_codec encode:message]]; +} + +- (void)setMessageHandler:(FLEMessageHandler)handler { + if (!handler) { + [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:nil]; + return; + } + + // Don't capture the channel in the callback, since that makes lifetimes harder to reason about. + id codec = _codec; + + FLEBinaryMessageHandler messageHandler = ^(NSData *message, FLEBinaryReply callback) { + handler([codec decode:message], ^(id reply) { + callback([codec encode:reply]); + }); + }; + + [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler]; +} + +@end + +#pragma mark - + NSString const *FLEMethodNotImplemented = @"notimplemented"; @implementation FLEMethodChannel { @@ -22,15 +71,15 @@ @implementation FLEMethodChannel { id _codec; } -+ (instancetype)methodChannelWithName:(nonnull NSString *)name - binaryMessenger:(nonnull id)messenger - codec:(nonnull NSObject *)codec { ++ (instancetype)methodChannelWithName:(NSString *)name + binaryMessenger:(id)messenger + codec:(NSObject *)codec { return [[[self class] alloc] initWithName:name binaryMessenger:messenger codec:codec]; } -- (instancetype)initWithName:(nonnull NSString *)name - binaryMessenger:(nonnull id)messenger - codec:(nonnull id)codec { +- (instancetype)initWithName:(NSString *)name + binaryMessenger:(id)messenger + codec:(id)codec { self = [super init]; if (self) { _name = [name copy]; @@ -40,7 +89,7 @@ - (instancetype)initWithName:(nonnull NSString *)name return self; } -- (void)invokeMethod:(NSString *)method arguments:(id _Nullable)arguments { +- (void)invokeMethod:(NSString *)method arguments:(id)arguments { FLEMethodCall *methodCall = [[FLEMethodCall alloc] initWithMethodName:method arguments:arguments]; NSData *message = [_codec encodeMethodCall:methodCall]; if (!message) { @@ -50,7 +99,7 @@ - (void)invokeMethod:(NSString *)method arguments:(id _Nullable)arguments { [_messenger sendOnChannel:_name message:message]; } -- (void)setMethodCallHandler:(FLEMethodCallHandler _Nullable)handler { +- (void)setMethodCallHandler:(FLEMethodCallHandler)handler { if (!handler) { [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:nil]; return; diff --git a/library/macos/FLECodecs.h b/library/macos/FLECodecs.h index ec6f722a1..12b361605 100644 --- a/library/macos/FLECodecs.h +++ b/library/macos/FLECodecs.h @@ -16,6 +16,33 @@ #import "FLEMethods.h" +@protocol FLEMessageCodec +/** + * Returns the shared instance of the codec. + */ ++ (nonnull instancetype)sharedInstance; + +/** + * Returns a binary encoding of the given |message|, or nil if the message cannot be + * serialized by this codec. + */ +- (nullable NSData*)encode:(nullable id)message; + +/** + * Returns the decoded mesasge, or nil if it cannot be decoded. + */ +- (nullable id)decode:(nullable NSData*)messageData; +@end + +/** + * A codec that uses JSON as the encoding format. Messages using this codec must be serializable + * to JSON. + */ +@interface FLEJSONMessageCodec : NSObject +@end + +#pragma mark - + /** * Translates between a binary message and higher-level method call and response/error objects. */ diff --git a/library/macos/FLECodecs.m b/library/macos/FLECodecs.m index 6f89a93a8..92efcf2da 100644 --- a/library/macos/FLECodecs.m +++ b/library/macos/FLECodecs.m @@ -14,6 +14,60 @@ #import "FLECodecs.h" +@implementation FLEJSONMessageCodec + ++ (instancetype)sharedInstance { + static FLEJSONMessageCodec *sharedInstance; + if (!sharedInstance) { + sharedInstance = [[FLEJSONMessageCodec alloc] init]; + } + return sharedInstance; +} + +- (NSData *)encode:(id)message { + if (!message) { + return nil; + } + + NSData *encoding; + NSError *error = nil; + if ([message isKindOfClass:[NSArray class]] || [message isKindOfClass:[NSDictionary class]]) { + encoding = [NSJSONSerialization dataWithJSONObject:message options:0 error:&error]; + } else { + // Wrap then unwrap non-collection objects; see FlutterCodecs.mm in the Flutter engine. + encoding = [NSJSONSerialization dataWithJSONObject:@[ message ] options:0 error:&error]; + const NSUInteger kJSONArrayStartLength = 1; + const NSUInteger kJSONArrayEndLength = 1; + encoding = [encoding subdataWithRange:NSMakeRange(kJSONArrayStartLength, + encoding.length - (kJSONArrayStartLength + + kJSONArrayEndLength))]; + } + if (error) { + NSLog(@"Error: Failed to create JSON message for %@: %@", message, error.debugDescription); + } + return encoding; +} + +// See FlutterCodecs.mm in the Flutter engine for implementation notes. +- (id)decode:(NSData *)messageData { + if (!messageData) { + return nil; + } + + NSError *error = nil; + id message = [NSJSONSerialization JSONObjectWithData:messageData + options:NSJSONReadingAllowFragments + error:&error]; + if (error) { + NSLog(@"Error: Failed to decode JSON message: %@", error.debugDescription); + } + return message; +} + +@end + +#pragma mark - + // Keys for JSON-encoded method calls. static NSString *const kMessageMethodKey = @"method"; static NSString *const kMessageArgumentsKey = @"args"; @@ -70,7 +124,7 @@ - (FLEMethodCall *)decodeMethodCall:(NSData *)methodData { return [[FLEMethodCall alloc] initWithMethodName:method arguments:arguments]; } -- (NSData *)encodeSuccessEnvelope:(id _Nullable)result { +- (NSData *)encodeSuccessEnvelope:(id)result { return SerializeAsJSON(@[ result ?: [NSNull null] ]); } From cbfc4813d544f8de40a852037c9f708362fec6a9 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 5 Dec 2018 10:14:29 -0800 Subject: [PATCH 2/4] Break apart channel/codec related files by class --- library/macos/FLEBasicMessageChannel.h | 67 +++++++++++++++ library/macos/FLEBasicMessageChannel.m | 62 ++++++++++++++ library/macos/FLEJSONMessageCodec.h | 24 ++++++ library/macos/FLEJSONMessageCodec.m | 67 +++++++++++++++ library/macos/FLEJSONMethodCodec.h | 24 ++++++ .../{FLECodecs.m => FLEJSONMethodCodec.m} | 56 +----------- library/macos/FLEMessageCodec.h | 38 +++++++++ library/macos/FLEMethodCall.h | 43 ++++++++++ library/macos/FLEMethodCall.m | 29 +++++++ .../{FLEChannels.h => FLEMethodChannel.h} | 54 +----------- .../{FLEChannels.m => FLEMethodChannel.m} | 51 +---------- .../macos/{FLECodecs.h => FLEMethodCodec.h} | 39 +-------- .../macos/{FLEMethods.h => FLEMethodError.h} | 30 +------ .../macos/{FLEMethods.m => FLEMethodError.m} | 18 +--- library/macos/FLEPlugin.h | 5 +- library/macos/FLEViewController.h | 2 +- library/macos/FlutterEmbedderMac.h | 11 ++- .../project.pbxproj | 85 +++++++++++++------ 18 files changed, 431 insertions(+), 274 deletions(-) create mode 100644 library/macos/FLEBasicMessageChannel.h create mode 100644 library/macos/FLEBasicMessageChannel.m create mode 100644 library/macos/FLEJSONMessageCodec.h create mode 100644 library/macos/FLEJSONMessageCodec.m create mode 100644 library/macos/FLEJSONMethodCodec.h rename library/macos/{FLECodecs.m => FLEJSONMethodCodec.m} (59%) create mode 100644 library/macos/FLEMessageCodec.h create mode 100644 library/macos/FLEMethodCall.h create mode 100644 library/macos/FLEMethodCall.m rename library/macos/{FLEChannels.h => FLEMethodChannel.h} (62%) rename library/macos/{FLEChannels.m => FLEMethodChannel.m} (65%) rename library/macos/{FLECodecs.h => FLEMethodCodec.h} (63%) rename library/macos/{FLEMethods.h => FLEMethodError.h} (66%) rename library/macos/{FLEMethods.m => FLEMethodError.m} (74%) diff --git a/library/macos/FLEBasicMessageChannel.h b/library/macos/FLEBasicMessageChannel.h new file mode 100644 index 000000000..ec2bb77a7 --- /dev/null +++ b/library/macos/FLEBasicMessageChannel.h @@ -0,0 +1,67 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +#import "FLEBinaryMessenger.h" +#import "FLEMessageCodec.h" + +/** + * A message response callback. Used for sending a message's reply back to the Flutter engine. + * The reply must be serializable by the codec used to encode the message. + */ +typedef void (^FLEMessageReply)(id _Nullable reply); + +/** + * A handler for receiving a message. Implementations should asynchronously call |callback| + * exactly once with the reply to the message (or nil if there is none). + */ +typedef void (^FLEMessageHandler)(id _Nullable message, FLEMessageReply _Nonnull callback); + +@interface FLEBasicMessageChannel : NSObject + +// TODO: support +messageChannelWithName:binaryMessenger: once the standard codec is supported +// (Issue #67). + +/** + * Returns a new channel that sends and receives messages on the channel named |name|, encoded + * with |codec| and dispatched via |messenger|. + */ ++ (nonnull instancetype)messageChannelWithName:(nonnull NSString *)name + binaryMessenger:(nonnull NSObject *)messenger + codec:(nonnull NSObject *)codec; + +/** + * Initializes a channel to send and receive messages on the channel named |name|, encoded + * with |codec| and dispatched via |messenger|. + */ +- (nonnull instancetype)initWithName:(nonnull NSString *)name + binaryMessenger:(nonnull NSObject *)messenger + codec:(nonnull NSObject *)codec; + +/** + * Sends a message to the Flutter engine on this channel. + * + * The message must be encodable using this channel's codec. + */ +- (void)sendMessage:(nullable id)message; + +// TODO: Support sendMessage:result: once +// https://github.com/flutter/flutter/issues/18852 is resolved + +/** + * Registers a handler that should be called any time a message is received on this channel. + */ +- (void)setMessageHandler:(nullable FLEMessageHandler)handler; +@end diff --git a/library/macos/FLEBasicMessageChannel.m b/library/macos/FLEBasicMessageChannel.m new file mode 100644 index 000000000..a20718caa --- /dev/null +++ b/library/macos/FLEBasicMessageChannel.m @@ -0,0 +1,62 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "FLEBasicMessageChannel.h" + +@implementation FLEBasicMessageChannel { + NSString *_name; + __weak id _messenger; + id _codec; +} ++ (instancetype)messageChannelWithName:(NSString *)name + binaryMessenger:(NSObject *)messenger + codec:(NSObject *)codec { + return [[[self class] alloc] initWithName:name binaryMessenger:messenger codec:codec]; +} + +- (instancetype)initWithName:(NSString *)name + binaryMessenger:(NSObject *)messenger + codec:(NSObject *)codec { + self = [super init]; + if (self) { + _name = [name copy]; + _messenger = messenger; + _codec = codec; + } + return self; +} + +- (void)sendMessage:(id)message { + [_messenger sendOnChannel:_name message:[_codec encode:message]]; +} + +- (void)setMessageHandler:(FLEMessageHandler)handler { + if (!handler) { + [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:nil]; + return; + } + + // Don't capture the channel in the callback, since that makes lifetimes harder to reason about. + id codec = _codec; + + FLEBinaryMessageHandler messageHandler = ^(NSData *message, FLEBinaryReply callback) { + handler([codec decode:message], ^(id reply) { + callback([codec encode:reply]); + }); + }; + + [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler]; +} + +@end diff --git a/library/macos/FLEJSONMessageCodec.h b/library/macos/FLEJSONMessageCodec.h new file mode 100644 index 000000000..ba5a50eec --- /dev/null +++ b/library/macos/FLEJSONMessageCodec.h @@ -0,0 +1,24 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +#import "FLEMessageCodec.h" + +/** + * A codec that uses JSON as the encoding format. Messages using this codec must be serializable + * to JSON. + */ +@interface FLEJSONMessageCodec : NSObject +@end diff --git a/library/macos/FLEJSONMessageCodec.m b/library/macos/FLEJSONMessageCodec.m new file mode 100644 index 000000000..585eb3c4f --- /dev/null +++ b/library/macos/FLEJSONMessageCodec.m @@ -0,0 +1,67 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "FLEJSONMessageCodec.h" + +@implementation FLEJSONMessageCodec + ++ (instancetype)sharedInstance { + static FLEJSONMessageCodec *sharedInstance; + if (!sharedInstance) { + sharedInstance = [[FLEJSONMessageCodec alloc] init]; + } + return sharedInstance; +} + +- (NSData *)encode:(id)message { + if (!message) { + return nil; + } + + NSData *encoding; + NSError *error = nil; + if ([message isKindOfClass:[NSArray class]] || [message isKindOfClass:[NSDictionary class]]) { + encoding = [NSJSONSerialization dataWithJSONObject:message options:0 error:&error]; + } else { + // Wrap then unwrap non-collection objects; see FlutterCodecs.mm in the Flutter engine. + encoding = [NSJSONSerialization dataWithJSONObject:@[ message ] options:0 error:&error]; + const NSUInteger kJSONArrayStartLength = 1; + const NSUInteger kJSONArrayEndLength = 1; + encoding = [encoding subdataWithRange:NSMakeRange(kJSONArrayStartLength, + encoding.length - (kJSONArrayStartLength + + kJSONArrayEndLength))]; + } + if (error) { + NSLog(@"Error: Failed to create JSON message for %@: %@", message, error.debugDescription); + } + return encoding; +} + +// See FlutterCodecs.mm in the Flutter engine for implementation notes. +- (id)decode:(NSData *)messageData { + if (!messageData) { + return nil; + } + + NSError *error = nil; + id message = [NSJSONSerialization JSONObjectWithData:messageData + options:NSJSONReadingAllowFragments + error:&error]; + if (error) { + NSLog(@"Error: Failed to decode JSON message: %@", error.debugDescription); + } + return message; +} + +@end diff --git a/library/macos/FLEJSONMethodCodec.h b/library/macos/FLEJSONMethodCodec.h new file mode 100644 index 000000000..2f1f8c03b --- /dev/null +++ b/library/macos/FLEJSONMethodCodec.h @@ -0,0 +1,24 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +#import "FLEMethodCodec.h" + +/** + * A codec that uses JSON as the encoding format. Method arguments and error details for plugins + * using this codec must be serializable to JSON. + */ +@interface FLEJSONMethodCodec : NSObject +@end diff --git a/library/macos/FLECodecs.m b/library/macos/FLEJSONMethodCodec.m similarity index 59% rename from library/macos/FLECodecs.m rename to library/macos/FLEJSONMethodCodec.m index 92efcf2da..945f986cc 100644 --- a/library/macos/FLECodecs.m +++ b/library/macos/FLEJSONMethodCodec.m @@ -12,61 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "FLECodecs.h" - -@implementation FLEJSONMessageCodec - -+ (instancetype)sharedInstance { - static FLEJSONMessageCodec *sharedInstance; - if (!sharedInstance) { - sharedInstance = [[FLEJSONMessageCodec alloc] init]; - } - return sharedInstance; -} - -- (NSData *)encode:(id)message { - if (!message) { - return nil; - } - - NSData *encoding; - NSError *error = nil; - if ([message isKindOfClass:[NSArray class]] || [message isKindOfClass:[NSDictionary class]]) { - encoding = [NSJSONSerialization dataWithJSONObject:message options:0 error:&error]; - } else { - // Wrap then unwrap non-collection objects; see FlutterCodecs.mm in the Flutter engine. - encoding = [NSJSONSerialization dataWithJSONObject:@[ message ] options:0 error:&error]; - const NSUInteger kJSONArrayStartLength = 1; - const NSUInteger kJSONArrayEndLength = 1; - encoding = [encoding subdataWithRange:NSMakeRange(kJSONArrayStartLength, - encoding.length - (kJSONArrayStartLength + - kJSONArrayEndLength))]; - } - if (error) { - NSLog(@"Error: Failed to create JSON message for %@: %@", message, error.debugDescription); - } - return encoding; -} - -// See FlutterCodecs.mm in the Flutter engine for implementation notes. -- (id)decode:(NSData *)messageData { - if (!messageData) { - return nil; - } - - NSError *error = nil; - id message = [NSJSONSerialization JSONObjectWithData:messageData - options:NSJSONReadingAllowFragments - error:&error]; - if (error) { - NSLog(@"Error: Failed to decode JSON message: %@", error.debugDescription); - } - return message; -} - -@end - -#pragma mark - +#import "FLEJSONMethodCodec.h" // Keys for JSON-encoded method calls. static NSString *const kMessageMethodKey = @"method"; diff --git a/library/macos/FLEMessageCodec.h b/library/macos/FLEMessageCodec.h new file mode 100644 index 000000000..15d5ca64e --- /dev/null +++ b/library/macos/FLEMessageCodec.h @@ -0,0 +1,38 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +/** + * Translates between a binary message and higher-level message objects. + */ +@protocol FLEMessageCodec + +/** + * Returns the shared instance of the codec. + */ ++ (nonnull instancetype)sharedInstance; + +/** + * Returns a binary encoding of the given |message|, or nil if the message cannot be + * serialized by this codec. + */ +- (nullable NSData*)encode:(nullable id)message; + +/** + * Returns the decoded mesasge, or nil if it cannot be decoded. + */ +- (nullable id)decode:(nullable NSData*)messageData; + +@end diff --git a/library/macos/FLEMethodCall.h b/library/macos/FLEMethodCall.h new file mode 100644 index 000000000..0bd697054 --- /dev/null +++ b/library/macos/FLEMethodCall.h @@ -0,0 +1,43 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +/** + * An object encapsulating a method call from Flutter. + */ +@interface FLEMethodCall : NSObject + +/** + * Initializes an FLEMethodCall. If |arguments| is provided, it must be serializable by the codec + * used to encode the call. + */ +- (nonnull instancetype)initWithMethodName:(nonnull NSString *)name + arguments:(nullable id)arguments NS_DESIGNATED_INITIALIZER; + +- (nonnull instancetype)init NS_UNAVAILABLE; + +/** + * The name of the method being called. + */ +@property(readonly, nonatomic, nonnull) NSString *methodName; + +/** + * The arguments to the method being called, if any. + * + * This object must be serializable by the codec used to encode the call. + */ +@property(readonly, nonatomic, nullable) id arguments; + +@end diff --git a/library/macos/FLEMethodCall.m b/library/macos/FLEMethodCall.m new file mode 100644 index 000000000..9b11a42fc --- /dev/null +++ b/library/macos/FLEMethodCall.m @@ -0,0 +1,29 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "FLEMethodCall.h" + +@implementation FLEMethodCall + +- (nonnull instancetype)initWithMethodName:(nonnull NSString *)name + arguments:(nullable id)arguments { + self = [super init]; + if (self) { + _methodName = name; + _arguments = arguments; + } + return self; +} + +@end diff --git a/library/macos/FLEChannels.h b/library/macos/FLEMethodChannel.h similarity index 62% rename from library/macos/FLEChannels.h rename to library/macos/FLEMethodChannel.h index 672733360..98dca1b7d 100644 --- a/library/macos/FLEChannels.h +++ b/library/macos/FLEMethodChannel.h @@ -15,59 +15,7 @@ #import #import "FLEBinaryMessenger.h" -#import "FLECodecs.h" -#import "FLEMethods.h" - -/** - * A message response callback. Used for sending a message's reply back to the Flutter engine. - * The reply must be serializable by the codec used to encode the message. - */ -typedef void (^FLEMessageReply)(id _Nullable reply); - -/** - * A handler for receiving a message. Implementations should asynchronously call |callback| - * exactly once with the reply to the message (or nil if there is none). - */ -typedef void (^FLEMessageHandler)(id _Nullable message, FLEMessageReply _Nonnull callback); - -@interface FLEBasicMessageChannel : NSObject - -// TODO: support +messageChannelWithName:binaryMessenger: once the standard codec is supported -// (Issue #67). - -/** - * Returns a new channel that sends and receives messages on the channel named |name|, encoded - * with |codec| and dispatched via |messenger|. - */ -+ (nonnull instancetype)messageChannelWithName:(nonnull NSString *)name - binaryMessenger:(nonnull NSObject *)messenger - codec:(nonnull NSObject *)codec; - -/** - * Initializes a channel to send and receive messages on the channel named |name|, encoded - * with |codec| and dispatched via |messenger|. - */ -- (nonnull instancetype)initWithName:(nonnull NSString *)name - binaryMessenger:(nonnull NSObject *)messenger - codec:(nonnull NSObject *)codec; - -/** - * Sends a message to the Flutter engine on this channel. - * - * The message must be encodable using this channel's codec. - */ -- (void)sendMessage:(nullable id)message; - -// TODO: Support sendMessage:result: once -// https://github.com/flutter/flutter/issues/18852 is resolved - -/** - * Registers a handler that should be called any time a message is received on this channel. - */ -- (void)setMessageHandler:(nullable FLEMessageHandler)handler; -@end - -#pragma mark - +#import "FLEMethodCodec.h" /** * A method call result callback. Used for sending a method call's response back to the diff --git a/library/macos/FLEChannels.m b/library/macos/FLEMethodChannel.m similarity index 65% rename from library/macos/FLEChannels.m rename to library/macos/FLEMethodChannel.m index 119575670..f279aac93 100644 --- a/library/macos/FLEChannels.m +++ b/library/macos/FLEMethodChannel.m @@ -12,56 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "FLEChannels.h" - -@implementation FLEBasicMessageChannel { - NSString *_name; - __weak id _messenger; - id _codec; -} -+ (instancetype)messageChannelWithName:(NSString *)name - binaryMessenger:(NSObject *)messenger - codec:(NSObject *)codec { - return [[[self class] alloc] initWithName:name binaryMessenger:messenger codec:codec]; -} - -- (instancetype)initWithName:(NSString *)name - binaryMessenger:(NSObject *)messenger - codec:(NSObject *)codec { - self = [super init]; - if (self) { - _name = [name copy]; - _messenger = messenger; - _codec = codec; - } - return self; -} - -- (void)sendMessage:(id)message { - [_messenger sendOnChannel:_name message:[_codec encode:message]]; -} - -- (void)setMessageHandler:(FLEMessageHandler)handler { - if (!handler) { - [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:nil]; - return; - } - - // Don't capture the channel in the callback, since that makes lifetimes harder to reason about. - id codec = _codec; - - FLEBinaryMessageHandler messageHandler = ^(NSData *message, FLEBinaryReply callback) { - handler([codec decode:message], ^(id reply) { - callback([codec encode:reply]); - }); - }; - - [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler]; -} - -@end - -#pragma mark - +#import "FLEMethodChannel.h" NSString const *FLEMethodNotImplemented = @"notimplemented"; diff --git a/library/macos/FLECodecs.h b/library/macos/FLEMethodCodec.h similarity index 63% rename from library/macos/FLECodecs.h rename to library/macos/FLEMethodCodec.h index 12b361605..9d25148ca 100644 --- a/library/macos/FLECodecs.h +++ b/library/macos/FLEMethodCodec.h @@ -14,34 +14,8 @@ #import -#import "FLEMethods.h" - -@protocol FLEMessageCodec -/** - * Returns the shared instance of the codec. - */ -+ (nonnull instancetype)sharedInstance; - -/** - * Returns a binary encoding of the given |message|, or nil if the message cannot be - * serialized by this codec. - */ -- (nullable NSData*)encode:(nullable id)message; - -/** - * Returns the decoded mesasge, or nil if it cannot be decoded. - */ -- (nullable id)decode:(nullable NSData*)messageData; -@end - -/** - * A codec that uses JSON as the encoding format. Messages using this codec must be serializable - * to JSON. - */ -@interface FLEJSONMessageCodec : NSObject -@end - -#pragma mark - +#import "FLEMethodCall.h" +#import "FLEMethodError.h" /** * Translates between a binary message and higher-level method call and response/error objects. @@ -77,12 +51,3 @@ - (nullable NSData*)encodeErrorEnvelope:(nonnull FLEMethodError*)error; @end - -/** - * A codec that uses JSON as the encoding format. Method arguments and error details for plugins - * using this codec must be serializable to JSON. - */ -@interface FLEJSONMethodCodec : NSObject -@end - -// TODO: Implement the other core Flutter codecs. Issue #67. diff --git a/library/macos/FLEMethods.h b/library/macos/FLEMethodError.h similarity index 66% rename from library/macos/FLEMethods.h rename to library/macos/FLEMethodError.h index f36a15db3..6a8ac79aa 100644 --- a/library/macos/FLEMethods.h +++ b/library/macos/FLEMethodError.h @@ -14,35 +14,6 @@ #import -/** - * An object encapsulating a method call from Flutter. - */ -@interface FLEMethodCall : NSObject - -/** - * Initializes an FLEMethodCall. If |arguments| is provided, it must be serializable by the codec - * used to encode the call. - */ -- (nonnull instancetype)initWithMethodName:(nonnull NSString *)name - arguments:(nullable id)arguments NS_DESIGNATED_INITIALIZER; -- (nonnull instancetype)init NS_UNAVAILABLE; - -/** - * The name of the method being called. - */ -@property(readonly, nonatomic, nonnull) NSString *methodName; - -/** - * The arguments to the method being called, if any. - * - * This object must be serializable by the codec used to encode the call. - */ -@property(readonly, nonatomic, nullable) id arguments; - -@end - -#pragma mark - - /** * An error object that can be passed to an FLEMethodResult to send an error response to the caller * on the Flutter side. @@ -55,6 +26,7 @@ - (nonnull instancetype)initWithCode:(nonnull NSString *)code message:(nullable NSString *)message details:(nullable id)details NS_DESIGNATED_INITIALIZER; + - (nonnull instancetype)init NS_UNAVAILABLE; /** diff --git a/library/macos/FLEMethods.m b/library/macos/FLEMethodError.m similarity index 74% rename from library/macos/FLEMethods.m rename to library/macos/FLEMethodError.m index ac3481089..0499aad85 100644 --- a/library/macos/FLEMethods.m +++ b/library/macos/FLEMethodError.m @@ -12,23 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "FLEMethods.h" - -@implementation FLEMethodCall - -- (nonnull instancetype)initWithMethodName:(nonnull NSString *)name - arguments:(nullable id)arguments { - self = [super init]; - if (self) { - _methodName = name; - _arguments = arguments; - } - return self; -} - -@end - -#pragma mark - +#import "FLEMethodError.h" @implementation FLEMethodError diff --git a/library/macos/FLEPlugin.h b/library/macos/FLEPlugin.h index d5b57b987..cad50efa4 100644 --- a/library/macos/FLEPlugin.h +++ b/library/macos/FLEPlugin.h @@ -14,8 +14,9 @@ #import -#import "FLEChannels.h" -#import "FLECodecs.h" +#import "FLEMethodCall.h" +#import "FLEMethodChannel.h" +#import "FLEMethodCodec.h" @class FLEViewController; diff --git a/library/macos/FLEViewController.h b/library/macos/FLEViewController.h index 74a2e05a4..51b6ac12e 100644 --- a/library/macos/FLEViewController.h +++ b/library/macos/FLEViewController.h @@ -14,7 +14,7 @@ #import -#import "FLECodecs.h" +#import "FLEMethodCodec.h" #import "FLEOpenGLContextHandling.h" #import "FLEPlugin.h" #import "FLEReshapeListener.h" diff --git a/library/macos/FlutterEmbedderMac.h b/library/macos/FlutterEmbedderMac.h index 5ca66a6b7..18ccefa39 100644 --- a/library/macos/FlutterEmbedderMac.h +++ b/library/macos/FlutterEmbedderMac.h @@ -12,10 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import "FLEBasicMessageChannel.h" #import "FLEBinaryMessenger.h" -#import "FLEChannels.h" -#import "FLECodecs.h" -#import "FLEMethods.h" +#import "FLEJSONMessageCodec.h" +#import "FLEJSONMethodCodec.h" +#import "FLEMessageCodec.h" +#import "FLEMethodCall.h" +#import "FLEMethodChannel.h" +#import "FLEMethodCodec.h" +#import "FLEMethodError.h" #import "FLEOpenGLContextHandling.h" #import "FLEPlugin.h" #import "FLEReshapeListener.h" diff --git a/library/macos/FlutterEmbedderMac.xcodeproj/project.pbxproj b/library/macos/FlutterEmbedderMac.xcodeproj/project.pbxproj index 18309c0b8..0b730ac53 100644 --- a/library/macos/FlutterEmbedderMac.xcodeproj/project.pbxproj +++ b/library/macos/FlutterEmbedderMac.xcodeproj/project.pbxproj @@ -31,12 +31,20 @@ 1EEF8E071FD1F0C300DD563C /* FLEView.h in Headers */ = {isa = PBXBuildFile; fileRef = 1EEF8E051FD1F0C300DD563C /* FLEView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1EEF8E081FD1F0C300DD563C /* FLEView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EEF8E061FD1F0C300DD563C /* FLEView.m */; }; 3389A6872159359200A27898 /* FLEBinaryMessenger.h in Headers */ = {isa = PBXBuildFile; fileRef = 3389A6862159359200A27898 /* FLEBinaryMessenger.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3389A68D215949CB00A27898 /* FLEMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = 3389A68C215949CB00A27898 /* FLEMethods.m */; }; - 3389A68F215949D600A27898 /* FLEMethods.h in Headers */ = {isa = PBXBuildFile; fileRef = 3389A68E215949D600A27898 /* FLEMethods.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 33A87EB620F6BCDB0086D21D /* FLECodecs.h in Headers */ = {isa = PBXBuildFile; fileRef = 33A87EB420F6BCDB0086D21D /* FLECodecs.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 33A87EB720F6BCDB0086D21D /* FLECodecs.m in Sources */ = {isa = PBXBuildFile; fileRef = 33A87EB520F6BCDB0086D21D /* FLECodecs.m */; }; - 33D7B59920A4F54400296EFC /* FLEChannels.h in Headers */ = {isa = PBXBuildFile; fileRef = 33D7B59720A4F54400296EFC /* FLEChannels.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 33D7B59A20A4F54400296EFC /* FLEChannels.m in Sources */ = {isa = PBXBuildFile; fileRef = 33D7B59820A4F54400296EFC /* FLEChannels.m */; }; + 3389A68D215949CB00A27898 /* FLEMethodError.m in Sources */ = {isa = PBXBuildFile; fileRef = 3389A68C215949CB00A27898 /* FLEMethodError.m */; }; + 3389A68F215949D600A27898 /* FLEMethodError.h in Headers */ = {isa = PBXBuildFile; fileRef = 3389A68E215949D600A27898 /* FLEMethodError.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 33A87EB620F6BCDB0086D21D /* FLEMethodCodec.h in Headers */ = {isa = PBXBuildFile; fileRef = 33A87EB420F6BCDB0086D21D /* FLEMethodCodec.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 33A87EB720F6BCDB0086D21D /* FLEJSONMethodCodec.m in Sources */ = {isa = PBXBuildFile; fileRef = 33A87EB520F6BCDB0086D21D /* FLEJSONMethodCodec.m */; }; + 33C0FA1A21B845F0008F8959 /* FLEBasicMessageChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 33C0FA1821B845EF008F8959 /* FLEBasicMessageChannel.m */; }; + 33C0FA1B21B845F0008F8959 /* FLEBasicMessageChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C0FA1921B845F0008F8959 /* FLEBasicMessageChannel.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 33C0FA2021B84810008F8959 /* FLEJSONMessageCodec.m in Sources */ = {isa = PBXBuildFile; fileRef = 33C0FA1C21B84810008F8959 /* FLEJSONMessageCodec.m */; }; + 33C0FA2121B84810008F8959 /* FLEJSONMethodCodec.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C0FA1D21B84810008F8959 /* FLEJSONMethodCodec.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 33C0FA2221B84810008F8959 /* FLEJSONMessageCodec.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C0FA1E21B84810008F8959 /* FLEJSONMessageCodec.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 33C0FA2321B84810008F8959 /* FLEMessageCodec.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C0FA1F21B84810008F8959 /* FLEMessageCodec.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 33C0FA2621B84AA4008F8959 /* FLEMethodCall.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C0FA2421B84AA4008F8959 /* FLEMethodCall.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 33C0FA2721B84AA4008F8959 /* FLEMethodCall.m in Sources */ = {isa = PBXBuildFile; fileRef = 33C0FA2521B84AA4008F8959 /* FLEMethodCall.m */; }; + 33D7B59920A4F54400296EFC /* FLEMethodChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 33D7B59720A4F54400296EFC /* FLEMethodChannel.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 33D7B59A20A4F54400296EFC /* FLEMethodChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 33D7B59820A4F54400296EFC /* FLEMethodChannel.m */; }; 33E202A5212BC0A800337F48 /* FLETextInputPlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 1E2492331FCF50BE00DD3BBB /* FLETextInputPlugin.h */; }; 33E202A6212BC0ED00337F48 /* FLEKeyEventPlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 64C76C2620D7BDFB00B16256 /* FLEKeyEventPlugin.h */; }; 33E202A7212BC0F100337F48 /* FLEViewController+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 6442F82C20EA6C5F00A393AE /* FLEViewController+Internal.h */; }; @@ -84,13 +92,21 @@ 1EEF8E051FD1F0C300DD563C /* FLEView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEView.h; sourceTree = ""; }; 1EEF8E061FD1F0C300DD563C /* FLEView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEView.m; sourceTree = ""; }; 3389A6862159359200A27898 /* FLEBinaryMessenger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEBinaryMessenger.h; sourceTree = ""; }; - 3389A68C215949CB00A27898 /* FLEMethods.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEMethods.m; sourceTree = ""; }; - 3389A68E215949D600A27898 /* FLEMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEMethods.h; sourceTree = ""; }; - 33A87EB420F6BCDB0086D21D /* FLECodecs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLECodecs.h; sourceTree = ""; }; - 33A87EB520F6BCDB0086D21D /* FLECodecs.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLECodecs.m; sourceTree = ""; }; + 3389A68C215949CB00A27898 /* FLEMethodError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEMethodError.m; sourceTree = ""; }; + 3389A68E215949D600A27898 /* FLEMethodError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEMethodError.h; sourceTree = ""; }; + 33A87EB420F6BCDB0086D21D /* FLEMethodCodec.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEMethodCodec.h; sourceTree = ""; }; + 33A87EB520F6BCDB0086D21D /* FLEJSONMethodCodec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEJSONMethodCodec.m; sourceTree = ""; }; 33B1650F201A5F7D00732DC9 /* FlutterEmbedder.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FlutterEmbedder.framework; path = ../../../flutter_engine_framework/macos/FlutterEmbedder.framework; sourceTree = SOURCE_ROOT; }; - 33D7B59720A4F54400296EFC /* FLEChannels.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEChannels.h; sourceTree = ""; }; - 33D7B59820A4F54400296EFC /* FLEChannels.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEChannels.m; sourceTree = ""; }; + 33C0FA1821B845EF008F8959 /* FLEBasicMessageChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEBasicMessageChannel.m; sourceTree = ""; }; + 33C0FA1921B845F0008F8959 /* FLEBasicMessageChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEBasicMessageChannel.h; sourceTree = ""; }; + 33C0FA1C21B84810008F8959 /* FLEJSONMessageCodec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEJSONMessageCodec.m; sourceTree = ""; }; + 33C0FA1D21B84810008F8959 /* FLEJSONMethodCodec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEJSONMethodCodec.h; sourceTree = ""; }; + 33C0FA1E21B84810008F8959 /* FLEJSONMessageCodec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEJSONMessageCodec.h; sourceTree = ""; }; + 33C0FA1F21B84810008F8959 /* FLEMessageCodec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEMessageCodec.h; sourceTree = ""; }; + 33C0FA2421B84AA4008F8959 /* FLEMethodCall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEMethodCall.h; sourceTree = ""; }; + 33C0FA2521B84AA4008F8959 /* FLEMethodCall.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEMethodCall.m; sourceTree = ""; }; + 33D7B59720A4F54400296EFC /* FLEMethodChannel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEMethodChannel.h; sourceTree = ""; }; + 33D7B59820A4F54400296EFC /* FLEMethodChannel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEMethodChannel.m; sourceTree = ""; }; 6442F82C20EA6C5F00A393AE /* FLEViewController+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FLEViewController+Internal.h"; sourceTree = ""; }; 64C76C2620D7BDFB00B16256 /* FLEKeyEventPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEKeyEventPlugin.h; sourceTree = ""; }; 64C76C2720D7BE2E00B16256 /* FLEKeyEventPlugin.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEKeyEventPlugin.m; sourceTree = ""; }; @@ -117,15 +133,18 @@ C4C1FE431FD74F6400691968 /* FlutterEmbedder.framework */, 1E2492371FCF50BE00DD3BBB /* FlutterEmbedderMac.h */, 1E2492451FCF536200DD3BBB /* Public */, - 33D7B59820A4F54400296EFC /* FLEChannels.m */, - 33A87EB520F6BCDB0086D21D /* FLECodecs.m */, - 3389A68C215949CB00A27898 /* FLEMethods.m */, + 33C0FA1821B845EF008F8959 /* FLEBasicMessageChannel.m */, + 33C0FA1C21B84810008F8959 /* FLEJSONMessageCodec.m */, + 33A87EB520F6BCDB0086D21D /* FLEJSONMethodCodec.m */, + 64C76C2620D7BDFB00B16256 /* FLEKeyEventPlugin.h */, + 64C76C2720D7BE2E00B16256 /* FLEKeyEventPlugin.m */, + 33C0FA2521B84AA4008F8959 /* FLEMethodCall.m */, + 33D7B59820A4F54400296EFC /* FLEMethodChannel.m */, + 3389A68C215949CB00A27898 /* FLEMethodError.m */, AA8AE8B71FD948AC00B6FB31 /* FLETextInputModel.h */, AA8AE8B91FD948BA00B6FB31 /* FLETextInputModel.m */, 1E2492331FCF50BE00DD3BBB /* FLETextInputPlugin.h */, 1E2492341FCF50BE00DD3BBB /* FLETextInputPlugin.m */, - 64C76C2620D7BDFB00B16256 /* FLEKeyEventPlugin.h */, - 64C76C2720D7BE2E00B16256 /* FLEKeyEventPlugin.m */, 1EEF8E061FD1F0C300DD563C /* FLEView.m */, 6442F82C20EA6C5F00A393AE /* FLEViewController+Internal.h */, 1E2492361FCF50BE00DD3BBB /* FLEViewController.m */, @@ -146,10 +165,15 @@ 1E2492451FCF536200DD3BBB /* Public */ = { isa = PBXGroup; children = ( + 33C0FA1921B845F0008F8959 /* FLEBasicMessageChannel.h */, 3389A6862159359200A27898 /* FLEBinaryMessenger.h */, - 33D7B59720A4F54400296EFC /* FLEChannels.h */, - 33A87EB420F6BCDB0086D21D /* FLECodecs.h */, - 3389A68E215949D600A27898 /* FLEMethods.h */, + 33C0FA1E21B84810008F8959 /* FLEJSONMessageCodec.h */, + 33C0FA1D21B84810008F8959 /* FLEJSONMethodCodec.h */, + 33C0FA1F21B84810008F8959 /* FLEMessageCodec.h */, + 33C0FA2421B84AA4008F8959 /* FLEMethodCall.h */, + 33D7B59720A4F54400296EFC /* FLEMethodChannel.h */, + 33A87EB420F6BCDB0086D21D /* FLEMethodCodec.h */, + 3389A68E215949D600A27898 /* FLEMethodError.h */, 1E24922F1FCF50BE00DD3BBB /* FLEOpenGLContextHandling.h */, 1E2492311FCF50BE00DD3BBB /* FLEPlugin.h */, 1E2492321FCF50BE00DD3BBB /* FLEReshapeListener.h */, @@ -175,20 +199,24 @@ buildActionMask = 2147483647; files = ( 33E202A6212BC0ED00337F48 /* FLEKeyEventPlugin.h in Headers */, + 33C0FA2621B84AA4008F8959 /* FLEMethodCall.h in Headers */, 1E24923B1FCF50BE00DD3BBB /* FLEPlugin.h in Headers */, 3389A6872159359200A27898 /* FLEBinaryMessenger.h in Headers */, - 33D7B59920A4F54400296EFC /* FLEChannels.h in Headers */, + 33D7B59920A4F54400296EFC /* FLEMethodChannel.h in Headers */, 1E24923F1FCF50BE00DD3BBB /* FLEViewController.h in Headers */, 33E202A5212BC0A800337F48 /* FLETextInputPlugin.h in Headers */, 1E2492411FCF50BE00DD3BBB /* FlutterEmbedderMac.h in Headers */, 1E2492391FCF50BE00DD3BBB /* FLEOpenGLContextHandling.h in Headers */, + 33C0FA1B21B845F0008F8959 /* FLEBasicMessageChannel.h in Headers */, + 33C0FA2321B84810008F8959 /* FLEMessageCodec.h in Headers */, 1E24923C1FCF50BE00DD3BBB /* FLEReshapeListener.h in Headers */, - 3389A689215935A100A27898 /* FLEMethods.h in Headers */, + 33C0FA2121B84810008F8959 /* FLEJSONMethodCodec.h in Headers */, 33E202A7212BC0F100337F48 /* FLEViewController+Internal.h in Headers */, AA8AE8B81FD948AC00B6FB31 /* FLETextInputModel.h in Headers */, 1EEF8E071FD1F0C300DD563C /* FLEView.h in Headers */, - 33A87EB620F6BCDB0086D21D /* FLECodecs.h in Headers */, - 3389A68F215949D600A27898 /* FLEMethods.h in Headers */, + 33C0FA2221B84810008F8959 /* FLEJSONMessageCodec.h in Headers */, + 33A87EB620F6BCDB0086D21D /* FLEMethodCodec.h in Headers */, + 3389A68F215949D600A27898 /* FLEMethodError.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -283,13 +311,16 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 33D7B59A20A4F54400296EFC /* FLEChannels.m in Sources */, + 33D7B59A20A4F54400296EFC /* FLEMethodChannel.m in Sources */, 1E2492401FCF50BE00DD3BBB /* FLEViewController.m in Sources */, - 3389A68D215949CB00A27898 /* FLEMethods.m in Sources */, + 3389A68D215949CB00A27898 /* FLEMethodError.m in Sources */, 64C76C2820D7BE2E00B16256 /* FLEKeyEventPlugin.m in Sources */, + 33C0FA2721B84AA4008F8959 /* FLEMethodCall.m in Sources */, + 33C0FA2021B84810008F8959 /* FLEJSONMessageCodec.m in Sources */, + 33C0FA1A21B845F0008F8959 /* FLEBasicMessageChannel.m in Sources */, 1E24923E1FCF50BE00DD3BBB /* FLETextInputPlugin.m in Sources */, 1EEF8E081FD1F0C300DD563C /* FLEView.m in Sources */, - 33A87EB720F6BCDB0086D21D /* FLECodecs.m in Sources */, + 33A87EB720F6BCDB0086D21D /* FLEJSONMethodCodec.m in Sources */, AA8AE8BA1FD948BA00B6FB31 /* FLETextInputModel.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; From 109bf859f9282a805dde1e9d9c1c06654396b753 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 5 Dec 2018 10:21:20 -0800 Subject: [PATCH 3/4] Nullability cleanup --- library/macos/FLEMethodCall.m | 3 +-- library/macos/FLEMethodError.m | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/library/macos/FLEMethodCall.m b/library/macos/FLEMethodCall.m index 9b11a42fc..35d263365 100644 --- a/library/macos/FLEMethodCall.m +++ b/library/macos/FLEMethodCall.m @@ -16,8 +16,7 @@ @implementation FLEMethodCall -- (nonnull instancetype)initWithMethodName:(nonnull NSString *)name - arguments:(nullable id)arguments { +- (instancetype)initWithMethodName:(NSString *)name arguments:(id)arguments { self = [super init]; if (self) { _methodName = name; diff --git a/library/macos/FLEMethodError.m b/library/macos/FLEMethodError.m index 0499aad85..20ffe8b75 100644 --- a/library/macos/FLEMethodError.m +++ b/library/macos/FLEMethodError.m @@ -16,9 +16,7 @@ @implementation FLEMethodError -- (nonnull instancetype)initWithCode:(nonnull NSString *)code - message:(nullable NSString *)message - details:(nullable id)details { +- (instancetype)initWithCode:(NSString *)code message:(NSString *)message details:(id)details { self = [super init]; if (self) { _code = code; From f8a17027420b39c163169d037dae50b454f379af Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 5 Dec 2018 11:45:12 -0800 Subject: [PATCH 4/4] Add missing comment --- library/macos/FLEBasicMessageChannel.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/macos/FLEBasicMessageChannel.h b/library/macos/FLEBasicMessageChannel.h index ec2bb77a7..7a2462437 100644 --- a/library/macos/FLEBasicMessageChannel.h +++ b/library/macos/FLEBasicMessageChannel.h @@ -29,6 +29,9 @@ typedef void (^FLEMessageReply)(id _Nullable reply); */ typedef void (^FLEMessageHandler)(id _Nullable message, FLEMessageReply _Nonnull callback); +/** + * A channel for communicating with the Flutter engine by sending asynchronous messages. + */ @interface FLEBasicMessageChannel : NSObject // TODO: support +messageChannelWithName:binaryMessenger: once the standard codec is supported