Skip to content

Commit

Permalink
generate api outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
schultek committed Dec 14, 2023
1 parent 0f39fd3 commit 6f85a29
Show file tree
Hide file tree
Showing 15 changed files with 6,037 additions and 7,893 deletions.
25 changes: 10 additions & 15 deletions packages/pigeon/example/app/macos/Runner/messages.g.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ typedef NS_ENUM(NSUInteger, PGNCode) {
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithName:(nullable NSString *)name
description:(nullable NSString *)description
code:(PGNCode)code
data:(NSDictionary<NSString *, NSString *> *)data;
@property(nonatomic, copy, nullable) NSString *name;
@property(nonatomic, copy, nullable) NSString *description;
description:(nullable NSString *)description
code:(PGNCode)code
data:(NSDictionary<NSString *, NSString *> *)data;
@property(nonatomic, copy, nullable) NSString * name;
@property(nonatomic, copy, nullable) NSString * description;
@property(nonatomic, assign) PGNCode code;
@property(nonatomic, copy) NSDictionary<NSString *, NSString *> *data;
@property(nonatomic, copy) NSDictionary<NSString *, NSString *> * data;
@end

/// The codec used by PGNExampleHostApi.
Expand All @@ -46,23 +46,18 @@ NSObject<FlutterMessageCodec> *PGNExampleHostApiGetCodec(void);
/// @return `nil` only when `error != nil`.
- (nullable NSString *)getHostLanguageWithError:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)addNumber:(NSInteger)a
toNumber:(NSInteger)b
error:(FlutterError *_Nullable *_Nonnull)error;
- (void)sendMessageMessage:(PGNMessageData *)message
completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
- (nullable NSNumber *)addNumber:(NSInteger)a toNumber:(NSInteger)b error:(FlutterError *_Nullable *_Nonnull)error;
- (void)sendMessageMessage:(PGNMessageData *)message completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
@end

extern void SetUpPGNExampleHostApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<PGNExampleHostApi> *_Nullable api);
extern void SetUpPGNExampleHostApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<PGNExampleHostApi> *_Nullable api);

/// The codec used by PGNMessageFlutterApi.
NSObject<FlutterMessageCodec> *PGNMessageFlutterApiGetCodec(void);

@interface PGNMessageFlutterApi : NSObject
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;
- (void)flutterMethodAString:(nullable NSString *)aString
completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
- (void)flutterMethodAString:(nullable NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
@end

NS_ASSUME_NONNULL_END
107 changes: 45 additions & 62 deletions packages/pigeon/example/app/macos/Runner/messages.g.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@
}

static FlutterError *createConnectionError(NSString *channelName) {
return [FlutterError
errorWithCode:@"channel-error"
message:[NSString stringWithFormat:@"%@/%@/%@",
@"Unable to establish connection on channel: '",
channelName, @"'."]
details:@""];
return [FlutterError errorWithCode:@"channel-error" message:[NSString stringWithFormat:@"%@/%@/%@", @"Unable to establish connection on channel: '", channelName, @"'."] details:@""];
}

static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
Expand All @@ -57,10 +52,10 @@ - (NSArray *)toList;

