Pigeon: Renamed HostApis

This commit is contained in:
gianlucaparadise 2021-11-01 19:59:03 +01:00
parent 1cf4e493d6
commit 1dd9ab2370
6 changed files with 82 additions and 82 deletions

View file

@ -1,8 +1,8 @@
pigeon: # Generates the typesafe bridge between host and flutter pigeon: # Generates the typesafe bridge between host and flutter
flutter pub run pigeon \ flutter pub run pigeon \
--input lib/src/HostApisDefinition.dart \ --input lib/src/PlatformBridgeApisDefinition.dart \
--dart_out lib/src/HostApis.dart \ --dart_out lib/src/PlatformBridgeApis.dart \
--objc_header_out ios/Classes/HostApis.h \ --objc_header_out ios/Classes/PlatformBridgeApis.h \
--objc_source_out ios/Classes/HostApis.m \ --objc_source_out ios/Classes/PlatformBridgeApis.m \
--java_out ./android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java \ --java_out ./android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java \
--java_package "com.gianlucaparadise.flutter_cast_framework" --java_package "com.gianlucaparadise.flutter_cast_framework"

View file

@ -17,7 +17,7 @@ import java.util.HashMap;
/** Generated class from Pigeon. */ /** Generated class from Pigeon. */
@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"})
public class HostApis { public class PlatformBridgeApis {
/** Generated class from Pigeon that represents data sent in messages. */ /** Generated class from Pigeon that represents data sent in messages. */
public static class CastMessage { public static class CastMessage {
@ -44,9 +44,9 @@ public class HostApis {
return fromMapResult; return fromMapResult;
} }
} }
private static class CastApiCodec extends StandardMessageCodec { private static class CastHostApiCodec extends StandardMessageCodec {
public static final CastApiCodec INSTANCE = new CastApiCodec(); public static final CastHostApiCodec INSTANCE = new CastHostApiCodec();
private CastApiCodec() {} private CastHostApiCodec() {}
@Override @Override
protected Object readValueOfType(byte type, ByteBuffer buffer) { protected Object readValueOfType(byte type, ByteBuffer buffer) {
switch (type) { switch (type) {
@ -71,20 +71,20 @@ public class HostApis {
} }
/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/ /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
public interface CastApi { public interface CastHostApi {
void sendMessage(CastMessage message); void sendMessage(CastMessage message);
void showCastDialog(); void showCastDialog();
/** The codec used by CastApi. */ /** The codec used by CastHostApi. */
static MessageCodec<Object> getCodec() { static MessageCodec<Object> getCodec() {
return CastApiCodec.INSTANCE; return CastHostApiCodec.INSTANCE;
} }
/** Sets up an instance of `CastApi` to handle messages through the `binaryMessenger`. */ /** Sets up an instance of `CastHostApi` to handle messages through the `binaryMessenger`. */
static void setup(BinaryMessenger binaryMessenger, CastApi api) { static void setup(BinaryMessenger binaryMessenger, CastHostApi api) {
{ {
BasicMessageChannel<Object> channel = BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastApi.sendMessage", getCodec()); new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.sendMessage", getCodec());
if (api != null) { if (api != null) {
channel.setMessageHandler((message, reply) -> { channel.setMessageHandler((message, reply) -> {
Map<String, Object> wrapped = new HashMap<>(); Map<String, Object> wrapped = new HashMap<>();
@ -108,7 +108,7 @@ public class HostApis {
} }
{ {
BasicMessageChannel<Object> channel = BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastApi.showCastDialog", getCodec()); new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.showCastDialog", getCodec());
if (api != null) { if (api != null) {
channel.setMessageHandler((message, reply) -> { channel.setMessageHandler((message, reply) -> {
Map<String, Object> wrapped = new HashMap<>(); Map<String, Object> wrapped = new HashMap<>();
@ -182,6 +182,13 @@ public class HostApis {
callback.reply(null); callback.reply(null);
}); });
} }
public void onMessageReceived(CastMessage messageArg, Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastFlutterApi.onMessageReceived", getCodec());
channel.send(new ArrayList<Object>(Arrays.asList(messageArg)), channelReply -> {
callback.reply(null);
});
}
public void onSessionStarting(Reply<Void> callback) { public void onSessionStarting(Reply<Void> callback) {
BasicMessageChannel<Object> channel = BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastFlutterApi.onSessionStarting", getCodec()); new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastFlutterApi.onSessionStarting", getCodec());
@ -245,13 +252,6 @@ public class HostApis {
callback.reply(null); callback.reply(null);
}); });
} }
public void onMessageReceived(CastMessage messageArg, Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastFlutterApi.onMessageReceived", getCodec());
channel.send(new ArrayList<Object>(Arrays.asList(messageArg)), channelReply -> {
callback.reply(null);
});
}
} }
private static Map<String, Object> wrapError(Throwable exception) { private static Map<String, Object> wrapError(Throwable exception) {
Map<String, Object> errorMap = new HashMap<>(); Map<String, Object> errorMap = new HashMap<>();

View file

@ -15,15 +15,15 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy, nullable) NSString * message; @property(nonatomic, copy, nullable) NSString * message;
@end @end
/// The codec used by CastApi. /// The codec used by CastHostApi.
NSObject<FlutterMessageCodec> *CastApiGetCodec(void); NSObject<FlutterMessageCodec> *CastHostApiGetCodec(void);
@protocol CastApi @protocol CastHostApi
- (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error; - (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error;
- (void)showCastDialogWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)showCastDialogWithError:(FlutterError *_Nullable *_Nonnull)error;
@end @end
extern void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi> *_Nullable api); extern void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastHostApi> *_Nullable api);
/// The codec used by CastFlutterApi. /// The codec used by CastFlutterApi.
NSObject<FlutterMessageCodec> *CastFlutterApiGetCodec(void); NSObject<FlutterMessageCodec> *CastFlutterApiGetCodec(void);
@ -32,6 +32,7 @@ NSObject<FlutterMessageCodec> *CastFlutterApiGetCodec(void);
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger; - (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;
- (void)getSessionMessageNamespacesWithCompletion:(void(^)(NSArray<NSString *> *, NSError *_Nullable))completion; - (void)getSessionMessageNamespacesWithCompletion:(void(^)(NSArray<NSString *> *, NSError *_Nullable))completion;
- (void)onCastStateChangedCastState:(NSNumber *)castState completion:(void(^)(NSError *_Nullable))completion; - (void)onCastStateChangedCastState:(NSNumber *)castState completion:(void(^)(NSError *_Nullable))completion;
- (void)onMessageReceivedMessage:(CastMessage *)message completion:(void(^)(NSError *_Nullable))completion;
- (void)onSessionStartingWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionStartingWithCompletion:(void(^)(NSError *_Nullable))completion;
- (void)onSessionStartedWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionStartedWithCompletion:(void(^)(NSError *_Nullable))completion;
- (void)onSessionStartFailedWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionStartFailedWithCompletion:(void(^)(NSError *_Nullable))completion;
@ -41,6 +42,5 @@ NSObject<FlutterMessageCodec> *CastFlutterApiGetCodec(void);
- (void)onSessionResumedWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionResumedWithCompletion:(void(^)(NSError *_Nullable))completion;
- (void)onSessionResumeFailedWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionResumeFailedWithCompletion:(void(^)(NSError *_Nullable))completion;
- (void)onSessionSuspendedWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionSuspendedWithCompletion:(void(^)(NSError *_Nullable))completion;
- (void)onMessageReceivedMessage:(CastMessage *)message completion:(void(^)(NSError *_Nullable))completion;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View file

@ -1,6 +1,6 @@
// Autogenerated from Pigeon (v1.0.8), do not edit directly. // Autogenerated from Pigeon (v1.0.8), do not edit directly.
// See also: https://pub.dev/packages/pigeon // See also: https://pub.dev/packages/pigeon
#import "HostApis.h" #import "PlatformBridgeApis.h"
#import <Flutter/Flutter.h> #import <Flutter/Flutter.h>
#if !__has_feature(objc_arc) #if !__has_feature(objc_arc)
@ -45,9 +45,9 @@ static NSDictionary<NSString *, id> *wrapResult(id result, FlutterError *error)
} }
@end @end
@interface CastApiCodecReader : FlutterStandardReader @interface CastHostApiCodecReader : FlutterStandardReader
@end @end
@implementation CastApiCodecReader @implementation CastHostApiCodecReader
- (nullable id)readValueOfType:(UInt8)type - (nullable id)readValueOfType:(UInt8)type
{ {
switch (type) { switch (type) {
@ -61,9 +61,9 @@ static NSDictionary<NSString *, id> *wrapResult(id result, FlutterError *error)
} }
@end @end
@interface CastApiCodecWriter : FlutterStandardWriter @interface CastHostApiCodecWriter : FlutterStandardWriter
@end @end
@implementation CastApiCodecWriter @implementation CastHostApiCodecWriter
- (void)writeValue:(id)value - (void)writeValue:(id)value
{ {
if ([value isKindOfClass:[CastMessage class]]) { if ([value isKindOfClass:[CastMessage class]]) {
@ -76,37 +76,37 @@ static NSDictionary<NSString *, id> *wrapResult(id result, FlutterError *error)
} }
@end @end
@interface CastApiCodecReaderWriter : FlutterStandardReaderWriter @interface CastHostApiCodecReaderWriter : FlutterStandardReaderWriter
@end @end
@implementation CastApiCodecReaderWriter @implementation CastHostApiCodecReaderWriter
- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - (FlutterStandardWriter *)writerWithData:(NSMutableData *)data {
return [[CastApiCodecWriter alloc] initWithData:data]; return [[CastHostApiCodecWriter alloc] initWithData:data];
} }
- (FlutterStandardReader *)readerWithData:(NSData *)data { - (FlutterStandardReader *)readerWithData:(NSData *)data {
return [[CastApiCodecReader alloc] initWithData:data]; return [[CastHostApiCodecReader alloc] initWithData:data];
} }
@end @end
NSObject<FlutterMessageCodec> *CastApiGetCodec() { NSObject<FlutterMessageCodec> *CastHostApiGetCodec() {
static dispatch_once_t s_pred = 0; static dispatch_once_t s_pred = 0;
static FlutterStandardMessageCodec *s_sharedObject = nil; static FlutterStandardMessageCodec *s_sharedObject = nil;
dispatch_once(&s_pred, ^{ dispatch_once(&s_pred, ^{
CastApiCodecReaderWriter *readerWriter = [[CastApiCodecReaderWriter alloc] init]; CastHostApiCodecReaderWriter *readerWriter = [[CastHostApiCodecReaderWriter alloc] init];
s_sharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; s_sharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
}); });
return s_sharedObject; return s_sharedObject;
} }
void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi> *api) { void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastHostApi> *api) {
{ {
FlutterBasicMessageChannel *channel = FlutterBasicMessageChannel *channel =
[FlutterBasicMessageChannel [FlutterBasicMessageChannel
messageChannelWithName:@"dev.flutter.pigeon.CastApi.sendMessage" messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.sendMessage"
binaryMessenger:binaryMessenger binaryMessenger:binaryMessenger
codec:CastApiGetCodec()]; codec:CastHostApiGetCodec()];
if (api) { if (api) {
NSCAssert([api respondsToSelector:@selector(sendMessageMessage:error:)], @"CastApi api (%@) doesn't respond to @selector(sendMessageMessage:error:)", api); NSCAssert([api respondsToSelector:@selector(sendMessageMessage:error:)], @"CastHostApi api (%@) doesn't respond to @selector(sendMessageMessage:error:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message; NSArray *args = message;
CastMessage *arg_message = args[0]; CastMessage *arg_message = args[0];
@ -122,11 +122,11 @@ void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi>
{ {
FlutterBasicMessageChannel *channel = FlutterBasicMessageChannel *channel =
[FlutterBasicMessageChannel [FlutterBasicMessageChannel
messageChannelWithName:@"dev.flutter.pigeon.CastApi.showCastDialog" messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.showCastDialog"
binaryMessenger:binaryMessenger binaryMessenger:binaryMessenger
codec:CastApiGetCodec()]; codec:CastHostApiGetCodec()];
if (api) { if (api) {
NSCAssert([api respondsToSelector:@selector(showCastDialogWithError:)], @"CastApi api (%@) doesn't respond to @selector(showCastDialogWithError:)", api); NSCAssert([api respondsToSelector:@selector(showCastDialogWithError:)], @"CastHostApi api (%@) doesn't respond to @selector(showCastDialogWithError:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error; FlutterError *error;
[api showCastDialogWithError:&error]; [api showCastDialogWithError:&error];
@ -225,6 +225,16 @@ NSObject<FlutterMessageCodec> *CastFlutterApiGetCodec() {
completion(nil); completion(nil);
}]; }];
} }
- (void)onMessageReceivedMessage:(CastMessage *)arg_message completion:(void(^)(NSError *_Nullable))completion {
FlutterBasicMessageChannel *channel =
[FlutterBasicMessageChannel
messageChannelWithName:@"dev.flutter.pigeon.CastFlutterApi.onMessageReceived"
binaryMessenger:self.binaryMessenger
codec:CastFlutterApiGetCodec()];
[channel sendMessage:@[arg_message] reply:^(id reply) {
completion(nil);
}];
}
- (void)onSessionStartingWithCompletion:(void(^)(NSError *_Nullable))completion { - (void)onSessionStartingWithCompletion:(void(^)(NSError *_Nullable))completion {
FlutterBasicMessageChannel *channel = FlutterBasicMessageChannel *channel =
[FlutterBasicMessageChannel [FlutterBasicMessageChannel
@ -315,14 +325,4 @@ NSObject<FlutterMessageCodec> *CastFlutterApiGetCodec() {
completion(nil); completion(nil);
}]; }];
} }
- (void)onMessageReceivedMessage:(CastMessage *)arg_message completion:(void(^)(NSError *_Nullable))completion {
FlutterBasicMessageChannel *channel =
[FlutterBasicMessageChannel
messageChannelWithName:@"dev.flutter.pigeon.CastFlutterApi.onMessageReceived"
binaryMessenger:self.binaryMessenger
codec:CastFlutterApiGetCodec()];
[channel sendMessage:@[arg_message] reply:^(id reply) {
completion(nil);
}];
}
@end @end

View file

@ -27,8 +27,8 @@ class CastMessage {
} }
} }
class _CastApiCodec extends StandardMessageCodec { class _CastHostApiCodec extends StandardMessageCodec {
const _CastApiCodec(); const _CastHostApiCodec();
@override @override
void writeValue(WriteBuffer buffer, Object? value) { void writeValue(WriteBuffer buffer, Object? value) {
if (value is CastMessage) { if (value is CastMessage) {
@ -52,19 +52,19 @@ class _CastApiCodec extends StandardMessageCodec {
} }
} }
class CastApi { class CastHostApi {
/// Constructor for [CastApi]. The [binaryMessenger] named argument is /// Constructor for [CastHostApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default /// available for dependency injection. If it is left null, the default
/// BinaryMessenger will be used which routes to the host platform. /// BinaryMessenger will be used which routes to the host platform.
CastApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; CastHostApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger;
final BinaryMessenger? _binaryMessenger; final BinaryMessenger? _binaryMessenger;
static const MessageCodec<Object?> codec = _CastApiCodec(); static const MessageCodec<Object?> codec = _CastHostApiCodec();
Future<void> sendMessage(CastMessage arg_message) async { Future<void> sendMessage(CastMessage arg_message) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.CastApi.sendMessage', codec, binaryMessenger: _binaryMessenger); 'dev.flutter.pigeon.CastHostApi.sendMessage', codec, binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap = final Map<Object?, Object?>? replyMap =
await channel.send(<Object>[arg_message]) as Map<Object?, Object?>?; await channel.send(<Object>[arg_message]) as Map<Object?, Object?>?;
if (replyMap == null) { if (replyMap == null) {
@ -87,7 +87,7 @@ class CastApi {
Future<void> showCastDialog() async { Future<void> showCastDialog() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.CastApi.showCastDialog', codec, binaryMessenger: _binaryMessenger); 'dev.flutter.pigeon.CastHostApi.showCastDialog', codec, binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap = final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?; await channel.send(null) as Map<Object?, Object?>?;
if (replyMap == null) { if (replyMap == null) {
@ -138,6 +138,7 @@ abstract class CastFlutterApi {
List<String?> getSessionMessageNamespaces(); List<String?> getSessionMessageNamespaces();
void onCastStateChanged(int castState); void onCastStateChanged(int castState);
void onMessageReceived(CastMessage message);
void onSessionStarting(); void onSessionStarting();
void onSessionStarted(); void onSessionStarted();
void onSessionStartFailed(); void onSessionStartFailed();
@ -147,7 +148,6 @@ abstract class CastFlutterApi {
void onSessionResumed(); void onSessionResumed();
void onSessionResumeFailed(); void onSessionResumeFailed();
void onSessionSuspended(); void onSessionSuspended();
void onMessageReceived(CastMessage message);
static void setup(CastFlutterApi? api) { static void setup(CastFlutterApi? api) {
{ {
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
@ -178,6 +178,22 @@ abstract class CastFlutterApi {
}); });
} }
} }
{
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.CastFlutterApi.onMessageReceived', codec);
if (api == null) {
channel.setMessageHandler(null);
} else {
channel.setMessageHandler((Object? message) async {
assert(message != null, 'Argument for dev.flutter.pigeon.CastFlutterApi.onMessageReceived was null.');
final List<Object?> args = (message as List<Object?>?)!;
final CastMessage? arg_message = args[0] as CastMessage?;
assert(arg_message != null, 'Argument for dev.flutter.pigeon.CastFlutterApi.onMessageReceived was null, expected non-null CastMessage.');
api.onMessageReceived(arg_message!);
return;
});
}
}
{ {
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.CastFlutterApi.onSessionStarting', codec); 'dev.flutter.pigeon.CastFlutterApi.onSessionStarting', codec);
@ -295,21 +311,5 @@ abstract class CastFlutterApi {
}); });
} }
} }
{
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.CastFlutterApi.onMessageReceived', codec);
if (api == null) {
channel.setMessageHandler(null);
} else {
channel.setMessageHandler((Object? message) async {
assert(message != null, 'Argument for dev.flutter.pigeon.CastFlutterApi.onMessageReceived was null.');
final List<Object?> args = (message as List<Object?>?)!;
final CastMessage? arg_message = args[0] as CastMessage?;
assert(arg_message != null, 'Argument for dev.flutter.pigeon.CastFlutterApi.onMessageReceived was null, expected non-null CastMessage.');
api.onMessageReceived(arg_message!);
return;
});
}
}
} }
} }

View file

@ -6,7 +6,7 @@ class CastMessage {
} }
@HostApi() @HostApi()
abstract class CastApi { abstract class CastHostApi {
void sendMessage(CastMessage message); void sendMessage(CastMessage message);
void showCastDialog(); void showCastDialog();
} }