@implementation PGNMessageData
+ (instancetype)makeWithName:(nullable NSString *)name
description:(nullable NSString *)description
code:(PGNCode)code
data:(NSDictionary<NSString *, NSString *> *)data {
PGNMessageData *pigeonResult = [[PGNMessageData alloc] init];
description:(nullable NSString *)description
code:(PGNCode)code
data:(NSDictionary<NSString *, NSString *> *)data {
PGNMessageData* pigeonResult = [[PGNMessageData alloc] init];
pigeonResult.name = name;
pigeonResult.description = description;
pigeonResult.code = code;
Expand Down Expand Up @@ -93,7 +88,7 @@ @interface PGNExampleHostApiCodecReader : FlutterStandardReader
@implementation PGNExampleHostApiCodecReader
- (nullable id)readValueOfType:(UInt8)type {
switch (type) {
case 128:
case 128:
return [PGNMessageData fromList:[self readValue]];
default:
return [super readValueOfType:type];
Expand Down Expand Up @@ -129,25 +124,21 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data {
static FlutterStandardMessageCodec *sSharedObject = nil;
static dispatch_once_t sPred = 0;
dispatch_once(&sPred, ^{
PGNExampleHostApiCodecReaderWriter *readerWriter =
[[PGNExampleHostApiCodecReaderWriter alloc] init];
PGNExampleHostApiCodecReaderWriter *readerWriter = [[PGNExampleHostApiCodecReaderWriter alloc] init];
sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
});
return sSharedObject;
}

void SetUpPGNExampleHostApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<PGNExampleHostApi> *api) {
void SetUpPGNExampleHostApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<PGNExampleHostApi> *api) {
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage"
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage"
binaryMessenger:binaryMessenger
codec:PGNExampleHostApiGetCodec()];
codec:PGNExampleHostApiGetCodec()];
if (api) {
NSCAssert(
[api respondsToSelector:@selector(getHostLanguageWithError:)],
@"PGNExampleHostApi api (%@) doesn't respond to @selector(getHostLanguageWithError:)",
api);
NSCAssert([api respondsToSelector:@selector(getHostLanguageWithError:)], @"PGNExampleHostApi api (%@) doesn't respond to @selector(getHostLanguageWithError:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
NSString *output = [api getHostLanguageWithError:&error];
Expand All @@ -158,15 +149,13 @@ void SetUpPGNExampleHostApi(id<FlutterBinaryMessenger> binaryMessenger,
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add"
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add"
binaryMessenger:binaryMessenger
codec:PGNExampleHostApiGetCodec()];
codec:PGNExampleHostApiGetCodec()];
if (api) {
NSCAssert(
[api respondsToSelector:@selector(addNumber:toNumber:error:)],
@"PGNExampleHostApi api (%@) doesn't respond to @selector(addNumber:toNumber:error:)",
api);
NSCAssert([api respondsToSelector:@selector(addNumber:toNumber:error:)], @"PGNExampleHostApi api (%@) doesn't respond to @selector(addNumber:toNumber:error:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSInteger arg_a = [GetNullableObjectAtIndex(args, 0) integerValue];
Expand All @@ -180,22 +169,19 @@ void SetUpPGNExampleHostApi(id<FlutterBinaryMessenger> binaryMessenger,
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage"
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage"
binaryMessenger:binaryMessenger
codec:PGNExampleHostApiGetCodec()];
codec:PGNExampleHostApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(sendMessageMessage:completion:)],
@"PGNExampleHostApi api (%@) doesn't respond to "
@"@selector(sendMessageMessage:completion:)",
api);
NSCAssert([api respondsToSelector:@selector(sendMessageMessage:completion:)], @"PGNExampleHostApi api (%@) doesn't respond to @selector(sendMessageMessage:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
PGNMessageData *arg_message = GetNullableObjectAtIndex(args, 0);
[api sendMessageMessage:arg_message
completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
[api sendMessageMessage:arg_message completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
} else {
[channel setMessageHandler:nil];
Expand All @@ -221,28 +207,25 @@ - (instancetype)initWithBinaryMessenger:(NSObject<FlutterBinaryMessenger> *)bina
}
return self;
}
- (void)flutterMethodAString:(nullable NSString *)arg_aString
completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion {
NSString *channelName =
@"dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod";
- (void)flutterMethodAString:(nullable NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion {
NSString *channelName = @"dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod";
FlutterBasicMessageChannel *channel =
[FlutterBasicMessageChannel messageChannelWithName:channelName
binaryMessenger:self.binaryMessenger
codec:PGNMessageFlutterApiGetCodec()];
[channel sendMessage:@[ arg_aString ?: [NSNull null] ]
reply:^(NSArray<id> *reply) {
if (reply != nil) {
if (reply.count > 1) {
completion(nil, [FlutterError errorWithCode:reply[0]
message:reply[1]
details:reply[2]]);
} else {
NSString *output = reply[0] == [NSNull null] ? nil : reply[0];
completion(output, nil);
}
} else {
completion(nil, createConnectionError(channelName));
}
}];
[FlutterBasicMessageChannel
messageChannelWithName:channelName
binaryMessenger:self.binaryMessenger
codec:PGNMessageFlutterApiGetCodec()];
[channel sendMessage:@[arg_aString ?: [NSNull null]] reply:^(NSArray<id> *reply) {
if (reply != nil) {
if (reply.count > 1) {
completion(nil, [FlutterError errorWithCode:reply[0] message:reply[1] details:reply[2]]);
} else {
NSString *output = reply[0] == [NSNull null] ? nil : reply[0];
completion(output, nil);
}
} else {
completion(nil, createConnectionError(channelName));
}
}];
}
@end

Loading

0 comments on commit 6f85a29

Please sign in to comment.