diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 366e387ce00..ec8daa80804 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 22.5.0 + +* [swift] Adds implementation for `@ProxyApi`. + ## 22.4.2 * Updates `README.md` to replace the deprecated `flutter pub run pigeon` command with `dart run pigeon`. diff --git a/packages/pigeon/CONTRIBUTING.md b/packages/pigeon/CONTRIBUTING.md index e19f6958623..4bf96c20808 100644 --- a/packages/pigeon/CONTRIBUTING.md +++ b/packages/pigeon/CONTRIBUTING.md @@ -62,7 +62,7 @@ This is what the temporary generated code that the _PigeonIsolate_ executes looks like (see [State Diagram](#state-diagram)): ```dart -import 'path/to/supplied/pigeon/file.dart' +import 'path/to/supplied/pigeon/file.dart'; import 'dart:io'; import 'dart:isolate'; import 'package:pigeon/pigeon_lib.dart'; diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 981c428a159..1c93d4630e3 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -8,6 +8,7 @@ import 'package:meta/meta.dart'; import 'generator_tools.dart'; import 'kotlin_generator.dart' show KotlinProxyApiOptions; import 'pigeon_lib.dart'; +import 'swift_generator.dart' show SwiftProxyApiOptions; typedef _ListEquals = bool Function(List, List); @@ -142,6 +143,7 @@ class AstProxyApi extends Api { required this.fields, this.superClass, this.interfaces = const {}, + this.swiftOptions, this.kotlinOptions, }); @@ -157,6 +159,10 @@ class AstProxyApi extends Api { /// Name of the classes this class considers to be implemented. Set interfaces; + /// Options that control how Swift code will be generated for a specific + /// ProxyApi. + final SwiftProxyApiOptions? swiftOptions; + /// Options that control how Kotlin code will be generated for a specific /// ProxyApi. final KotlinProxyApiOptions? kotlinOptions; diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index ef623942f4f..37bce3f6402 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -14,7 +14,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '22.4.2'; +const String pigeonVersion = '22.5.0'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/pigeon.dart b/packages/pigeon/lib/pigeon.dart index e9aa0992226..bfa23ad5801 100644 --- a/packages/pigeon/lib/pigeon.dart +++ b/packages/pigeon/lib/pigeon.dart @@ -11,4 +11,4 @@ export 'java_generator.dart' show JavaOptions; export 'kotlin_generator.dart' show KotlinOptions, KotlinProxyApiOptions; export 'objc_generator.dart' show ObjcOptions; export 'pigeon_lib.dart'; -export 'swift_generator.dart' show SwiftOptions; +export 'swift_generator.dart' show SwiftOptions, SwiftProxyApiOptions; diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 0d42a849fab..8b8a0506877 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -23,6 +23,7 @@ import 'package:analyzer/error/error.dart' show AnalysisError; import 'package:args/args.dart'; import 'package:collection/collection.dart' as collection; import 'package:path/path.dart' as path; +import 'package:pub_semver/pub_semver.dart'; import 'ast.dart'; import 'ast_generator.dart'; @@ -139,7 +140,7 @@ class FlutterApi { /// methods. class ProxyApi { /// Parametric constructor for [ProxyApi]. - const ProxyApi({this.superClass, this.kotlinOptions}); + const ProxyApi({this.superClass, this.kotlinOptions, this.swiftOptions}); /// The proxy api that is a super class to this one. /// @@ -150,6 +151,10 @@ class ProxyApi { /// with inherited method names. final Type? superClass; + /// Options that control how Swift code will be generated for a specific + /// ProxyApi. + final SwiftProxyApiOptions? swiftOptions; + /// Options that control how Kotlin code will be generated for a specific /// ProxyApi. final KotlinProxyApiOptions? kotlinOptions; @@ -1674,6 +1679,40 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } } + SwiftProxyApiOptions? swiftOptions; + final Map? swiftOptionsMap = + annotationMap['swiftOptions'] as Map?; + if (swiftOptionsMap != null) { + swiftOptions = SwiftProxyApiOptions( + name: swiftOptionsMap['name'] as String?, + import: swiftOptionsMap['import'] as String?, + minIosApi: swiftOptionsMap['minIosApi'] as String?, + minMacosApi: swiftOptionsMap['minMacosApi'] as String?, + supportsIos: swiftOptionsMap['supportsIos'] as bool? ?? true, + supportsMacos: swiftOptionsMap['supportsMacos'] as bool? ?? true, + ); + } + + void tryParseApiRequirement(String? version) { + if (version == null) { + return; + } + try { + Version.parse(version); + } on FormatException catch (error) { + _errors.add( + Error( + message: + 'Could not parse version: ${error.message}. Please use semantic versioning format: "1.2.3".', + lineNumber: _calculateLineNumber(source, node.offset), + ), + ); + } + } + + tryParseApiRequirement(swiftOptions?.minIosApi); + tryParseApiRequirement(swiftOptions?.minMacosApi); + KotlinProxyApiOptions? kotlinOptions; final Map? kotlinOptionsMap = annotationMap['kotlinOptions'] as Map?; @@ -1691,6 +1730,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { fields: [], superClass: superClass, interfaces: interfaces, + swiftOptions: swiftOptions, kotlinOptions: kotlinOptions, documentationComments: _documentationCommentsParser(node.documentationComment?.tokens), diff --git a/packages/pigeon/lib/swift/templates.dart b/packages/pigeon/lib/swift/templates.dart new file mode 100644 index 00000000000..d67e8acf18f --- /dev/null +++ b/packages/pigeon/lib/swift/templates.dart @@ -0,0 +1,256 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '../generator_tools.dart'; +import '../pigeon.dart'; + +/// Name of delegate that handles the callback when an object is deallocated +/// in an `InstanceManager`. +String instanceManagerFinalizerDelegateName(SwiftOptions options) => + '${_instanceManagerFinalizerName(options)}Delegate'; + +/// The name of the registrar containing all the ProxyApi implementations. +String proxyApiRegistrarName(SwiftOptions options) => + '${options.fileSpecificClassNameComponent ?? ''}${proxyApiClassNamePrefix}ProxyApiRegistrar'; + +/// The name of the `ReaderWriter` that handles ProxyApis. +String proxyApiReaderWriterName(SwiftOptions options) => + '${options.fileSpecificClassNameComponent ?? ''}${classNamePrefix}ProxyApiCodecReaderWriter'; + +/// Name of the Swift `InstanceManager`. +String swiftInstanceManagerClassName(SwiftOptions options) => + '${options.fileSpecificClassNameComponent ?? ''}${proxyApiClassNamePrefix}InstanceManager'; + +/// Template for delegate with callback when an object is deallocated. +String instanceManagerFinalizerDelegateTemplate(SwiftOptions options) => ''' +/// Handles the callback when an object is deallocated. +protocol ${instanceManagerFinalizerDelegateName(options)}: AnyObject { + /// Invoked when the strong reference of an object is deallocated in an `InstanceManager`. + func onDeinit(identifier: Int64) +} + +'''; + +/// Template for an object that tracks when an object is deallocated. +String instanceManagerFinalizerTemplate(SwiftOptions options) => ''' +// Attaches to an object to receive a callback when the object is deallocated. +internal final class ${_instanceManagerFinalizerName(options)} { + private static let associatedObjectKey = malloc(1)! + + private let identifier: Int64 + // Reference to the delegate is weak because the callback should be ignored if the + // `InstanceManager` is deallocated. + private weak var delegate: ${instanceManagerFinalizerDelegateName(options)}? + + private init(identifier: Int64, delegate: ${instanceManagerFinalizerDelegateName(options)}) { + self.identifier = identifier + self.delegate = delegate + } + + internal static func attach( + to instance: AnyObject, identifier: Int64, delegate: ${instanceManagerFinalizerDelegateName(options)} + ) { + let finalizer = ${_instanceManagerFinalizerName(options)}(identifier: identifier, delegate: delegate) + objc_setAssociatedObject(instance, associatedObjectKey, finalizer, .OBJC_ASSOCIATION_RETAIN) + } + + static func detach(from instance: AnyObject) { + objc_setAssociatedObject(instance, associatedObjectKey, nil, .OBJC_ASSOCIATION_ASSIGN) + } + + deinit { + delegate?.onDeinit(identifier: identifier) + } +} + +'''; + +/// The Swift `InstanceManager`. +String instanceManagerTemplate(SwiftOptions options) { + return ''' +/// Maintains instances used to communicate with the corresponding objects in Dart. +/// +/// Objects stored in this container are represented by an object in Dart that is also stored in +/// an InstanceManager with the same identifier. +/// +/// When an instance is added with an identifier, either can be used to retrieve the other. +/// +/// Added instances are added as a weak reference and a strong reference. When the strong +/// reference is removed and the weak reference is deallocated,`${instanceManagerFinalizerDelegateName(options)}.onDeinit` +/// is called with the instance's identifier. However, if the strong reference is removed and then the identifier is +/// retrieved with the intention to pass the identifier to Dart (e.g. by calling `identifierWithStrongReference`), +/// the strong reference to the instance is re-added. The strong reference will then need to be removed manually +/// again. +/// +/// Accessing and inserting to an InstanceManager is thread safe. +final class ${swiftInstanceManagerClassName(options)} { + // Identifiers are locked to a specific range to avoid collisions with objects + // created simultaneously from Dart. + // Host uses identifiers >= 2^16 and Dart is expected to use values n where, + // 0 <= n < 2^16. + private static let minHostCreatedIdentifier: Int64 = 65536 + + private let lockQueue = DispatchQueue(label: "${swiftInstanceManagerClassName(options)}") + private let identifiers: NSMapTable = NSMapTable( + keyOptions: [.weakMemory, .objectPointerPersonality], valueOptions: .strongMemory) + private let weakInstances: NSMapTable = NSMapTable( + keyOptions: .strongMemory, valueOptions: [.weakMemory, .objectPointerPersonality]) + private let strongInstances: NSMapTable = NSMapTable( + keyOptions: .strongMemory, valueOptions: [.strongMemory, .objectPointerPersonality]) + private let finalizerDelegate: ${instanceManagerFinalizerDelegateName(options)} + private var nextIdentifier: Int64 = minHostCreatedIdentifier + + public init(finalizerDelegate: ${instanceManagerFinalizerDelegateName(options)}) { + self.finalizerDelegate = finalizerDelegate + } + + /// Adds a new instance that was instantiated from Dart. + /// + /// The same instance can be added multiple times, but each identifier must be unique. This allows + /// two objects that are equivalent (e.g. conforms to `Equatable`) to both be added. + /// + /// - Parameters: + /// - instance: the instance to be stored + /// - identifier: the identifier to be paired with instance. This value must be >= 0 and unique + func addDartCreatedInstance(_ instance: AnyObject, withIdentifier identifier: Int64) { + lockQueue.async { + self.addInstance(instance, withIdentifier: identifier) + } + } + + /// Adds a new instance that was instantiated from the host platform. + /// + /// - Parameters: + /// - instance: the instance to be stored. This must be unique to all other added instances. + /// - Returns: the unique identifier (>= 0) stored with instance + func addHostCreatedInstance(_ instance: AnyObject) -> Int64 { + assert(!containsInstance(instance), "Instance of \\(instance) has already been added.") + var identifier: Int64 = -1 + lockQueue.sync { + identifier = nextIdentifier + nextIdentifier += 1 + self.addInstance(instance, withIdentifier: identifier) + } + return identifier + } + + /// Removes `instanceIdentifier` and its associated strongly referenced instance, if present, from the manager. + /// + /// - Parameters: + /// - instanceIdentifier: the identifier paired to an instance. + /// - Returns: removed instance if the manager contains the given identifier, otherwise `nil` if + /// the manager doesn't contain the value + func removeInstance(withIdentifier instanceIdentifier: Int64) throws -> T? { + var instance: AnyObject? = nil + lockQueue.sync { + instance = strongInstances.object(forKey: NSNumber(value: instanceIdentifier)) + strongInstances.removeObject(forKey: NSNumber(value: instanceIdentifier)) + } + return instance as? T + } + + /// Retrieves the instance associated with identifier. + /// + /// - Parameters: + /// - instanceIdentifier: the identifier associated with an instance + /// - Returns: the instance associated with `instanceIdentifier` if the manager contains the value, otherwise + /// `nil` if the manager doesn't contain the value + func instance(forIdentifier instanceIdentifier: Int64) -> T? { + var instance: AnyObject? = nil + lockQueue.sync { + instance = weakInstances.object(forKey: NSNumber(value: instanceIdentifier)) + } + return instance as? T + } + + private func addInstance(_ instance: AnyObject, withIdentifier identifier: Int64) { + assert(identifier >= 0) + assert( + weakInstances.object(forKey: identifier as NSNumber) == nil, + "Identifier has already been added: \\(identifier)") + identifiers.setObject(NSNumber(value: identifier), forKey: instance) + weakInstances.setObject(instance, forKey: NSNumber(value: identifier)) + strongInstances.setObject(instance, forKey: NSNumber(value: identifier)) + ${_instanceManagerFinalizerName(options)}.attach(to: instance, identifier: identifier, delegate: finalizerDelegate) + } + + /// Retrieves the identifier paired with an instance. + /// + /// If the manager contains a strong reference to `instance`, it will return the identifier + /// associated with `instance`. If the manager contains only a weak reference to `instance`, a new + /// strong reference to `instance` will be added and will need to be removed again with `removeInstance`. + /// + /// If this method returns a nonnull identifier, this method also expects the Dart + /// `${swiftInstanceManagerClassName(options)}` to have, or recreate, a weak reference to the Dart instance the + /// identifier is associated with. + /// + /// - Parameters: + /// - instance: an instance that may be stored in the manager + /// - Returns: the identifier associated with `instance` if the manager contains the value, otherwise + /// `nil` if the manager doesn't contain the value + func identifierWithStrongReference(forInstance instance: AnyObject) -> Int64? { + var identifier: Int64? = nil + lockQueue.sync { + if let existingIdentifier = identifiers.object(forKey: instance)?.int64Value { + strongInstances.setObject(instance, forKey: NSNumber(value: existingIdentifier)) + identifier = existingIdentifier + } + } + return identifier + } + + /// Whether this manager contains the given `instance`. + /// + /// - Parameters: + /// - instance: the instance whose presence in this manager is to be tested + /// - Returns: whether this manager contains the given `instance` + func containsInstance(_ instance: AnyObject) -> Bool { + var containsInstance = false + lockQueue.sync { + containsInstance = identifiers.object(forKey: instance) != nil + } + return containsInstance + } + + /// Removes all of the instances from this manager. + /// + /// The manager will be empty after this call returns. + func removeAllObjects() throws { + lockQueue.sync { + identifiers.removeAllObjects() + weakInstances.removeAllObjects() + strongInstances.removeAllObjects() + nextIdentifier = ${swiftInstanceManagerClassName(options)}.minHostCreatedIdentifier + } + } + + /// The number of instances stored as a strong reference. + /// + /// For debugging and testing purposes. + internal var strongInstanceCount: Int { + var count: Int = 0 + lockQueue.sync { + count = strongInstances.count + } + return count + } + + /// The number of instances stored as a weak reference. + /// + /// For debugging and testing purposes. NSMapTables that store keys or objects as weak + /// reference will be reclaimed non-deterministically. + internal var weakInstanceCount: Int { + var count: Int = 0 + lockQueue.sync { + count = weakInstances.count + } + return count + } +} + +'''; +} + +String _instanceManagerFinalizerName(SwiftOptions options) => + '${options.fileSpecificClassNameComponent ?? ''}${classNamePrefix}Finalizer'; diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 9b4bf79fdd3..bda343b8b6c 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -2,10 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:collection/collection.dart' as collection; +import 'package:graphs/graphs.dart'; +import 'package:pub_semver/pub_semver.dart'; + import 'ast.dart'; import 'functional.dart'; import 'generator.dart'; import 'generator_tools.dart'; +import 'swift/templates.dart'; /// Documentation comment open symbol. const String _docCommentPrefix = '///'; @@ -64,6 +69,54 @@ class SwiftOptions { } } +/// Options that control how Swift code will be generated for a specific +/// ProxyApi. +class SwiftProxyApiOptions { + /// Constructs a [SwiftProxyApiOptions]. + const SwiftProxyApiOptions({ + this.name, + this.import, + this.minIosApi, + this.minMacosApi, + this.supportsIos = true, + this.supportsMacos = true, + }); + + /// The name of the Swift class. + /// + /// By default, generated code will use the same name as the class in the Dart + /// pigeon file. + final String? name; + + /// The name of the module that needs to be imported to access the class. + final String? import; + + /// The API version requirement for iOS. + /// + /// This adds `@available` annotations on top of any constructor, field, or + /// method that references this element. + final String? minIosApi; + + /// The API version requirement for macOS. + /// + /// This adds `@available` annotations on top of any constructor, field, or + /// method that references this element. + final String? minMacosApi; + + /// Whether this ProxyApi class compiles on iOS. + /// + /// This adds `#` annotations on top of any constructor, field, or + /// method that references this element. + /// + /// Defaults to true. + final bool supportsIos; + + /// Whether this ProxyApi class compiles on macOS. + /// + /// Defaults to true. + final bool supportsMacos; +} + /// Class that manages all Swift code generation. class SwiftGenerator extends StructuredGenerator { /// Instantiates a Swift Generator. @@ -92,7 +145,17 @@ class SwiftGenerator extends StructuredGenerator { required String dartPackageName, }) { indent.writeln('import Foundation'); + + final Iterable proxyApiImports = root.apis + .whereType() + .map((AstProxyApi proxyApi) => proxyApi.swiftOptions?.import) + .whereNotNull() + .toSet(); + for (final String import in proxyApiImports) { + indent.writeln('import $import'); + } indent.newln(); + indent.format(''' #if os(iOS) import Flutter @@ -580,7 +643,8 @@ if (wrapped == nil) { indent, generatorOptions: generatorOptions, name: func.name, - channelName: makeChannelName(api, func, dartPackageName), + channelName: + '${makeChannelName(api, func, dartPackageName)}\\(messageChannelSuffix)', parameters: func.parameters, returnType: func.returnType, swiftFunction: func.swiftFunction, @@ -644,7 +708,8 @@ if (wrapped == nil) { _writeHostMethodMessageHandler( indent, name: method.name, - channelName: makeChannelName(api, method, dartPackageName), + channelName: + '${makeChannelName(api, method, dartPackageName)}\\(channelSuffix)', parameters: method.parameters, returnType: method.returnType, isAsynchronous: method.isAsynchronous, @@ -656,6 +721,474 @@ if (wrapped == nil) { }); } + @override + void writeInstanceManager( + SwiftOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + indent.format(instanceManagerFinalizerDelegateTemplate(generatorOptions)); + indent.format(instanceManagerFinalizerTemplate(generatorOptions)); + indent.format(instanceManagerTemplate(generatorOptions)); + } + + @override + void writeInstanceManagerApi( + SwiftOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + final String instanceManagerApiName = + '${swiftInstanceManagerClassName(generatorOptions)}Api'; + + final String removeStrongReferenceName = + makeRemoveStrongReferenceChannelName( + dartPackageName, + ); + + indent.writeScoped('private class $instanceManagerApiName {', '}', () { + addDocumentationComments( + indent, + [' The codec used for serializing messages.'], + _docCommentSpec, + ); + indent.writeln( + 'var codec: FlutterStandardMessageCodec { ${_getCodecName(generatorOptions)}.shared }', + ); + indent.newln(); + + addDocumentationComments( + indent, + [' Handles sending and receiving messages with Dart.'], + _docCommentSpec, + ); + indent.writeln('unowned let binaryMessenger: FlutterBinaryMessenger'); + indent.newln(); + + indent.writeScoped( + 'init(binaryMessenger: FlutterBinaryMessenger) {', + '}', + () { + indent.writeln('self.binaryMessenger = binaryMessenger'); + }, + ); + indent.newln(); + + addDocumentationComments( + indent, + [ + ' Sets up an instance of `$instanceManagerApiName` to handle messages through the `binaryMessenger`.', + ], + _docCommentSpec, + ); + indent.writeScoped( + 'static func setUpMessageHandlers(binaryMessenger: FlutterBinaryMessenger, instanceManager: ${swiftInstanceManagerClassName(generatorOptions)}?) {', + '}', + () { + indent.writeln( + 'let codec = ${_getCodecName(generatorOptions)}.shared', + ); + const String setHandlerCondition = + 'let instanceManager = instanceManager'; + _writeHostMethodMessageHandler( + indent, + name: 'removeStrongReference', + channelName: removeStrongReferenceName, + parameters: [ + Parameter( + name: 'identifier', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + swiftFunction: 'method(withIdentifier:)', + setHandlerCondition: setHandlerCondition, + isAsynchronous: false, + onCreateCall: ( + List safeArgNames, { + required String apiVarName, + }) { + return 'let _: AnyObject? = try instanceManager.removeInstance(${safeArgNames.single})'; + }, + ); + _writeHostMethodMessageHandler( + indent, + name: 'clear', + channelName: makeClearChannelName(dartPackageName), + parameters: [], + returnType: const TypeDeclaration.voidDeclaration(), + setHandlerCondition: setHandlerCondition, + swiftFunction: null, + isAsynchronous: false, + onCreateCall: ( + List safeArgNames, { + required String apiVarName, + }) { + return 'try instanceManager.removeAllObjects()'; + }, + ); + }, + ); + indent.newln(); + + addDocumentationComments( + indent, + [ + ' Sends a message to the Dart `InstanceManager` to remove the strong reference of the instance associated with `identifier`.', + ], + _docCommentSpec, + ); + _writeFlutterMethod( + indent, + generatorOptions: generatorOptions, + name: 'removeStrongReference', + parameters: [ + Parameter( + name: 'identifier', + type: const TypeDeclaration(baseName: 'int', isNullable: false), + ) + ], + returnType: const TypeDeclaration.voidDeclaration(), + channelName: removeStrongReferenceName, + swiftFunction: null, + ); + }); + } + + @override + void writeProxyApiBaseCodec( + SwiftOptions generatorOptions, + Root root, + Indent indent, + ) { + final Iterable allProxyApis = + root.apis.whereType(); + + _writeProxyApiRegistrar( + indent, + generatorOptions: generatorOptions, + allProxyApis: allProxyApis, + ); + + final String filePrefix = + generatorOptions.fileSpecificClassNameComponent ?? ''; + + final String registrarName = proxyApiRegistrarName(generatorOptions); + + indent.writeScoped( + 'private class ${proxyApiReaderWriterName(generatorOptions)}: FlutterStandardReaderWriter {', + '}', + () { + indent.writeln( + 'unowned let pigeonRegistrar: $registrarName', + ); + indent.newln(); + + indent.writeScoped( + 'private class $filePrefix${classNamePrefix}ProxyApiCodecReader: ${_getCodecName(generatorOptions)}Reader {', + '}', + () { + indent.writeln('unowned let pigeonRegistrar: $registrarName'); + indent.newln(); + + indent.writeScoped( + 'init(data: Data, pigeonRegistrar: $registrarName) {', + '}', + () { + indent.writeln('self.pigeonRegistrar = pigeonRegistrar'); + indent.writeln('super.init(data: data)'); + }, + ); + indent.newln(); + + indent.writeScoped( + 'override func readValue(ofType type: UInt8) -> Any? {', + '}', + () { + indent.format( + ''' + switch type { + case $proxyApiCodecInstanceManagerKey: + let identifier = self.readValue() + let instance: AnyObject? = pigeonRegistrar.instanceManager.instance( + forIdentifier: identifier is Int64 ? identifier as! Int64 : Int64(identifier as! Int32)) + return instance + default: + return super.readValue(ofType: type) + }''', + ); + }, + ); + }, + ); + indent.newln(); + + indent.writeScoped( + 'private class $filePrefix${classNamePrefix}ProxyApiCodecWriter: ${_getCodecName(generatorOptions)}Writer {', + '}', + () { + indent.writeln( + 'unowned let pigeonRegistrar: $registrarName', + ); + indent.newln(); + + indent.writeScoped( + 'init(data: NSMutableData, pigeonRegistrar: $registrarName) {', + '}', + () { + indent.writeln('self.pigeonRegistrar = pigeonRegistrar'); + indent.writeln('super.init(data: data)'); + }, + ); + indent.newln(); + + indent.writeScoped( + 'override func writeValue(_ value: Any) {', + '}', + () { + final List nonProxyApiTypes = [ + '[Any]', + 'Bool', + 'Data', + '[AnyHashable: Any]', + 'Double', + 'FlutterStandardTypedData', + 'Int64', + 'String', + ...root.enums.map((Enum anEnum) => anEnum.name), + ]; + final String isBuiltinExpression = nonProxyApiTypes + .map((String swiftType) => 'value is $swiftType') + .join(' || '); + // Non ProxyApi types are checked first to prevent the scenario + // where a client wraps the `NSObject` class which all the + // classes above extend. + indent.writeScoped('if $isBuiltinExpression {', '}', () { + indent.writeln('super.writeValue(value)'); + indent.writeln('return'); + }); + indent.newln(); + + // Sort APIs where edges are an API's super class and interfaces. + // + // This sorts the APIs to have child classes be listed before their parent + // classes. This prevents the scenario where a method might return the super + // class of the actual class, so the incorrect Dart class gets created + // because the 'value is ' was checked first in the codec. For + // example: + // + // class Shape {} + // class Circle extends Shape {} + // + // class SomeClass { + // Shape giveMeAShape() => Circle(); + // } + final List sortedApis = topologicalSort( + allProxyApis, + (AstProxyApi api) { + return [ + if (api.superClass?.associatedProxyApi != null) + api.superClass!.associatedProxyApi!, + ...api.interfaces.map( + (TypeDeclaration interface) => + interface.associatedProxyApi!, + ), + ]; + }, + ); + + enumerate( + sortedApis, + (int index, AstProxyApi api) { + final TypeDeclaration apiAsTypeDecl = TypeDeclaration( + baseName: api.name, + isNullable: false, + associatedProxyApi: api, + ); + final String? availability = _tryGetAvailabilityAnnotation( + [apiAsTypeDecl], + ); + final String? unsupportedPlatforms = + _tryGetUnsupportedPlatformsCondition( + [apiAsTypeDecl], + ); + final String className = api.swiftOptions?.name ?? api.name; + indent.format( + ''' + ${unsupportedPlatforms != null ? '#if $unsupportedPlatforms' : ''} + if ${availability != null ? '#$availability, ' : ''}let instance = value as? $className { + pigeonRegistrar.apiDelegate.pigeonApi${api.name}(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte($proxyApiCodecInstanceManagerKey) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference(forInstance: instance as AnyObject)!) + return + } + ${unsupportedPlatforms != null ? '#endif' : ''}''', + ); + }, + ); + indent.newln(); + + indent.format( + ''' + if let instance = value as AnyObject?, pigeonRegistrar.instanceManager.containsInstance(instance) + { + super.writeByte($proxyApiCodecInstanceManagerKey) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference(forInstance: instance)!) + } else { + print("Unsupported value: \\(value) of \\(type(of: value))") + assert(false, "Unsupported value for $filePrefix${classNamePrefix}ProxyApiCodecWriter") + } + ''', + ); + }, + ); + }, + ); + indent.newln(); + + indent.format( + ''' + init(pigeonRegistrar: $registrarName) { + self.pigeonRegistrar = pigeonRegistrar + }''', + ); + indent.newln(); + + indent.format( + ''' + override func reader(with data: Data) -> FlutterStandardReader { + return $filePrefix${classNamePrefix}ProxyApiCodecReader(data: data, pigeonRegistrar: pigeonRegistrar) + }''', + ); + indent.newln(); + + indent.format( + ''' + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return $filePrefix${classNamePrefix}ProxyApiCodecWriter(data: data, pigeonRegistrar: pigeonRegistrar) + }''', + ); + }, + ); + } + + @override + void writeProxyApi( + SwiftOptions generatorOptions, + Root root, + Indent indent, + AstProxyApi api, { + required String dartPackageName, + }) { + final TypeDeclaration apiAsTypeDeclaration = TypeDeclaration( + baseName: api.name, + isNullable: false, + associatedProxyApi: api, + ); + + final String swiftApiDelegateName = + '${hostProxyApiPrefix}Delegate${api.name}'; + final String type = + api.hasMethodsRequiringImplementation() ? 'protocol' : 'open class'; + indent.writeScoped('$type $swiftApiDelegateName {', '}', () { + _writeProxyApiConstructorDelegateMethods( + indent, + api, + apiAsTypeDeclaration: apiAsTypeDeclaration, + ); + _writeProxyApiAttachedFieldDelegateMethods( + indent, + api, + apiAsTypeDeclaration: apiAsTypeDeclaration, + ); + if (api.hasCallbackConstructor()) { + _writeProxyApiUnattachedFieldDelegateMethods( + indent, + api, + apiAsTypeDeclaration: apiAsTypeDeclaration, + ); + } + _writeProxyApiHostMethodDelegateMethods( + indent, + api, + apiAsTypeDeclaration: apiAsTypeDeclaration, + ); + }); + indent.newln(); + + final String swiftApiProtocolName = + '${hostProxyApiPrefix}Protocol${api.name}'; + indent.writeScoped('protocol $swiftApiProtocolName {', '}', () { + _writeProxyApiFlutterMethods( + indent, + api, + generatorOptions: generatorOptions, + apiAsTypeDeclaration: apiAsTypeDeclaration, + dartPackageName: dartPackageName, + writeBody: false, + ); + }); + indent.newln(); + + final String swiftApiName = '$hostProxyApiPrefix${api.name}'; + indent.writeScoped( + 'final class $swiftApiName: $swiftApiProtocolName {', '}', () { + indent.writeln( + 'unowned let pigeonRegistrar: ${proxyApiRegistrarName(generatorOptions)}', + ); + indent.writeln('let pigeonDelegate: $swiftApiDelegateName'); + + _writeProxyApiInheritedApiMethods(indent, api); + + indent.writeScoped( + 'init(pigeonRegistrar: ${proxyApiRegistrarName(generatorOptions)}, delegate: $swiftApiDelegateName) {', + '}', + () { + indent.writeln('self.pigeonRegistrar = pigeonRegistrar'); + indent.writeln('self.pigeonDelegate = delegate'); + }, + ); + + if (api.hasAnyHostMessageCalls()) { + _writeProxyApiMessageHandlerMethod( + indent, + api, + generatorOptions: generatorOptions, + apiAsTypeDeclaration: apiAsTypeDeclaration, + swiftApiName: swiftApiName, + dartPackageName: dartPackageName, + ); + indent.newln(); + } + + _writeProxyApiNewInstanceMethod( + indent, + api, + generatorOptions: generatorOptions, + apiAsTypeDeclaration: apiAsTypeDeclaration, + newInstanceMethodName: '${classMemberNamePrefix}newInstance', + dartPackageName: dartPackageName, + ); + + _writeProxyApiFlutterMethods( + indent, + api, + generatorOptions: generatorOptions, + apiAsTypeDeclaration: apiAsTypeDeclaration, + dartPackageName: dartPackageName, + ); + }); + } + String _castForceUnwrap(String value, TypeDeclaration type) { assert(!type.isVoid); if (type.baseName == 'Object') { @@ -768,14 +1301,15 @@ private func nilOrValue(_ value: Any?) -> T? { final bool hasFlutterApi = root.apis .whereType() .any((Api api) => api.methods.isNotEmpty); + final bool hasProxyApi = root.apis.any((Api api) => api is AstProxyApi); _writePigeonError(generatorOptions, indent); - if (hasHostApi) { + if (hasHostApi || hasProxyApi) { _writeWrapResult(indent); _writeWrapError(generatorOptions, indent); } - if (hasFlutterApi) { + if (hasFlutterApi || hasProxyApi) { _writeCreateConnectionError(generatorOptions, indent); } @@ -802,66 +1336,81 @@ private func nilOrValue(_ value: Any?) -> T? { getParameterName: _getSafeArgumentName, ); + indent.writeScoped('$methodSignature {', '}', () { + _writeFlutterMethodMessageCall( + indent, + generatorOptions: generatorOptions, + parameters: parameters, + returnType: returnType, + channelName: channelName, + ); + }); + } + + void _writeFlutterMethodMessageCall( + Indent indent, { + required SwiftOptions generatorOptions, + required List parameters, + required TypeDeclaration returnType, + required String channelName, + }) { /// Returns an argument name that can be used in a context where it is possible to collide. String getEnumSafeArgumentExpression(int count, NamedType argument) { return '${_getArgumentName(count, argument)}Arg'; } - indent.writeScoped('$methodSignature {', '}', () { - final Iterable enumSafeArgNames = parameters.asMap().entries.map( - (MapEntry e) => - getEnumSafeArgumentExpression(e.key, e.value)); - final String sendArgument = parameters.isEmpty - ? 'nil' - : '[${enumSafeArgNames.join(', ')}] as [Any?]'; - const String channel = 'channel'; - indent.writeln( - 'let channelName: String = "$channelName\\(messageChannelSuffix)"'); - indent.writeln( - 'let $channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)'); - indent.write('$channel.sendMessage($sendArgument) '); + final Iterable enumSafeArgNames = parameters.asMap().entries.map( + (MapEntry e) => + getEnumSafeArgumentExpression(e.key, e.value)); + final String sendArgument = parameters.isEmpty + ? 'nil' + : '[${enumSafeArgNames.join(', ')}] as [Any?]'; + const String channel = 'channel'; + indent.writeln('let channelName: String = "$channelName"'); + indent.writeln( + 'let $channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)'); + indent.write('$channel.sendMessage($sendArgument) '); - indent.addScoped('{ response in', '}', () { - indent.writeScoped( - 'guard let listResponse = response as? [Any?] else {', '}', () { - indent.writeln( - 'completion(.failure(createConnectionError(withChannelName: channelName)))'); - indent.writeln('return'); - }); - indent.writeScoped('if listResponse.count > 1 {', '} ', () { - indent.writeln('let code: String = listResponse[0] as! String'); - indent.writeln('let message: String? = nilOrValue(listResponse[1])'); - indent.writeln('let details: String? = nilOrValue(listResponse[2])'); + indent.addScoped('{ response in', '}', () { + indent.writeScoped( + 'guard let listResponse = response as? [Any?] else {', '}', () { + indent.writeln( + 'completion(.failure(createConnectionError(withChannelName: channelName)))'); + indent.writeln('return'); + }); + indent.writeScoped('if listResponse.count > 1 {', '} ', () { + indent.writeln('let code: String = listResponse[0] as! String'); + indent.writeln('let message: String? = nilOrValue(listResponse[1])'); + indent.writeln('let details: String? = nilOrValue(listResponse[2])'); + indent.writeln( + 'completion(.failure(${_getErrorClassName(generatorOptions)}(code: code, message: message, details: details)))'); + }, addTrailingNewline: false); + if (!returnType.isNullable && !returnType.isVoid) { + indent.addScoped('else if listResponse[0] == nil {', '} ', () { indent.writeln( - 'completion(.failure(${_getErrorClassName(generatorOptions)}(code: code, message: message, details: details)))'); + 'completion(.failure(${_getErrorClassName(generatorOptions)}(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))'); }, addTrailingNewline: false); - if (!returnType.isNullable && !returnType.isVoid) { - indent.addScoped('else if listResponse[0] == nil {', '} ', () { - indent.writeln( - 'completion(.failure(${_getErrorClassName(generatorOptions)}(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))'); - }, addTrailingNewline: false); + } + indent.addScoped('else {', '}', () { + if (returnType.isVoid) { + indent.writeln('completion(.success(Void()))'); + } else { + final String fieldType = _swiftTypeForDartType(returnType); + _writeGenericCasting( + indent: indent, + value: 'listResponse[0]', + variableName: 'result', + fieldType: fieldType, + type: returnType, + ); + // There is a swift bug with unwrapping maps of nullable Enums; + final String enumMapForceUnwrap = returnType.baseName == 'Map' && + returnType.typeArguments + .any((TypeDeclaration type) => type.isEnum) + ? '!' + : ''; + indent.writeln('completion(.success(result$enumMapForceUnwrap))'); } - indent.addScoped('else {', '}', () { - if (returnType.isVoid) { - indent.writeln('completion(.success(Void()))'); - } else { - final String fieldType = _swiftTypeForDartType(returnType); - _writeGenericCasting( - indent: indent, - value: 'listResponse[0]', - variableName: 'result', - fieldType: fieldType, - type: returnType, - ); - // There is a swift bug with unwrapping maps of nullable Enums; - final String enumMapForceUnwrap = returnType.baseName == 'Map' && - returnType.typeArguments - .any((TypeDeclaration type) => type.isEnum) - ? '!' - : ''; - indent.writeln('completion(.success(result$enumMapForceUnwrap))'); - } - }); }); }); } @@ -874,7 +1423,10 @@ private func nilOrValue(_ value: Any?) -> T? { required TypeDeclaration returnType, required bool isAsynchronous, required String? swiftFunction, + String setHandlerCondition = 'let api = api', List documentationComments = const [], + String Function(List safeArgNames, {required String apiVarName})? + onCreateCall, }) { final _SwiftFunctionComponents components = _SwiftFunctionComponents( name: name, @@ -886,8 +1438,8 @@ private func nilOrValue(_ value: Any?) -> T? { final String varChannelName = '${name}Channel'; addDocumentationComments(indent, documentationComments, _docCommentSpec); indent.writeln( - 'let $varChannelName = FlutterBasicMessageChannel(name: "$channelName\\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)'); - indent.write('if let api = api '); + 'let $varChannelName = FlutterBasicMessageChannel(name: "$channelName", binaryMessenger: binaryMessenger, codec: codec)'); + indent.write('if $setHandlerCondition '); indent.addScoped('{', '}', () { indent.write('$varChannelName.setMessageHandler '); final String messageVarName = parameters.isNotEmpty ? 'message' : '_'; @@ -923,13 +1475,17 @@ private func nilOrValue(_ value: Any?) -> T? { }); } final String tryStatement = isAsynchronous ? '' : 'try '; - // Empty parens are not required when calling a method whose only - // argument is a trailing closure. - final String argumentString = methodArgument.isEmpty && isAsynchronous - ? '' - : '(${methodArgument.join(', ')})'; - final String call = - '${tryStatement}api.${components.name}$argumentString'; + late final String call; + if (onCreateCall == null) { + // Empty parens are not required when calling a method whose only + // argument is a trailing closure. + final String argumentString = methodArgument.isEmpty && isAsynchronous + ? '' + : '(${methodArgument.join(', ')})'; + call = '${tryStatement}api.${components.name}$argumentString'; + } else { + call = onCreateCall(methodArgument, apiVarName: 'api'); + } if (isAsynchronous) { final String resultName = returnType.isVoid ? 'nil' : 'res'; final String successVariableInit = @@ -971,6 +1527,837 @@ private func nilOrValue(_ value: Any?) -> T? { }); } + void _writeProxyApiRegistrar( + Indent indent, { + required SwiftOptions generatorOptions, + required Iterable allProxyApis, + }) { + final String delegateName = + '${generatorOptions.fileSpecificClassNameComponent ?? ''}${proxyApiClassNamePrefix}ProxyApiDelegate'; + indent.writeScoped('protocol $delegateName {', '}', () { + for (final AstProxyApi api in allProxyApis) { + final String hostApiName = '$hostProxyApiPrefix${api.name}'; + addDocumentationComments( + indent, + [ + ' An implementation of [$hostApiName] used to add a new Dart instance of', + ' `${api.name}` to the Dart `InstanceManager` and make calls to Dart.' + ], + _docCommentSpec, + ); + indent.writeln( + 'func pigeonApi${api.name}(_ registrar: ${proxyApiRegistrarName(generatorOptions)}) -> $hostApiName', + ); + } + }); + indent.newln(); + + // Some APIs don't have any methods to implement, + // so this creates an extension of the PigeonProxyApiDelegate that adds + // default implementations for these APIs. + final Iterable apisThatCanHaveADefaultImpl = allProxyApis + .where((AstProxyApi api) => !api.hasMethodsRequiringImplementation()); + if (apisThatCanHaveADefaultImpl.isNotEmpty) { + indent.writeScoped('extension $delegateName {', '}', () { + for (final AstProxyApi api in apisThatCanHaveADefaultImpl) { + final String hostApiName = '$hostProxyApiPrefix${api.name}'; + final String swiftApiDelegateName = + '${hostProxyApiPrefix}Delegate${api.name}'; + indent.format( + ''' + func pigeonApi${api.name}(_ registrar: ${proxyApiRegistrarName(generatorOptions)}) -> $hostApiName { + return $hostApiName(pigeonRegistrar: registrar, delegate: $swiftApiDelegateName()) + }''', + ); + } + }); + indent.newln(); + } + + final String instanceManagerApiName = + '${swiftInstanceManagerClassName(generatorOptions)}Api'; + + indent.writeScoped( + 'open class ${proxyApiRegistrarName(generatorOptions)} {', '}', () { + indent.writeln('let binaryMessenger: FlutterBinaryMessenger'); + indent.writeln('let apiDelegate: $delegateName'); + indent.writeln( + 'let instanceManager: ${swiftInstanceManagerClassName(generatorOptions)}'); + + addDocumentationComments( + indent, + [' Whether APIs should ignore calling to Dart.'], + _docCommentSpec, + ); + indent.writeln('public var ignoreCallsToDart = false'); + + indent.writeln('private var _codec: FlutterStandardMessageCodec?'); + indent.format( + ''' + var codec: FlutterStandardMessageCodec { + if _codec == nil { + _codec = FlutterStandardMessageCodec( + readerWriter: ${proxyApiReaderWriterName(generatorOptions)}(pigeonRegistrar: self)) + } + return _codec! + }''', + ); + indent.newln(); + + indent.format( + ''' + private class InstanceManagerApiFinalizerDelegate: ${instanceManagerFinalizerDelegateName(generatorOptions)} { + let api: $instanceManagerApiName + + init(_ api: $instanceManagerApiName) { + self.api = api + } + + public func onDeinit(identifier: Int64) { + api.removeStrongReference(identifier: identifier) { + _ in + } + } + }''', + ); + indent.newln(); + + indent.format( + ''' + init(binaryMessenger: FlutterBinaryMessenger, apiDelegate: $delegateName) { + self.binaryMessenger = binaryMessenger + self.apiDelegate = apiDelegate + self.instanceManager = ${swiftInstanceManagerClassName(generatorOptions)}( + finalizerDelegate: InstanceManagerApiFinalizerDelegate( + $instanceManagerApiName(binaryMessenger: binaryMessenger))) + }''', + ); + indent.newln(); + + indent.writeScoped('func setUp() {', '}', () { + indent.writeln( + '$instanceManagerApiName.setUpMessageHandlers(binaryMessenger: binaryMessenger, instanceManager: instanceManager)', + ); + for (final AstProxyApi api in allProxyApis) { + if (api.hasAnyHostMessageCalls()) { + indent.writeln( + '$hostProxyApiPrefix${api.name}.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApi${api.name}(self))', + ); + } + } + }); + + indent.writeScoped('func tearDown() {', '}', () { + indent.writeln( + '$instanceManagerApiName.setUpMessageHandlers(binaryMessenger: binaryMessenger, instanceManager: nil)', + ); + for (final AstProxyApi api in allProxyApis) { + if (api.hasAnyHostMessageCalls()) { + indent.writeln( + '$hostProxyApiPrefix${api.name}.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil)', + ); + } + } + }); + }); + } + + // Writes the delegate method that instantiates a new instance of the Kotlin + // class. + void _writeProxyApiConstructorDelegateMethods( + Indent indent, + AstProxyApi api, { + required TypeDeclaration apiAsTypeDeclaration, + }) { + for (final Constructor constructor in api.constructors) { + final List allReferencedTypes = [ + apiAsTypeDeclaration, + ...api.unattachedFields.map((ApiField field) => field.type), + ...constructor.parameters.map((Parameter parameter) => parameter.type), + ]; + + final String? unsupportedPlatforms = + _tryGetUnsupportedPlatformsCondition(allReferencedTypes); + if (unsupportedPlatforms != null) { + indent.writeln('#if $unsupportedPlatforms'); + } + + addDocumentationComments( + indent, + constructor.documentationComments, + _docCommentSpec, + ); + + final String? availableAnnotation = + _tryGetAvailabilityAnnotation(allReferencedTypes); + if (availableAnnotation != null) { + indent.writeln('@$availableAnnotation'); + } + + final String methodSignature = _getMethodSignature( + name: constructor.name.isNotEmpty + ? constructor.name + : 'pigeonDefaultConstructor', + parameters: [ + Parameter( + name: 'pigeonApi', + type: TypeDeclaration( + baseName: '$hostProxyApiPrefix${api.name}', + isNullable: false, + ), + ), + ...api.unattachedFields.map((ApiField field) { + return Parameter(name: field.name, type: field.type); + }), + ...constructor.parameters + ], + returnType: apiAsTypeDeclaration, + errorTypeName: '', + ); + indent.writeln(methodSignature); + + if (unsupportedPlatforms != null) { + indent.writeln('#endif'); + } + } + } + + // Writes the delegate method that handles instantiating an attached field. + void _writeProxyApiAttachedFieldDelegateMethods( + Indent indent, + AstProxyApi api, { + required TypeDeclaration apiAsTypeDeclaration, + }) { + for (final ApiField field in api.attachedFields) { + final List allReferencedTypes = [ + apiAsTypeDeclaration, + field.type, + ]; + + final String? unsupportedPlatforms = + _tryGetUnsupportedPlatformsCondition(allReferencedTypes); + if (unsupportedPlatforms != null) { + indent.writeln('#if $unsupportedPlatforms'); + } + + addDocumentationComments( + indent, + field.documentationComments, + _docCommentSpec, + ); + + final String? availableAnnotation = + _tryGetAvailabilityAnnotation(allReferencedTypes); + if (availableAnnotation != null) { + indent.writeln('@$availableAnnotation'); + } + + final String methodSignature = _getMethodSignature( + name: field.name, + parameters: [ + Parameter( + name: 'pigeonApi', + type: TypeDeclaration( + baseName: '$hostProxyApiPrefix${api.name}', + isNullable: false, + ), + ), + if (!field.isStatic) + Parameter( + name: 'pigeonInstance', + type: apiAsTypeDeclaration, + ), + ], + returnType: field.type, + errorTypeName: '', + ); + indent.writeln(methodSignature); + + if (unsupportedPlatforms != null) { + indent.writeln('#endif'); + } + } + } + + // Writes the delegate method that handles accessing an unattached field. + void _writeProxyApiUnattachedFieldDelegateMethods( + Indent indent, + AstProxyApi api, { + required TypeDeclaration apiAsTypeDeclaration, + }) { + for (final ApiField field in api.unattachedFields) { + final List allReferencedTypes = [ + apiAsTypeDeclaration, + field.type, + ]; + + final String? unsupportedPlatforms = + _tryGetUnsupportedPlatformsCondition(allReferencedTypes); + if (unsupportedPlatforms != null) { + indent.writeln('#if $unsupportedPlatforms'); + } + + addDocumentationComments( + indent, + field.documentationComments, + _docCommentSpec, + ); + + final String? availableAnnotation = + _tryGetAvailabilityAnnotation(allReferencedTypes); + if (availableAnnotation != null) { + indent.writeln('@$availableAnnotation'); + } + + final String methodSignature = _getMethodSignature( + name: field.name, + parameters: [ + Parameter( + name: 'pigeonApi', + type: TypeDeclaration( + baseName: '$hostProxyApiPrefix${api.name}', + isNullable: false, + ), + ), + Parameter( + name: 'pigeonInstance', + type: apiAsTypeDeclaration, + ), + ], + returnType: field.type, + errorTypeName: '', + ); + indent.writeln(methodSignature); + + if (unsupportedPlatforms != null) { + indent.writeln('#endif'); + } + } + } + + // Writes the delegate method that handles making a call from for a host + // method. + void _writeProxyApiHostMethodDelegateMethods( + Indent indent, + AstProxyApi api, { + required TypeDeclaration apiAsTypeDeclaration, + }) { + for (final Method method in api.hostMethods) { + final List allReferencedTypes = [ + if (!method.isStatic) apiAsTypeDeclaration, + method.returnType, + ...method.parameters.map((Parameter p) => p.type), + ]; + + final String? unsupportedPlatforms = + _tryGetUnsupportedPlatformsCondition(allReferencedTypes); + if (unsupportedPlatforms != null) { + indent.writeln('#if $unsupportedPlatforms'); + } + + addDocumentationComments( + indent, + method.documentationComments, + _docCommentSpec, + ); + + final String? availableAnnotation = + _tryGetAvailabilityAnnotation(allReferencedTypes); + if (availableAnnotation != null) { + indent.writeln('@$availableAnnotation'); + } + + final String methodSignature = _getMethodSignature( + name: method.name, + parameters: [ + Parameter( + name: 'pigeonApi', + type: TypeDeclaration( + baseName: '$hostProxyApiPrefix${api.name}', + isNullable: false, + ), + ), + if (!method.isStatic) + Parameter( + name: 'pigeonInstance', + type: apiAsTypeDeclaration, + ), + ...method.parameters, + ], + returnType: method.returnType, + isAsynchronous: method.isAsynchronous, + errorTypeName: 'Error', + ); + indent.writeln(methodSignature); + + if (unsupportedPlatforms != null) { + indent.writeln('#endif'); + } + } + } + + // Writes the getters for accessing the implementation of other ProxyApis. + // + // These are used for inherited Flutter methods. + void _writeProxyApiInheritedApiMethods(Indent indent, AstProxyApi api) { + final Set inheritedApiNames = { + if (api.superClass != null) api.superClass!.baseName, + ...api.interfaces.map((TypeDeclaration type) => type.baseName), + }; + for (final String name in inheritedApiNames) { + addDocumentationComments( + indent, + [ + 'An implementation of [$name] used to access callback methods', + ], + _docCommentSpec, + ); + indent.writeScoped( + 'var pigeonApi$name: $hostProxyApiPrefix$name {', + '}', + () { + indent.writeln( + 'return pigeonRegistrar.apiDelegate.pigeonApi$name(pigeonRegistrar)', + ); + }, + ); + indent.newln(); + } + } + + // Writes the `..setUpMessageHandler` method to ensure incoming messages are + // handled by the correct delegate host methods. + void _writeProxyApiMessageHandlerMethod( + Indent indent, + AstProxyApi api, { + required SwiftOptions generatorOptions, + required TypeDeclaration apiAsTypeDeclaration, + required String swiftApiName, + required String dartPackageName, + }) { + indent.writeScoped( + 'static func setUpMessageHandlers(binaryMessenger: FlutterBinaryMessenger, api: $swiftApiName?) {', + '}', + () { + indent.format( + ''' + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: ${proxyApiReaderWriterName(generatorOptions)}(pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance()''', + ); + void writeWithApiCheckIfNecessary( + List types, { + required String methodName, + required String channelName, + required void Function() onWrite, + }) { + final String? unsupportedPlatforms = + _tryGetUnsupportedPlatformsCondition(types); + if (unsupportedPlatforms != null) { + indent.writeln('#if $unsupportedPlatforms'); + } + + final String? availableAnnotation = + _tryGetAvailabilityAnnotation(types); + if (availableAnnotation != null) { + indent.writeScoped( + 'if #$availableAnnotation {', + '}', + onWrite, + addTrailingNewline: false, + ); + indent.writeScoped(' else {', '}', () { + final String varChannelName = '${methodName}Channel'; + indent.format( + ''' + let $varChannelName = FlutterBasicMessageChannel( + name: "$channelName", + binaryMessenger: binaryMessenger, codec: codec) + if api != nil { + $varChannelName.setMessageHandler { message, reply in + reply(wrapError(FlutterError(code: "PigeonUnsupportedOperationError", + message: "Call to $methodName requires @$availableAnnotation.", + details: nil + ))) + } + } else { + $varChannelName.setMessageHandler(nil) + }''', + ); + }); + } else { + onWrite(); + } + + if (unsupportedPlatforms != null) { + indent.writeln('#endif'); + } + } + + for (final Constructor constructor in api.constructors) { + final String name = constructor.name.isNotEmpty + ? constructor.name + : 'pigeonDefaultConstructor'; + final String channelName = makeChannelNameWithStrings( + apiName: api.name, + methodName: '${classMemberNamePrefix}defaultConstructor', + dartPackageName: dartPackageName, + ); + writeWithApiCheckIfNecessary( + [ + apiAsTypeDeclaration, + ...api.unattachedFields.map((ApiField f) => f.type), + ...constructor.parameters.map((Parameter p) => p.type), + ], + methodName: name, + channelName: channelName, + onWrite: () { + _writeHostMethodMessageHandler( + indent, + name: name, + channelName: channelName, + returnType: const TypeDeclaration.voidDeclaration(), + swiftFunction: null, + isAsynchronous: false, + onCreateCall: ( + List methodParameters, { + required String apiVarName, + }) { + final List parameters = [ + 'pigeonApi: $apiVarName', + // Skip the identifier used by the InstanceManager. + ...methodParameters.skip(1), + ]; + return '$apiVarName.pigeonRegistrar.instanceManager.addDartCreatedInstance(\n' + 'try $apiVarName.pigeonDelegate.$name(${parameters.join(', ')}),\n' + 'withIdentifier: pigeonIdentifierArg)'; + }, + parameters: [ + Parameter( + name: 'pigeonIdentifier', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ...api.unattachedFields.map((ApiField field) { + return Parameter( + name: field.name, + type: field.type, + ); + }), + ...constructor.parameters, + ], + ); + }, + ); + } + + for (final ApiField field in api.attachedFields) { + final String channelName = makeChannelNameWithStrings( + apiName: api.name, + methodName: field.name, + dartPackageName: dartPackageName, + ); + writeWithApiCheckIfNecessary( + [apiAsTypeDeclaration, field.type], + methodName: field.name, + channelName: channelName, + onWrite: () { + _writeHostMethodMessageHandler( + indent, + name: field.name, + channelName: channelName, + swiftFunction: null, + isAsynchronous: false, + returnType: const TypeDeclaration.voidDeclaration(), + onCreateCall: ( + List methodParameters, { + required String apiVarName, + }) { + final String instanceArg = field.isStatic + ? '' + : ', pigeonInstance: pigeonInstanceArg'; + return '$apiVarName.pigeonRegistrar.instanceManager.addDartCreatedInstance(' + 'try $apiVarName.pigeonDelegate.${field.name}(pigeonApi: api$instanceArg), ' + 'withIdentifier: pigeonIdentifierArg)'; + }, + parameters: [ + if (!field.isStatic) + Parameter( + name: 'pigeonInstance', + type: apiAsTypeDeclaration, + ), + Parameter( + name: 'pigeonIdentifier', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ], + ); + }, + ); + } + + for (final Method method in api.hostMethods) { + final String channelName = + makeChannelName(api, method, dartPackageName); + writeWithApiCheckIfNecessary( + [ + apiAsTypeDeclaration, + method.returnType, + ...method.parameters.map((Parameter parameter) => parameter.type), + ], + methodName: method.name, + channelName: channelName, + onWrite: () { + _writeHostMethodMessageHandler( + indent, + name: method.name, + channelName: makeChannelName(api, method, dartPackageName), + returnType: method.returnType, + isAsynchronous: method.isAsynchronous, + swiftFunction: null, + onCreateCall: ( + List methodParameters, { + required String apiVarName, + }) { + final String tryStatement = + method.isAsynchronous ? '' : 'try '; + final List parameters = [ + 'pigeonApi: $apiVarName', + // Skip the identifier used by the InstanceManager. + ...methodParameters, + ]; + + return '$tryStatement$apiVarName.pigeonDelegate.${method.name}(${parameters.join(', ')})'; + }, + parameters: [ + if (!method.isStatic) + Parameter( + name: 'pigeonInstance', + type: apiAsTypeDeclaration, + ), + ...method.parameters, + ], + ); + }, + ); + } + }, + ); + } + + // Writes the method that calls to Dart to instantiate a new Dart instance. + void _writeProxyApiNewInstanceMethod( + Indent indent, + AstProxyApi api, { + required SwiftOptions generatorOptions, + required TypeDeclaration apiAsTypeDeclaration, + required String newInstanceMethodName, + required String dartPackageName, + }) { + final List allReferencedTypes = [ + apiAsTypeDeclaration, + ...api.unattachedFields.map((ApiField field) => field.type), + ]; + + final String? unsupportedPlatforms = + _tryGetUnsupportedPlatformsCondition(allReferencedTypes); + if (unsupportedPlatforms != null) { + indent.writeln('#if $unsupportedPlatforms'); + } + + addDocumentationComments( + indent, + [ + 'Creates a Dart instance of ${api.name} and attaches it to [pigeonInstance].' + ], + _docCommentSpec, + ); + + final String? availableAnnotation = _tryGetAvailabilityAnnotation( + allReferencedTypes, + ); + if (availableAnnotation != null) { + indent.writeln('@$availableAnnotation'); + } + + final String methodSignature = _getMethodSignature( + name: 'pigeonNewInstance', + parameters: [ + Parameter(name: 'pigeonInstance', type: apiAsTypeDeclaration), + ], + returnType: const TypeDeclaration.voidDeclaration(), + isAsynchronous: true, + errorTypeName: _getErrorClassName(generatorOptions), + ); + indent.writeScoped('$methodSignature {', '}', () { + indent.writeScoped( + 'if pigeonRegistrar.ignoreCallsToDart {', + '}', + () { + indent.format( + ''' + completion( + .failure( + ${_getErrorClassName(generatorOptions)}( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return''', + ); + }, + ); + + indent.writeScoped( + 'if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) {', + '}', + () { + indent.writeln('completion(.success(Void()))'); + indent.writeln('return'); + }, + ); + if (api.hasCallbackConstructor()) { + indent.writeln( + 'let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeonInstance as AnyObject)', + ); + enumerate(api.unattachedFields, (int index, ApiField field) { + final String argName = _getSafeArgumentName(index, field); + indent.writeln( + 'let $argName = try! pigeonDelegate.${field.name}(pigeonApi: self, pigeonInstance: pigeonInstance)', + ); + }); + indent.writeln( + 'let binaryMessenger = pigeonRegistrar.binaryMessenger', + ); + indent.writeln('let codec = pigeonRegistrar.codec'); + _writeFlutterMethodMessageCall( + indent, + generatorOptions: generatorOptions, + parameters: [ + Parameter( + name: 'pigeonIdentifier', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ), + ...api.unattachedFields.map( + (ApiField field) { + return Parameter(name: field.name, type: field.type); + }, + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + channelName: makeChannelNameWithStrings( + apiName: api.name, + methodName: newInstanceMethodName, + dartPackageName: dartPackageName, + ), + ); + } else { + indent.writeln( + 'print("Error: Attempting to create a new Dart instance of ${api.name}, but the class has a nonnull callback method.")', + ); + } + }); + + if (unsupportedPlatforms != null) { + indent.writeln('#endif'); + } + } + + // Writes the Flutter methods that call back to Dart. + void _writeProxyApiFlutterMethods( + Indent indent, + AstProxyApi api, { + required SwiftOptions generatorOptions, + required TypeDeclaration apiAsTypeDeclaration, + required String dartPackageName, + bool writeBody = true, + }) { + for (final Method method in api.flutterMethods) { + final List allReferencedTypes = [ + apiAsTypeDeclaration, + ...method.parameters.map((Parameter parameter) => parameter.type), + method.returnType, + ]; + + final String? unsupportedPlatforms = + _tryGetUnsupportedPlatformsCondition(allReferencedTypes); + if (unsupportedPlatforms != null) { + indent.writeln('#if $unsupportedPlatforms'); + } + + addDocumentationComments( + indent, + method.documentationComments, + _docCommentSpec, + ); + + final String? availableAnnotation = + _tryGetAvailabilityAnnotation(allReferencedTypes); + if (availableAnnotation != null) { + indent.writeln('@$availableAnnotation'); + } + + final String methodSignature = _getMethodSignature( + name: method.name, + parameters: [ + Parameter(name: 'pigeonInstance', type: apiAsTypeDeclaration), + ...method.parameters, + ], + returnType: method.returnType, + isAsynchronous: true, + errorTypeName: _getErrorClassName(generatorOptions), + getParameterName: _getSafeArgumentName, + ); + + indent.write(methodSignature); + if (writeBody) { + indent.writeScoped(' {', '}', () { + indent.writeScoped( + 'if pigeonRegistrar.ignoreCallsToDart {', + '}', + () { + indent.format( + ''' + completion( + .failure( + ${_getErrorClassName(generatorOptions)}( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return''', + ); + }, + ); + indent + .writeln('let binaryMessenger = pigeonRegistrar.binaryMessenger'); + indent.writeln('let codec = pigeonRegistrar.codec'); + + _writeFlutterMethodMessageCall( + indent, + generatorOptions: generatorOptions, + parameters: [ + Parameter(name: 'pigeonInstance', type: apiAsTypeDeclaration), + ...method.parameters, + ], + returnType: method.returnType, + channelName: makeChannelName(api, method, dartPackageName), + ); + }); + } + if (unsupportedPlatforms != null) { + indent.writeln('#endif'); + } + indent.newln(); + } + } + void _writePigeonError(SwiftOptions generatorOptions, Indent indent) { indent.newln(); indent.writeln( @@ -999,6 +2386,99 @@ private func nilOrValue(_ value: Any?) -> T? { } } +typedef _VersionRequirement = ({TypeDeclaration type, Version version}); +({_VersionRequirement? ios, _VersionRequirement? macos}) + _findHighestVersionRequirement( + Iterable types, +) { + final _VersionRequirement? iosApiRequirement = + findHighestApiRequirement( + types, + onGetApiRequirement: (TypeDeclaration type) { + final String? apiRequirement = + type.associatedProxyApi?.swiftOptions?.minIosApi; + if (apiRequirement != null) { + return Version.parse(apiRequirement); + } + + return null; + }, + onCompare: (Version one, Version two) => one.compareTo(two), + ); + + final _VersionRequirement? macosApiRequirement = + findHighestApiRequirement( + types, + onGetApiRequirement: (TypeDeclaration type) { + final String? apiRequirement = + type.associatedProxyApi?.swiftOptions?.minMacosApi; + if (apiRequirement != null) { + return Version.parse(apiRequirement); + } + + return null; + }, + onCompare: (Version one, Version two) => one.compareTo(two), + ); + + return (ios: iosApiRequirement, macos: macosApiRequirement); +} + +/// Finds the highest api requirement for each supported platform and creates +/// the `available(platform version , platform version ..., *)` annotation. +/// +/// Returns `null` if there is not api requirement in [types]. +String? _tryGetAvailabilityAnnotation(Iterable types) { + final ({ + _VersionRequirement? ios, + _VersionRequirement? macos + }) versionRequirement = _findHighestVersionRequirement(types); + + final List apis = [ + if (versionRequirement.ios != null) + 'iOS ${versionRequirement.ios!.version}', + if (versionRequirement.macos != null) + 'macOS ${versionRequirement.macos!.version}', + ]; + + return apis.isNotEmpty ? 'available(${apis.join(', ')}, *)' : null; +} + +/// Creates the string used to indicate a platform is unsupported. +/// +/// Recursively iterates through all types to find any that are not supported +/// by a platform. +/// +/// Returns `null` if every type supports all platforms. +String? _tryGetUnsupportedPlatformsCondition(Iterable types) { + Iterable addAllRecursive(TypeDeclaration type) sync* { + yield type; + if (type.typeArguments.isNotEmpty) { + for (final TypeDeclaration typeArg in type.typeArguments) { + yield* addAllRecursive(typeArg); + } + } + } + + final Iterable allReferencedTypes = + types.expand(addAllRecursive); + + final List unsupportedPlatforms = [ + if (!allReferencedTypes.every((TypeDeclaration type) { + return type.associatedProxyApi?.swiftOptions?.supportsIos ?? true; + })) + '!os(iOS)', + if (!allReferencedTypes.every((TypeDeclaration type) { + return type.associatedProxyApi?.swiftOptions?.supportsMacos ?? true; + })) + '!os(macOS)', + ]; + + return unsupportedPlatforms.isNotEmpty + ? unsupportedPlatforms.join(' || ') + : null; +} + /// Calculates the name of the codec that will be generated for [api]. String _getCodecName(SwiftOptions options) { return '${options.fileSpecificClassNameComponent}PigeonCodec'; @@ -1078,8 +2558,19 @@ String? _swiftTypeForBuiltinDartType( } } +String? _swiftTypeForProxyApiType(TypeDeclaration type) { + if (type.isProxyApi) { + return type.associatedProxyApi!.swiftOptions?.name ?? + type.associatedProxyApi!.name; + } + + return null; +} + String _swiftTypeForDartType(TypeDeclaration type, {bool mapKey = false}) { - return _swiftTypeForBuiltinDartType(type, mapKey: mapKey) ?? type.baseName; + return _swiftTypeForBuiltinDartType(type, mapKey: mapKey) ?? + _swiftTypeForProxyApiType(type) ?? + type.baseName; } String _nullSafeSwiftTypeForDartType( diff --git a/packages/pigeon/pigeons/proxy_api_tests.dart b/packages/pigeon/pigeons/proxy_api_tests.dart index fe6fb73fcfd..0e7bfed75ff 100644 --- a/packages/pigeon/pigeons/proxy_api_tests.dart +++ b/packages/pigeon/pigeons/proxy_api_tests.dart @@ -459,6 +459,7 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass kotlinOptions: KotlinProxyApiOptions( fullClassName: 'com.example.test_plugin.ProxyApiSuperClass', ), + swiftOptions: SwiftProxyApiOptions(name: 'ProxyApiSuperClass'), ) abstract class ProxyApiSuperClass { ProxyApiSuperClass(); @@ -474,6 +475,10 @@ abstract class ProxyApiInterface { @ProxyApi( kotlinOptions: KotlinProxyApiOptions(minAndroidApi: 25), + swiftOptions: SwiftProxyApiOptions( + minIosApi: '15.0.0', + minMacosApi: '10.0.0', + ), ) abstract class ClassWithApiRequirement { ClassWithApiRequirement(); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart index 763e7b222c5..21d76637675 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart @@ -33,6 +33,12 @@ enum TargetGenerator { swift, } +/// Host languages that support generating Proxy APIs. +const Set proxyApiSupportedLanguages = { + TargetGenerator.kotlin, + TargetGenerator.swift, +}; + /// Sets up and runs the integration tests. void runPigeonIntegrationTests(TargetGenerator targetGenerator) { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); @@ -2160,7 +2166,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { }); group('Proxy API Tests', () { - if (targetGenerator != TargetGenerator.kotlin) { + if (!proxyApiSupportedLanguages.contains(targetGenerator)) { return; } diff --git a/packages/pigeon/platform_tests/test_plugin/example/.gitignore b/packages/pigeon/platform_tests/test_plugin/example/.gitignore index 24476c5d1eb..6c319542b34 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/.gitignore +++ b/packages/pigeon/platform_tests/test_plugin/example/.gitignore @@ -5,9 +5,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/project.pbxproj b/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/project.pbxproj index c0ccf06b3f2..ea266506b36 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/Runner.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 6885ADFFF3D912887C317B7C /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 786308B4AA81D1B6AA2FA10F /* Pods_Runner.framework */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 8F85C49D2BBB14F30053FB60 /* InstanceManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F85C49C2BBB14F30053FB60 /* InstanceManagerTests.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; @@ -79,6 +80,7 @@ 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 786308B4AA81D1B6AA2FA10F /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 8F85C49C2BBB14F30053FB60 /* InstanceManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceManagerTests.swift; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -130,6 +132,7 @@ 33A341B7291ECCA100D34E0F /* RunnerTests.swift */, E04641F92A46270400661C9E /* NSNullFieldTests.swift */, 33A341CA291ECDFD00D34E0F /* Utils.swift */, + 8F85C49C2BBB14F30053FB60 /* InstanceManagerTests.swift */, ); path = RunnerTests; sourceTree = ""; @@ -407,6 +410,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 8F85C49D2BBB14F30053FB60 /* InstanceManagerTests.swift in Sources */, 33A341D0291ECDFD00D34E0F /* EchoBinaryMessenger.swift in Sources */, 33A341D3291ECDFD00D34E0F /* PrimitiveTests.swift in Sources */, 33A341D4291ECDFD00D34E0F /* HandlerBinaryMessenger.swift in Sources */, diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/InstanceManagerTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/InstanceManagerTests.swift new file mode 100644 index 00000000000..2031b078dbf --- /dev/null +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/InstanceManagerTests.swift @@ -0,0 +1,143 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Flutter +import XCTest + +@testable import test_plugin + +final class InstanceManagerTests: XCTestCase { + func testAddDartCreatedInstance() { + let finalizerDelegate = EmptyFinalizerDelegate() + let instanceManager = ProxyApiTestsPigeonInstanceManager(finalizerDelegate: finalizerDelegate) + let object = NSObject() + + instanceManager.addDartCreatedInstance(object, withIdentifier: 0) + XCTAssertEqual(instanceManager.instance(forIdentifier: 0), object) + XCTAssertEqual(instanceManager.identifierWithStrongReference(forInstance: object), 0) + } + + func testAddHostCreatedInstance() { + let finalizerDelegate = EmptyFinalizerDelegate() + let instanceManager = ProxyApiTestsPigeonInstanceManager(finalizerDelegate: finalizerDelegate) + let object = NSObject() + _ = instanceManager.addHostCreatedInstance(object) + + let identifier = instanceManager.identifierWithStrongReference(forInstance: object) + XCTAssertEqual(instanceManager.instance(forIdentifier: try XCTUnwrap(identifier)), object) + } + + func testRemoveInstance() { + let finalizerDelegate = EmptyFinalizerDelegate() + let instanceManager = ProxyApiTestsPigeonInstanceManager(finalizerDelegate: finalizerDelegate) + let object = NSObject() + + instanceManager.addDartCreatedInstance(object, withIdentifier: 0) + + XCTAssertEqual(try! instanceManager.removeInstance(withIdentifier: 0), object) + XCTAssertEqual(instanceManager.strongInstanceCount, 0) + } + + func testFinalizerCallsDelegateMethod() { + let finalizerDelegate = TestFinalizerDelegate() + + var object: NSObject? = NSObject() + ProxyApiTestsPigeonInternalFinalizer.attach( + to: object!, identifier: 0, delegate: finalizerDelegate) + + object = nil + XCTAssertEqual(finalizerDelegate.lastHandledIdentifier, 0) + } + + func testRemoveAllObjects() { + let finalizerDelegate = EmptyFinalizerDelegate() + let instanceManager = ProxyApiTestsPigeonInstanceManager(finalizerDelegate: finalizerDelegate) + let object = NSObject() + + instanceManager.addDartCreatedInstance(object, withIdentifier: 0) + try? instanceManager.removeAllObjects() + + XCTAssertEqual(instanceManager.strongInstanceCount, 0) + XCTAssertEqual(instanceManager.weakInstanceCount, 0) + } + + func testCanAddSameObjectWithAddDartCreatedInstance() { + let finalizerDelegate = EmptyFinalizerDelegate() + let instanceManager = ProxyApiTestsPigeonInstanceManager(finalizerDelegate: finalizerDelegate) + let object = NSObject() + + instanceManager.addDartCreatedInstance(object, withIdentifier: 0) + instanceManager.addDartCreatedInstance(object, withIdentifier: 1) + + let instance1: NSObject? = instanceManager.instance(forIdentifier: 0) + let instance2: NSObject? = instanceManager.instance(forIdentifier: 1) + + XCTAssertEqual(instance1, instance2) + } + + func testObjectsAreStoredWithPointerHashcode() { + let finalizerDelegate = EmptyFinalizerDelegate() + let instanceManager = ProxyApiTestsPigeonInstanceManager(finalizerDelegate: finalizerDelegate) + + class EquatableClass: Equatable { + static func == (lhs: EquatableClass, rhs: EquatableClass) -> Bool { + return true + } + } + + let instance1 = EquatableClass() + let instance2 = EquatableClass() + + // Ensure instances are considered equal. + XCTAssertTrue(instance1 == instance2) + + _ = instanceManager.addHostCreatedInstance(instance1) + _ = instanceManager.addHostCreatedInstance(instance2) + + XCTAssertNotEqual( + instanceManager.identifierWithStrongReference(forInstance: instance1), + instanceManager.identifierWithStrongReference(forInstance: instance2)) + } + + func testInstanceManagerCanBeDeallocated() { + let binaryMessenger = MockBinaryMessenger( + codec: FlutterStandardMessageCodec.sharedInstance()) + + var registrar: ProxyApiTestsPigeonProxyApiRegistrar? = ProxyApiTestsPigeonProxyApiRegistrar( + binaryMessenger: binaryMessenger, apiDelegate: ProxyApiDelegate()) + + // Add the scenario where the InstanceManager contains an instance that contains a ProxyApi implementation + class TestClass { + let api: PigeonApiProxyApiTestClass + + init(_ api: PigeonApiProxyApiTestClass) { + self.api = api + } + } + _ = registrar!.instanceManager.addHostCreatedInstance( + TestClass(registrar!.apiDelegate.pigeonApiProxyApiTestClass(registrar!))) + + registrar!.setUp() + registrar!.tearDown() + + let finalizerDelegate = TestFinalizerDelegate() + + ProxyApiTestsPigeonInternalFinalizer.attach( + to: registrar!.instanceManager, identifier: 0, delegate: finalizerDelegate) + registrar = nil + XCTAssertEqual(finalizerDelegate.lastHandledIdentifier, 0) + } +} + +class EmptyFinalizerDelegate: ProxyApiTestsPigeonInternalFinalizerDelegate { + func onDeinit(identifier: Int64) {} +} + +class TestFinalizerDelegate: ProxyApiTestsPigeonInternalFinalizerDelegate { + var lastHandledIdentifier: Int64? + + func onDeinit(identifier: Int64) { + lastHandledIdentifier = identifier + } +} diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/.gitignore b/packages/pigeon/platform_tests/test_plugin/ios/Classes/.gitignore index 65eaa145c8a..18ad850358d 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/.gitignore +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/.gitignore @@ -2,4 +2,8 @@ # changes on generated files. This will need a way to avoid unnecessary churn, # such as a flag to suppress version stamp generation. *.gen.swift -!CoreTests.gen.swift \ No newline at end of file +!CoreTests.gen.swift +# Keeping this makes it easier to review changes to ProxyApi generation. +!ProxyApiTests.gen.swift +# Contains the class declartions for testing ProxyApis. +!ProxyApiTestClass.swift diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTestClass.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTestClass.swift new file mode 100644 index 00000000000..04a14c4e69f --- /dev/null +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTestClass.swift @@ -0,0 +1,14 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Foundation + +class ProxyApiTestClass: ProxyApiSuperClass, ProxyApiInterface {} + +open class ProxyApiSuperClass {} + +protocol ProxyApiInterface {} + +@available(iOS 15, *) +class ClassWithApiRequirement {} diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTests.gen.swift new file mode 100644 index 00000000000..d3a699ca47a --- /dev/null +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTests.gen.swift @@ -0,0 +1,4191 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Autogenerated from Pigeon, do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +/// Error class for passing custom error details to Dart side. +final class ProxyApiTestsError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "ProxyApiTestsError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? ProxyApiTestsError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details, + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)", + ] +} + +private func createConnectionError(withChannelName channelName: String) -> ProxyApiTestsError { + return ProxyApiTestsError( + code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", + details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} +/// Handles the callback when an object is deallocated. +protocol ProxyApiTestsPigeonInternalFinalizerDelegate: AnyObject { + /// Invoked when the strong reference of an object is deallocated in an `InstanceManager`. + func onDeinit(identifier: Int64) +} + +// Attaches to an object to receive a callback when the object is deallocated. +internal final class ProxyApiTestsPigeonInternalFinalizer { + private static let associatedObjectKey = malloc(1)! + + private let identifier: Int64 + // Reference to the delegate is weak because the callback should be ignored if the + // `InstanceManager` is deallocated. + private weak var delegate: ProxyApiTestsPigeonInternalFinalizerDelegate? + + private init(identifier: Int64, delegate: ProxyApiTestsPigeonInternalFinalizerDelegate) { + self.identifier = identifier + self.delegate = delegate + } + + internal static func attach( + to instance: AnyObject, identifier: Int64, + delegate: ProxyApiTestsPigeonInternalFinalizerDelegate + ) { + let finalizer = ProxyApiTestsPigeonInternalFinalizer(identifier: identifier, delegate: delegate) + objc_setAssociatedObject(instance, associatedObjectKey, finalizer, .OBJC_ASSOCIATION_RETAIN) + } + + static func detach(from instance: AnyObject) { + objc_setAssociatedObject(instance, associatedObjectKey, nil, .OBJC_ASSOCIATION_ASSIGN) + } + + deinit { + delegate?.onDeinit(identifier: identifier) + } +} + +/// Maintains instances used to communicate with the corresponding objects in Dart. +/// +/// Objects stored in this container are represented by an object in Dart that is also stored in +/// an InstanceManager with the same identifier. +/// +/// When an instance is added with an identifier, either can be used to retrieve the other. +/// +/// Added instances are added as a weak reference and a strong reference. When the strong +/// reference is removed and the weak reference is deallocated,`ProxyApiTestsPigeonInternalFinalizerDelegate.onDeinit` +/// is called with the instance's identifier. However, if the strong reference is removed and then the identifier is +/// retrieved with the intention to pass the identifier to Dart (e.g. by calling `identifierWithStrongReference`), +/// the strong reference to the instance is re-added. The strong reference will then need to be removed manually +/// again. +/// +/// Accessing and inserting to an InstanceManager is thread safe. +final class ProxyApiTestsPigeonInstanceManager { + // Identifiers are locked to a specific range to avoid collisions with objects + // created simultaneously from Dart. + // Host uses identifiers >= 2^16 and Dart is expected to use values n where, + // 0 <= n < 2^16. + private static let minHostCreatedIdentifier: Int64 = 65536 + + private let lockQueue = DispatchQueue(label: "ProxyApiTestsPigeonInstanceManager") + private let identifiers: NSMapTable = NSMapTable( + keyOptions: [.weakMemory, .objectPointerPersonality], valueOptions: .strongMemory) + private let weakInstances: NSMapTable = NSMapTable( + keyOptions: .strongMemory, valueOptions: [.weakMemory, .objectPointerPersonality]) + private let strongInstances: NSMapTable = NSMapTable( + keyOptions: .strongMemory, valueOptions: [.strongMemory, .objectPointerPersonality]) + private let finalizerDelegate: ProxyApiTestsPigeonInternalFinalizerDelegate + private var nextIdentifier: Int64 = minHostCreatedIdentifier + + public init(finalizerDelegate: ProxyApiTestsPigeonInternalFinalizerDelegate) { + self.finalizerDelegate = finalizerDelegate + } + + /// Adds a new instance that was instantiated from Dart. + /// + /// The same instance can be added multiple times, but each identifier must be unique. This allows + /// two objects that are equivalent (e.g. conforms to `Equatable`) to both be added. + /// + /// - Parameters: + /// - instance: the instance to be stored + /// - identifier: the identifier to be paired with instance. This value must be >= 0 and unique + func addDartCreatedInstance(_ instance: AnyObject, withIdentifier identifier: Int64) { + lockQueue.async { + self.addInstance(instance, withIdentifier: identifier) + } + } + + /// Adds a new instance that was instantiated from the host platform. + /// + /// - Parameters: + /// - instance: the instance to be stored. This must be unique to all other added instances. + /// - Returns: the unique identifier (>= 0) stored with instance + func addHostCreatedInstance(_ instance: AnyObject) -> Int64 { + assert(!containsInstance(instance), "Instance of \(instance) has already been added.") + var identifier: Int64 = -1 + lockQueue.sync { + identifier = nextIdentifier + nextIdentifier += 1 + self.addInstance(instance, withIdentifier: identifier) + } + return identifier + } + + /// Removes `instanceIdentifier` and its associated strongly referenced instance, if present, from the manager. + /// + /// - Parameters: + /// - instanceIdentifier: the identifier paired to an instance. + /// - Returns: removed instance if the manager contains the given identifier, otherwise `nil` if + /// the manager doesn't contain the value + func removeInstance(withIdentifier instanceIdentifier: Int64) throws -> T? { + var instance: AnyObject? = nil + lockQueue.sync { + instance = strongInstances.object(forKey: NSNumber(value: instanceIdentifier)) + strongInstances.removeObject(forKey: NSNumber(value: instanceIdentifier)) + } + return instance as? T + } + + /// Retrieves the instance associated with identifier. + /// + /// - Parameters: + /// - instanceIdentifier: the identifier associated with an instance + /// - Returns: the instance associated with `instanceIdentifier` if the manager contains the value, otherwise + /// `nil` if the manager doesn't contain the value + func instance(forIdentifier instanceIdentifier: Int64) -> T? { + var instance: AnyObject? = nil + lockQueue.sync { + instance = weakInstances.object(forKey: NSNumber(value: instanceIdentifier)) + } + return instance as? T + } + + private func addInstance(_ instance: AnyObject, withIdentifier identifier: Int64) { + assert(identifier >= 0) + assert( + weakInstances.object(forKey: identifier as NSNumber) == nil, + "Identifier has already been added: \(identifier)") + identifiers.setObject(NSNumber(value: identifier), forKey: instance) + weakInstances.setObject(instance, forKey: NSNumber(value: identifier)) + strongInstances.setObject(instance, forKey: NSNumber(value: identifier)) + ProxyApiTestsPigeonInternalFinalizer.attach( + to: instance, identifier: identifier, delegate: finalizerDelegate) + } + + /// Retrieves the identifier paired with an instance. + /// + /// If the manager contains a strong reference to `instance`, it will return the identifier + /// associated with `instance`. If the manager contains only a weak reference to `instance`, a new + /// strong reference to `instance` will be added and will need to be removed again with `removeInstance`. + /// + /// If this method returns a nonnull identifier, this method also expects the Dart + /// `ProxyApiTestsPigeonInstanceManager` to have, or recreate, a weak reference to the Dart instance the + /// identifier is associated with. + /// + /// - Parameters: + /// - instance: an instance that may be stored in the manager + /// - Returns: the identifier associated with `instance` if the manager contains the value, otherwise + /// `nil` if the manager doesn't contain the value + func identifierWithStrongReference(forInstance instance: AnyObject) -> Int64? { + var identifier: Int64? = nil + lockQueue.sync { + if let existingIdentifier = identifiers.object(forKey: instance)?.int64Value { + strongInstances.setObject(instance, forKey: NSNumber(value: existingIdentifier)) + identifier = existingIdentifier + } + } + return identifier + } + + /// Whether this manager contains the given `instance`. + /// + /// - Parameters: + /// - instance: the instance whose presence in this manager is to be tested + /// - Returns: whether this manager contains the given `instance` + func containsInstance(_ instance: AnyObject) -> Bool { + var containsInstance = false + lockQueue.sync { + containsInstance = identifiers.object(forKey: instance) != nil + } + return containsInstance + } + + /// Removes all of the instances from this manager. + /// + /// The manager will be empty after this call returns. + func removeAllObjects() throws { + lockQueue.sync { + identifiers.removeAllObjects() + weakInstances.removeAllObjects() + strongInstances.removeAllObjects() + nextIdentifier = ProxyApiTestsPigeonInstanceManager.minHostCreatedIdentifier + } + } + + /// The number of instances stored as a strong reference. + /// + /// For debugging and testing purposes. + internal var strongInstanceCount: Int { + var count: Int = 0 + lockQueue.sync { + count = strongInstances.count + } + return count + } + + /// The number of instances stored as a weak reference. + /// + /// For debugging and testing purposes. NSMapTables that store keys or objects as weak + /// reference will be reclaimed non-deterministically. + internal var weakInstanceCount: Int { + var count: Int = 0 + lockQueue.sync { + count = weakInstances.count + } + return count + } +} + +private class ProxyApiTestsPigeonInstanceManagerApi { + /// The codec used for serializing messages. + var codec: FlutterStandardMessageCodec { ProxyApiTestsPigeonCodec.shared } + + /// Handles sending and receiving messages with Dart. + unowned let binaryMessenger: FlutterBinaryMessenger + + init(binaryMessenger: FlutterBinaryMessenger) { + self.binaryMessenger = binaryMessenger + } + + /// Sets up an instance of `ProxyApiTestsPigeonInstanceManagerApi` to handle messages through the `binaryMessenger`. + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, instanceManager: ProxyApiTestsPigeonInstanceManager? + ) { + let codec = ProxyApiTestsPigeonCodec.shared + let removeStrongReferenceChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.PigeonInternalInstanceManager.removeStrongReference", + binaryMessenger: binaryMessenger, codec: codec) + if let instanceManager = instanceManager { + removeStrongReferenceChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let identifierArg = args[0] as! Int64 + do { + let _: AnyObject? = try instanceManager.removeInstance(withIdentifier: identifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + removeStrongReferenceChannel.setMessageHandler(nil) + } + let clearChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.PigeonInternalInstanceManager.clear", + binaryMessenger: binaryMessenger, codec: codec) + if let instanceManager = instanceManager { + clearChannel.setMessageHandler { _, reply in + do { + try instanceManager.removeAllObjects() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + clearChannel.setMessageHandler(nil) + } + } + + /// Sends a message to the Dart `InstanceManager` to remove the strong reference of the instance associated with `identifier`. + func removeStrongReference( + identifier identifierArg: Int64, + completion: @escaping (Result) -> Void + ) { + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.PigeonInternalInstanceManager.removeStrongReference" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([identifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol ProxyApiTestsPigeonProxyApiDelegate { + /// An implementation of [PigeonApiProxyApiTestClass] used to add a new Dart instance of + /// `ProxyApiTestClass` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiProxyApiTestClass(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiTestClass + /// An implementation of [PigeonApiProxyApiSuperClass] used to add a new Dart instance of + /// `ProxyApiSuperClass` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiProxyApiSuperClass(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiSuperClass + /// An implementation of [PigeonApiProxyApiInterface] used to add a new Dart instance of + /// `ProxyApiInterface` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiProxyApiInterface(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiInterface + /// An implementation of [PigeonApiClassWithApiRequirement] used to add a new Dart instance of + /// `ClassWithApiRequirement` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiClassWithApiRequirement(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiClassWithApiRequirement +} + +extension ProxyApiTestsPigeonProxyApiDelegate { + func pigeonApiProxyApiInterface(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiInterface + { + return PigeonApiProxyApiInterface( + pigeonRegistrar: registrar, delegate: PigeonApiDelegateProxyApiInterface()) + } +} + +open class ProxyApiTestsPigeonProxyApiRegistrar { + let binaryMessenger: FlutterBinaryMessenger + let apiDelegate: ProxyApiTestsPigeonProxyApiDelegate + let instanceManager: ProxyApiTestsPigeonInstanceManager + /// Whether APIs should ignore calling to Dart. + public var ignoreCallsToDart = false + private var _codec: FlutterStandardMessageCodec? + var codec: FlutterStandardMessageCodec { + if _codec == nil { + _codec = FlutterStandardMessageCodec( + readerWriter: ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter(pigeonRegistrar: self)) + } + return _codec! + } + + private class InstanceManagerApiFinalizerDelegate: ProxyApiTestsPigeonInternalFinalizerDelegate { + let api: ProxyApiTestsPigeonInstanceManagerApi + + init(_ api: ProxyApiTestsPigeonInstanceManagerApi) { + self.api = api + } + + public func onDeinit(identifier: Int64) { + api.removeStrongReference(identifier: identifier) { + _ in + } + } + } + + init(binaryMessenger: FlutterBinaryMessenger, apiDelegate: ProxyApiTestsPigeonProxyApiDelegate) { + self.binaryMessenger = binaryMessenger + self.apiDelegate = apiDelegate + self.instanceManager = ProxyApiTestsPigeonInstanceManager( + finalizerDelegate: InstanceManagerApiFinalizerDelegate( + ProxyApiTestsPigeonInstanceManagerApi(binaryMessenger: binaryMessenger))) + } + + func setUp() { + ProxyApiTestsPigeonInstanceManagerApi.setUpMessageHandlers( + binaryMessenger: binaryMessenger, instanceManager: instanceManager) + PigeonApiProxyApiTestClass.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiProxyApiTestClass(self)) + PigeonApiProxyApiSuperClass.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiProxyApiSuperClass(self)) + PigeonApiClassWithApiRequirement.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiClassWithApiRequirement(self)) + } + func tearDown() { + ProxyApiTestsPigeonInstanceManagerApi.setUpMessageHandlers( + binaryMessenger: binaryMessenger, instanceManager: nil) + PigeonApiProxyApiTestClass.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiProxyApiSuperClass.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiClassWithApiRequirement.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: nil) + } +} +private class ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter: FlutterStandardReaderWriter { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + + private class ProxyApiTestsPigeonInternalProxyApiCodecReader: ProxyApiTestsPigeonCodecReader { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + + init(data: Data, pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar) { + self.pigeonRegistrar = pigeonRegistrar + super.init(data: data) + } + + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 128: + let identifier = self.readValue() + let instance: AnyObject? = pigeonRegistrar.instanceManager.instance( + forIdentifier: identifier is Int64 ? identifier as! Int64 : Int64(identifier as! Int32)) + return instance + default: + return super.readValue(ofType: type) + } + } + } + + private class ProxyApiTestsPigeonInternalProxyApiCodecWriter: ProxyApiTestsPigeonCodecWriter { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + + init(data: NSMutableData, pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar) { + self.pigeonRegistrar = pigeonRegistrar + super.init(data: data) + } + + override func writeValue(_ value: Any) { + if value is [Any] || value is Bool || value is Data || value is [AnyHashable: Any] + || value is Double || value is FlutterStandardTypedData || value is Int64 || value is String + || value is ProxyApiTestEnum + { + super.writeValue(value) + return + } + + if let instance = value as? ProxyApiTestClass { + pigeonRegistrar.apiDelegate.pigeonApiProxyApiTestClass(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? ProxyApiSuperClass { + pigeonRegistrar.apiDelegate.pigeonApiProxyApiSuperClass(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? ProxyApiInterface { + pigeonRegistrar.apiDelegate.pigeonApiProxyApiInterface(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if #available(iOS 15.0.0, macOS 10.0.0, *), let instance = value as? ClassWithApiRequirement { + pigeonRegistrar.apiDelegate.pigeonApiClassWithApiRequirement(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as AnyObject?, + pigeonRegistrar.instanceManager.containsInstance(instance) + { + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference(forInstance: instance)!) + } else { + print("Unsupported value: \(value) of \(type(of: value))") + assert(false, "Unsupported value for ProxyApiTestsPigeonInternalProxyApiCodecWriter") + } + + } + } + + init(pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar) { + self.pigeonRegistrar = pigeonRegistrar + } + + override func reader(with data: Data) -> FlutterStandardReader { + return ProxyApiTestsPigeonInternalProxyApiCodecReader( + data: data, pigeonRegistrar: pigeonRegistrar) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return ProxyApiTestsPigeonInternalProxyApiCodecWriter( + data: data, pigeonRegistrar: pigeonRegistrar) + } +} + +enum ProxyApiTestEnum: Int { + case one = 0 + case two = 1 + case three = 2 +} + +private class ProxyApiTestsPigeonCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 129: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return ProxyApiTestEnum(rawValue: enumResultAsInt) + } + return nil + default: + return super.readValue(ofType: type) + } + } +} + +private class ProxyApiTestsPigeonCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? ProxyApiTestEnum { + super.writeByte(129) + super.writeValue(value.rawValue) + } else { + super.writeValue(value) + } + } +} + +private class ProxyApiTestsPigeonCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return ProxyApiTestsPigeonCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return ProxyApiTestsPigeonCodecWriter(data: data) + } +} + +class ProxyApiTestsPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = ProxyApiTestsPigeonCodec(readerWriter: ProxyApiTestsPigeonCodecReaderWriter()) +} + +protocol PigeonApiDelegateProxyApiTestClass { + func pigeonDefaultConstructor( + pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double, + aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?], + anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?, + aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?, + aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?, + aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: ProxyApiSuperClass?, boolParam: Bool, intParam: Int64, doubleParam: Double, + stringParam: String, aUint8ListParam: FlutterStandardTypedData, listParam: [Any?], + mapParam: [String?: Any?], enumParam: ProxyApiTestEnum, proxyApiParam: ProxyApiSuperClass, + nullableBoolParam: Bool?, nullableIntParam: Int64?, nullableDoubleParam: Double?, + nullableStringParam: String?, nullableUint8ListParam: FlutterStandardTypedData?, + nullableListParam: [Any?]?, nullableMapParam: [String?: Any?]?, + nullableEnumParam: ProxyApiTestEnum?, nullableProxyApiParam: ProxyApiSuperClass? + ) throws -> ProxyApiTestClass + func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiSuperClass + func staticAttachedField(pigeonApi: PigeonApiProxyApiTestClass) throws -> ProxyApiSuperClass + func aBool(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Bool + func anInt(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Int64 + func aDouble(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Double + func aString(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> String + func aUint8List(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> FlutterStandardTypedData + func aList(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [Any?] + func aMap(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [String?: Any?] + func anEnum(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> ProxyApiTestEnum + func aProxyApi(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> ProxyApiSuperClass + func aNullableBool(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Bool? + func aNullableInt(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Int64? + func aNullableDouble(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Double? + func aNullableString(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> String? + func aNullableUint8List(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> FlutterStandardTypedData? + func aNullableList(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> [Any?]? + func aNullableMap(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [String?: Any?]? + func aNullableEnum(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiTestEnum? + func aNullableProxyApi(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiSuperClass? + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + func noop(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + /// Returns an error, to test error handling. + func throwError(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Any? + /// Returns an error from a void function, to test error handling. + func throwErrorFromVoid(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws + /// Returns a Flutter error, to test error handling. + func throwFlutterError(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Any? + /// Returns passed in int. + func echoInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64 + ) throws -> Int64 + /// Returns passed in double. + func echoDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double + ) throws -> Double + /// Returns the passed in boolean. + func echoBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool + ) throws -> Bool + /// Returns the passed in string. + func echoString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String + ) throws -> String + /// Returns the passed in Uint8List. + func echoUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData + ) throws -> FlutterStandardTypedData + /// Returns the passed in generic Object. + func echoObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any + ) throws -> Any + /// Returns the passed list, to test serialization and deserialization. + func echoList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?] + ) throws -> [Any?] + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + func echoProxyApiList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aList: [ProxyApiTestClass] + ) throws -> [ProxyApiTestClass] + /// Returns the passed map, to test serialization and deserialization. + func echoMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aMap: [String?: Any?] + ) throws -> [String?: Any?] + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + func echoProxyApiMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String: ProxyApiTestClass] + ) throws -> [String: ProxyApiTestClass] + /// Returns the passed enum to test serialization and deserialization. + func echoEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum + ) throws -> ProxyApiTestEnum + /// Returns the passed ProxyApi to test serialization and deserialization. + func echoProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass + ) throws -> ProxyApiSuperClass + /// Returns passed in int. + func echoNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aNullableInt: Int64? + ) throws -> Int64? + /// Returns passed in double. + func echoNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableDouble: Double? + ) throws -> Double? + /// Returns the passed in boolean. + func echoNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aNullableBool: Bool? + ) throws -> Bool? + /// Returns the passed in string. + func echoNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableString: String? + ) throws -> String? + /// Returns the passed in Uint8List. + func echoNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableUint8List: FlutterStandardTypedData? + ) throws -> FlutterStandardTypedData? + /// Returns the passed in generic Object. + func echoNullableObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aNullableObject: Any? + ) throws -> Any? + /// Returns the passed list, to test serialization and deserialization. + func echoNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aNullableList: [Any?]? + ) throws -> [Any?]? + /// Returns the passed map, to test serialization and deserialization. + func echoNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableMap: [String?: Any?]? + ) throws -> [String?: Any?]? + func echoNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableEnum: ProxyApiTestEnum? + ) throws -> ProxyApiTestEnum? + /// Returns the passed ProxyApi to test serialization and deserialization. + func echoNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableProxyApi: ProxyApiSuperClass? + ) throws -> ProxyApiSuperClass? + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + func noopAsync( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Returns passed in int asynchronously. + func echoAsyncInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64, + completion: @escaping (Result) -> Void) + /// Returns passed in double asynchronously. + func echoAsyncDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double, + completion: @escaping (Result) -> Void) + /// Returns the passed in boolean asynchronously. + func echoAsyncBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool, + completion: @escaping (Result) -> Void) + /// Returns the passed string asynchronously. + func echoAsyncString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void) + /// Returns the passed in Uint8List asynchronously. + func echoAsyncUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData, + completion: @escaping (Result) -> Void) + /// Returns the passed in generic Object asynchronously. + func echoAsyncObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any, + completion: @escaping (Result) -> Void) + /// Returns the passed list, to test asynchronous serialization and deserialization. + func echoAsyncList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?], + completion: @escaping (Result<[Any?], Error>) -> Void) + /// Returns the passed map, to test asynchronous serialization and deserialization. + func echoAsyncMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aMap: [String?: Any?], + completion: @escaping (Result<[String?: Any?], Error>) -> Void) + /// Returns the passed enum, to test asynchronous serialization and deserialization. + func echoAsyncEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum, completion: @escaping (Result) -> Void) + /// Responds with an error from an async function returning a value. + func throwAsyncError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Responds with an error from an async void function. + func throwAsyncErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Responds with a Flutter error from an async function returning a value. + func throwAsyncFlutterError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Returns passed in int asynchronously. + func echoAsyncNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64?, + completion: @escaping (Result) -> Void) + /// Returns passed in double asynchronously. + func echoAsyncNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double?, + completion: @escaping (Result) -> Void) + /// Returns the passed in boolean asynchronously. + func echoAsyncNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool?, + completion: @escaping (Result) -> Void) + /// Returns the passed string asynchronously. + func echoAsyncNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String?, + completion: @escaping (Result) -> Void) + /// Returns the passed in Uint8List asynchronously. + func echoAsyncNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void) + /// Returns the passed in generic Object asynchronously. + func echoAsyncNullableObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any?, + completion: @escaping (Result) -> Void) + /// Returns the passed list, to test asynchronous serialization and deserialization. + func echoAsyncNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?]?, + completion: @escaping (Result<[Any?]?, Error>) -> Void) + /// Returns the passed map, to test asynchronous serialization and deserialization. + func echoAsyncNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) + /// Returns the passed enum, to test asynchronous serialization and deserialization. + func echoAsyncNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum?, completion: @escaping (Result) -> Void) + func staticNoop(pigeonApi: PigeonApiProxyApiTestClass) throws + func echoStaticString(pigeonApi: PigeonApiProxyApiTestClass, aString: String) throws -> String + func staticAsyncNoop( + pigeonApi: PigeonApiProxyApiTestClass, completion: @escaping (Result) -> Void) + func callFlutterNoop( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + func callFlutterThrowError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + func callFlutterThrowErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + func callFlutterEchoBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool, + completion: @escaping (Result) -> Void) + func callFlutterEchoInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64, + completion: @escaping (Result) -> Void) + func callFlutterEchoDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double, + completion: @escaping (Result) -> Void) + func callFlutterEchoString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void) + func callFlutterEchoUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData, + completion: @escaping (Result) -> Void) + func callFlutterEchoList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?], + completion: @escaping (Result<[Any?], Error>) -> Void) + func callFlutterEchoProxyApiList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aList: [ProxyApiTestClass?], completion: @escaping (Result<[ProxyApiTestClass?], Error>) -> Void + ) + func callFlutterEchoMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aMap: [String?: Any?], + completion: @escaping (Result<[String?: Any?], Error>) -> Void) + func callFlutterEchoProxyApiMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: ProxyApiTestClass?], + completion: @escaping (Result<[String?: ProxyApiTestClass?], Error>) -> Void) + func callFlutterEchoEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum, completion: @escaping (Result) -> Void) + func callFlutterEchoProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass, completion: @escaping (Result) -> Void + ) + func callFlutterEchoNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?]?, + completion: @escaping (Result<[Any?]?, Error>) -> Void) + func callFlutterEchoNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) + func callFlutterEchoNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass?, + completion: @escaping (Result) -> Void) + func callFlutterNoopAsync( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + func callFlutterEchoAsyncString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void) +} + +protocol PigeonApiProtocolProxyApiTestClass { + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + func flutterNoop( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Responds with an error from an async function returning a value. + func flutterThrowError( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Responds with an error from an async void function. + func flutterThrowErrorFromVoid( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Returns the passed boolean, to test serialization and deserialization. + func flutterEchoBool( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aBool aBoolArg: Bool, + completion: @escaping (Result) -> Void) + /// Returns the passed int, to test serialization and deserialization. + func flutterEchoInt( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anInt anIntArg: Int64, + completion: @escaping (Result) -> Void) + /// Returns the passed double, to test serialization and deserialization. + func flutterEchoDouble( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aDouble aDoubleArg: Double, + completion: @escaping (Result) -> Void) + /// Returns the passed string, to test serialization and deserialization. + func flutterEchoString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String, + completion: @escaping (Result) -> Void) + /// Returns the passed byte list, to test serialization and deserialization. + func flutterEchoUint8List( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: FlutterStandardTypedData, + completion: @escaping (Result) -> Void) + /// Returns the passed list, to test serialization and deserialization. + func flutterEchoList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [Any?], + completion: @escaping (Result<[Any?], ProxyApiTestsError>) -> Void) + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + func flutterEchoProxyApiList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [ProxyApiTestClass?], + completion: @escaping (Result<[ProxyApiTestClass?], ProxyApiTestsError>) -> Void) + /// Returns the passed map, to test serialization and deserialization. + func flutterEchoMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aMap aMapArg: [String?: Any?], + completion: @escaping (Result<[String?: Any?], ProxyApiTestsError>) -> Void) + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + func flutterEchoProxyApiMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + aMap aMapArg: [String?: ProxyApiTestClass?], + completion: @escaping (Result<[String?: ProxyApiTestClass?], ProxyApiTestsError>) -> Void) + /// Returns the passed enum to test serialization and deserialization. + func flutterEchoEnum( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anEnum anEnumArg: ProxyApiTestEnum, + completion: @escaping (Result) -> Void) + /// Returns the passed ProxyApi to test serialization and deserialization. + func flutterEchoProxyApi( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aProxyApi aProxyApiArg: ProxyApiSuperClass, + completion: @escaping (Result) -> Void) + /// Returns the passed boolean, to test serialization and deserialization. + func flutterEchoNullableBool( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aBool aBoolArg: Bool?, + completion: @escaping (Result) -> Void) + /// Returns the passed int, to test serialization and deserialization. + func flutterEchoNullableInt( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anInt anIntArg: Int64?, + completion: @escaping (Result) -> Void) + /// Returns the passed double, to test serialization and deserialization. + func flutterEchoNullableDouble( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aDouble aDoubleArg: Double?, + completion: @escaping (Result) -> Void) + /// Returns the passed string, to test serialization and deserialization. + func flutterEchoNullableString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String?, + completion: @escaping (Result) -> Void) + /// Returns the passed byte list, to test serialization and deserialization. + func flutterEchoNullableUint8List( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void) + /// Returns the passed list, to test serialization and deserialization. + func flutterEchoNullableList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [Any?]?, + completion: @escaping (Result<[Any?]?, ProxyApiTestsError>) -> Void) + /// Returns the passed map, to test serialization and deserialization. + func flutterEchoNullableMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aMap aMapArg: [String?: Any?]?, + completion: @escaping (Result<[String?: Any?]?, ProxyApiTestsError>) -> Void) + /// Returns the passed enum to test serialization and deserialization. + func flutterEchoNullableEnum( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anEnum anEnumArg: ProxyApiTestEnum?, + completion: @escaping (Result) -> Void) + /// Returns the passed ProxyApi to test serialization and deserialization. + func flutterEchoNullableProxyApi( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + aProxyApi aProxyApiArg: ProxyApiSuperClass?, + completion: @escaping (Result) -> Void) + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + func flutterNoopAsync( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Returns the passed in generic Object asynchronously. + func flutterEchoAsyncString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String, + completion: @escaping (Result) -> Void) +} + +final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateProxyApiTestClass + ///An implementation of [ProxyApiSuperClass] used to access callback methods + var pigeonApiProxyApiSuperClass: PigeonApiProxyApiSuperClass { + return pigeonRegistrar.apiDelegate.pigeonApiProxyApiSuperClass(pigeonRegistrar) + } + + ///An implementation of [ProxyApiInterface] used to access callback methods + var pigeonApiProxyApiInterface: PigeonApiProxyApiInterface { + return pigeonRegistrar.apiDelegate.pigeonApiProxyApiInterface(pigeonRegistrar) + } + + init( + pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateProxyApiTestClass + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiProxyApiTestClass? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let aBoolArg = args[1] as! Bool + let anIntArg = args[2] as! Int64 + let aDoubleArg = args[3] as! Double + let aStringArg = args[4] as! String + let aUint8ListArg = args[5] as! FlutterStandardTypedData + let aListArg = args[6] as! [Any?] + let aMapArg = args[7] as! [String?: Any?] + let anEnumArg = args[8] as! ProxyApiTestEnum + let aProxyApiArg = args[9] as! ProxyApiSuperClass + let aNullableBoolArg: Bool? = nilOrValue(args[10]) + let aNullableIntArg: Int64? = nilOrValue(args[11]) + let aNullableDoubleArg: Double? = nilOrValue(args[12]) + let aNullableStringArg: String? = nilOrValue(args[13]) + let aNullableUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[14]) + let aNullableListArg: [Any?]? = nilOrValue(args[15]) + let aNullableMapArg: [String?: Any?]? = nilOrValue(args[16]) + let aNullableEnumArg: ProxyApiTestEnum? = nilOrValue(args[17]) + let aNullableProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[18]) + let boolParamArg = args[19] as! Bool + let intParamArg = args[20] as! Int64 + let doubleParamArg = args[21] as! Double + let stringParamArg = args[22] as! String + let aUint8ListParamArg = args[23] as! FlutterStandardTypedData + let listParamArg = args[24] as! [Any?] + let mapParamArg = args[25] as! [String?: Any?] + let enumParamArg = args[26] as! ProxyApiTestEnum + let proxyApiParamArg = args[27] as! ProxyApiSuperClass + let nullableBoolParamArg: Bool? = nilOrValue(args[28]) + let nullableIntParamArg: Int64? = nilOrValue(args[29]) + let nullableDoubleParamArg: Double? = nilOrValue(args[30]) + let nullableStringParamArg: String? = nilOrValue(args[31]) + let nullableUint8ListParamArg: FlutterStandardTypedData? = nilOrValue(args[32]) + let nullableListParamArg: [Any?]? = nilOrValue(args[33]) + let nullableMapParamArg: [String?: Any?]? = nilOrValue(args[34]) + let nullableEnumParamArg: ProxyApiTestEnum? = nilOrValue(args[35]) + let nullableProxyApiParamArg: ProxyApiSuperClass? = nilOrValue(args[36]) + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, aBool: aBoolArg, anInt: anIntArg, aDouble: aDoubleArg, + aString: aStringArg, aUint8List: aUint8ListArg, aList: aListArg, aMap: aMapArg, + anEnum: anEnumArg, aProxyApi: aProxyApiArg, aNullableBool: aNullableBoolArg, + aNullableInt: aNullableIntArg, aNullableDouble: aNullableDoubleArg, + aNullableString: aNullableStringArg, aNullableUint8List: aNullableUint8ListArg, + aNullableList: aNullableListArg, aNullableMap: aNullableMapArg, + aNullableEnum: aNullableEnumArg, aNullableProxyApi: aNullableProxyApiArg, + boolParam: boolParamArg, intParam: intParamArg, doubleParam: doubleParamArg, + stringParam: stringParamArg, aUint8ListParam: aUint8ListParamArg, + listParam: listParamArg, mapParam: mapParamArg, enumParam: enumParamArg, + proxyApiParam: proxyApiParamArg, nullableBoolParam: nullableBoolParamArg, + nullableIntParam: nullableIntParamArg, nullableDoubleParam: nullableDoubleParamArg, + nullableStringParam: nullableStringParamArg, + nullableUint8ListParam: nullableUint8ListParamArg, + nullableListParam: nullableListParamArg, nullableMapParam: nullableMapParamArg, + nullableEnumParam: nullableEnumParamArg, + nullableProxyApiParam: nullableProxyApiParamArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + let attachedFieldChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.attachedField", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + attachedFieldChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let pigeonIdentifierArg = args[1] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.attachedField(pigeonApi: api, pigeonInstance: pigeonInstanceArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + attachedFieldChannel.setMessageHandler(nil) + } + let staticAttachedFieldChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticAttachedField", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + staticAttachedFieldChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.staticAttachedField(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + staticAttachedFieldChannel.setMessageHandler(nil) + } + let noopChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.noop", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + noopChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + do { + try api.pigeonDelegate.noop(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + noopChannel.setMessageHandler(nil) + } + let throwErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + do { + let result = try api.pigeonDelegate.throwError( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + throwErrorChannel.setMessageHandler(nil) + } + let throwErrorFromVoidChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwErrorFromVoid", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwErrorFromVoidChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + do { + try api.pigeonDelegate.throwErrorFromVoid( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + throwErrorFromVoidChannel.setMessageHandler(nil) + } + let throwFlutterErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwFlutterError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwFlutterErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + do { + let result = try api.pigeonDelegate.throwFlutterError( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + throwFlutterErrorChannel.setMessageHandler(nil) + } + let echoIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg = args[1] as! Int64 + do { + let result = try api.pigeonDelegate.echoInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoIntChannel.setMessageHandler(nil) + } + let echoDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg = args[1] as! Double + do { + let result = try api.pigeonDelegate.echoDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoDoubleChannel.setMessageHandler(nil) + } + let echoBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg = args[1] as! Bool + do { + let result = try api.pigeonDelegate.echoBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoBoolChannel.setMessageHandler(nil) + } + let echoStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg = args[1] as! String + do { + let result = try api.pigeonDelegate.echoString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoStringChannel.setMessageHandler(nil) + } + let echoUint8ListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg = args[1] as! FlutterStandardTypedData + do { + let result = try api.pigeonDelegate.echoUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoUint8ListChannel.setMessageHandler(nil) + } + let echoObjectChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoObject", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anObjectArg = args[1]! + do { + let result = try api.pigeonDelegate.echoObject( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anObject: anObjectArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoObjectChannel.setMessageHandler(nil) + } + let echoListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [Any?] + do { + let result = try api.pigeonDelegate.echoList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoListChannel.setMessageHandler(nil) + } + let echoProxyApiListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoProxyApiList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoProxyApiListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [ProxyApiTestClass] + do { + let result = try api.pigeonDelegate.echoProxyApiList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoProxyApiListChannel.setMessageHandler(nil) + } + let echoMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String?: Any?] + do { + let result = try api.pigeonDelegate.echoMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoMapChannel.setMessageHandler(nil) + } + let echoProxyApiMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoProxyApiMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoProxyApiMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String: ProxyApiTestClass] + do { + let result = try api.pigeonDelegate.echoProxyApiMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoProxyApiMapChannel.setMessageHandler(nil) + } + let echoEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg = args[1] as! ProxyApiTestEnum + do { + let result = try api.pigeonDelegate.echoEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoEnumChannel.setMessageHandler(nil) + } + let echoProxyApiChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoProxyApi", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoProxyApiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aProxyApiArg = args[1] as! ProxyApiSuperClass + do { + let result = try api.pigeonDelegate.echoProxyApi( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aProxyApi: aProxyApiArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoProxyApiChannel.setMessageHandler(nil) + } + let echoNullableIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableIntArg: Int64? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableInt: aNullableIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableIntChannel.setMessageHandler(nil) + } + let echoNullableDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableDoubleArg: Double? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableDouble: aNullableDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableDoubleChannel.setMessageHandler(nil) + } + let echoNullableBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableBoolArg: Bool? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableBool: aNullableBoolArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableBoolChannel.setMessageHandler(nil) + } + let echoNullableStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableStringArg: String? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableString: aNullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableStringChannel.setMessageHandler(nil) + } + let echoNullableUint8ListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, + aNullableUint8List: aNullableUint8ListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableUint8ListChannel.setMessageHandler(nil) + } + let echoNullableObjectChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableObject", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableObjectArg: Any? = args[1] + do { + let result = try api.pigeonDelegate.echoNullableObject( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableObject: aNullableObjectArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableObjectChannel.setMessageHandler(nil) + } + let echoNullableListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableListArg: [Any?]? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableList: aNullableListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableListChannel.setMessageHandler(nil) + } + let echoNullableMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableMapArg: [String?: Any?]? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableMap: aNullableMapArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableMapChannel.setMessageHandler(nil) + } + let echoNullableEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableEnumArg: ProxyApiTestEnum? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableEnum: aNullableEnumArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableEnumChannel.setMessageHandler(nil) + } + let echoNullableProxyApiChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableProxyApi", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableProxyApiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableProxyApi( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, + aNullableProxyApi: aNullableProxyApiArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableProxyApiChannel.setMessageHandler(nil) + } + let noopAsyncChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.noopAsync", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + noopAsyncChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.noopAsync(pigeonApi: api, pigeonInstance: pigeonInstanceArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + noopAsyncChannel.setMessageHandler(nil) + } + let echoAsyncIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg = args[1] as! Int64 + api.pigeonDelegate.echoAsyncInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncIntChannel.setMessageHandler(nil) + } + let echoAsyncDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg = args[1] as! Double + api.pigeonDelegate.echoAsyncDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncDoubleChannel.setMessageHandler(nil) + } + let echoAsyncBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg = args[1] as! Bool + api.pigeonDelegate.echoAsyncBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncBoolChannel.setMessageHandler(nil) + } + let echoAsyncStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg = args[1] as! String + api.pigeonDelegate.echoAsyncString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncStringChannel.setMessageHandler(nil) + } + let echoAsyncUint8ListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg = args[1] as! FlutterStandardTypedData + api.pigeonDelegate.echoAsyncUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncUint8ListChannel.setMessageHandler(nil) + } + let echoAsyncObjectChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncObject", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anObjectArg = args[1]! + api.pigeonDelegate.echoAsyncObject( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anObject: anObjectArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncObjectChannel.setMessageHandler(nil) + } + let echoAsyncListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [Any?] + api.pigeonDelegate.echoAsyncList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncListChannel.setMessageHandler(nil) + } + let echoAsyncMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String?: Any?] + api.pigeonDelegate.echoAsyncMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncMapChannel.setMessageHandler(nil) + } + let echoAsyncEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg = args[1] as! ProxyApiTestEnum + api.pigeonDelegate.echoAsyncEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncEnumChannel.setMessageHandler(nil) + } + let throwAsyncErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwAsyncError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwAsyncErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.throwAsyncError(pigeonApi: api, pigeonInstance: pigeonInstanceArg) { + result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + throwAsyncErrorChannel.setMessageHandler(nil) + } + let throwAsyncErrorFromVoidChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwAsyncErrorFromVoid", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwAsyncErrorFromVoidChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.throwAsyncErrorFromVoid( + pigeonApi: api, pigeonInstance: pigeonInstanceArg + ) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + throwAsyncErrorFromVoidChannel.setMessageHandler(nil) + } + let throwAsyncFlutterErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwAsyncFlutterError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwAsyncFlutterErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.throwAsyncFlutterError(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + throwAsyncFlutterErrorChannel.setMessageHandler(nil) + } + let echoAsyncNullableIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg: Int64? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableIntChannel.setMessageHandler(nil) + } + let echoAsyncNullableDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg: Double? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableDoubleChannel.setMessageHandler(nil) + } + let echoAsyncNullableBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg: Bool? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableBoolChannel.setMessageHandler(nil) + } + let echoAsyncNullableStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg: String? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableStringChannel.setMessageHandler(nil) + } + let echoAsyncNullableUint8ListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableUint8ListChannel.setMessageHandler(nil) + } + let echoAsyncNullableObjectChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableObject", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anObjectArg: Any? = args[1] + api.pigeonDelegate.echoAsyncNullableObject( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anObject: anObjectArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableObjectChannel.setMessageHandler(nil) + } + let echoAsyncNullableListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg: [Any?]? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableListChannel.setMessageHandler(nil) + } + let echoAsyncNullableMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg: [String?: Any?]? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableMapChannel.setMessageHandler(nil) + } + let echoAsyncNullableEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg: ProxyApiTestEnum? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableEnumChannel.setMessageHandler(nil) + } + let staticNoopChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticNoop", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + staticNoopChannel.setMessageHandler { _, reply in + do { + try api.pigeonDelegate.staticNoop(pigeonApi: api) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + staticNoopChannel.setMessageHandler(nil) + } + let echoStaticStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoStaticString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoStaticStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aStringArg = args[0] as! String + do { + let result = try api.pigeonDelegate.echoStaticString(pigeonApi: api, aString: aStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoStaticStringChannel.setMessageHandler(nil) + } + let staticAsyncNoopChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticAsyncNoop", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + staticAsyncNoopChannel.setMessageHandler { _, reply in + api.pigeonDelegate.staticAsyncNoop(pigeonApi: api) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + staticAsyncNoopChannel.setMessageHandler(nil) + } + let callFlutterNoopChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterNoop", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterNoopChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.callFlutterNoop(pigeonApi: api, pigeonInstance: pigeonInstanceArg) { + result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterNoopChannel.setMessageHandler(nil) + } + let callFlutterThrowErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterThrowError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterThrowErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.callFlutterThrowError(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterThrowErrorChannel.setMessageHandler(nil) + } + let callFlutterThrowErrorFromVoidChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterThrowErrorFromVoid", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterThrowErrorFromVoidChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.callFlutterThrowErrorFromVoid( + pigeonApi: api, pigeonInstance: pigeonInstanceArg + ) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterThrowErrorFromVoidChannel.setMessageHandler(nil) + } + let callFlutterEchoBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg = args[1] as! Bool + api.pigeonDelegate.callFlutterEchoBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoBoolChannel.setMessageHandler(nil) + } + let callFlutterEchoIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg = args[1] as! Int64 + api.pigeonDelegate.callFlutterEchoInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoIntChannel.setMessageHandler(nil) + } + let callFlutterEchoDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg = args[1] as! Double + api.pigeonDelegate.callFlutterEchoDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoDoubleChannel.setMessageHandler(nil) + } + let callFlutterEchoStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg = args[1] as! String + api.pigeonDelegate.callFlutterEchoString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoStringChannel.setMessageHandler(nil) + } + let callFlutterEchoUint8ListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg = args[1] as! FlutterStandardTypedData + api.pigeonDelegate.callFlutterEchoUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoUint8ListChannel.setMessageHandler(nil) + } + let callFlutterEchoListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [Any?] + api.pigeonDelegate.callFlutterEchoList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoListChannel.setMessageHandler(nil) + } + let callFlutterEchoProxyApiListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoProxyApiList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoProxyApiListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [ProxyApiTestClass?] + api.pigeonDelegate.callFlutterEchoProxyApiList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoProxyApiListChannel.setMessageHandler(nil) + } + let callFlutterEchoMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String?: Any?] + api.pigeonDelegate.callFlutterEchoMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoMapChannel.setMessageHandler(nil) + } + let callFlutterEchoProxyApiMapChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoProxyApiMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoProxyApiMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String?: ProxyApiTestClass?] + api.pigeonDelegate.callFlutterEchoProxyApiMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoProxyApiMapChannel.setMessageHandler(nil) + } + let callFlutterEchoEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg = args[1] as! ProxyApiTestEnum + api.pigeonDelegate.callFlutterEchoEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoEnumChannel.setMessageHandler(nil) + } + let callFlutterEchoProxyApiChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoProxyApi", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoProxyApiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aProxyApiArg = args[1] as! ProxyApiSuperClass + api.pigeonDelegate.callFlutterEchoProxyApi( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aProxyApi: aProxyApiArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoProxyApiChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableBoolChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg: Bool? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableBoolChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableIntChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg: Int64? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableIntChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableDoubleChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg: Double? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableDoubleChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableStringChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg: String? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableStringChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableUint8ListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableUint8ListChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg: [Any?]? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableListChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableMapChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg: [String?: Any?]? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableMapChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableEnumChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg: ProxyApiTestEnum? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableEnumChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableProxyApiChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableProxyApi", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableProxyApiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableProxyApi( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aProxyApi: aProxyApiArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableProxyApiChannel.setMessageHandler(nil) + } + let callFlutterNoopAsyncChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterNoopAsync", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterNoopAsyncChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.callFlutterNoopAsync(pigeonApi: api, pigeonInstance: pigeonInstanceArg) { + result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterNoopAsyncChannel.setMessageHandler(nil) + } + let callFlutterEchoAsyncStringChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoAsyncString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoAsyncStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg = args[1] as! String + api.pigeonDelegate.callFlutterEchoAsyncString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoAsyncStringChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of ProxyApiTestClass and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let aBoolArg = try! pigeonDelegate.aBool(pigeonApi: self, pigeonInstance: pigeonInstance) + let anIntArg = try! pigeonDelegate.anInt(pigeonApi: self, pigeonInstance: pigeonInstance) + let aDoubleArg = try! pigeonDelegate.aDouble(pigeonApi: self, pigeonInstance: pigeonInstance) + let aStringArg = try! pigeonDelegate.aString(pigeonApi: self, pigeonInstance: pigeonInstance) + let aUint8ListArg = try! pigeonDelegate.aUint8List( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aListArg = try! pigeonDelegate.aList(pigeonApi: self, pigeonInstance: pigeonInstance) + let aMapArg = try! pigeonDelegate.aMap(pigeonApi: self, pigeonInstance: pigeonInstance) + let anEnumArg = try! pigeonDelegate.anEnum(pigeonApi: self, pigeonInstance: pigeonInstance) + let aProxyApiArg = try! pigeonDelegate.aProxyApi( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableBoolArg = try! pigeonDelegate.aNullableBool( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableIntArg = try! pigeonDelegate.aNullableInt( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableDoubleArg = try! pigeonDelegate.aNullableDouble( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableStringArg = try! pigeonDelegate.aNullableString( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableUint8ListArg = try! pigeonDelegate.aNullableUint8List( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableListArg = try! pigeonDelegate.aNullableList( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableMapArg = try! pigeonDelegate.aNullableMap( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableEnumArg = try! pigeonDelegate.aNullableEnum( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableProxyApiArg = try! pigeonDelegate.aNullableProxyApi( + pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage( + [ + pigeonIdentifierArg, aBoolArg, anIntArg, aDoubleArg, aStringArg, aUint8ListArg, aListArg, + aMapArg, anEnumArg, aProxyApiArg, aNullableBoolArg, aNullableIntArg, aNullableDoubleArg, + aNullableStringArg, aNullableUint8ListArg, aNullableListArg, aNullableMapArg, + aNullableEnumArg, aNullableProxyApiArg, + ] as [Any?] + ) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + func flutterNoop( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoop" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Responds with an error from an async function returning a value. + func flutterThrowError( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowError" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: Any? = listResponse[0] + completion(.success(result)) + } + } + } + + /// Responds with an error from an async void function. + func flutterThrowErrorFromVoid( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowErrorFromVoid" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Returns the passed boolean, to test serialization and deserialization. + func flutterEchoBool( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aBool aBoolArg: Bool, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoBool" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aBoolArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! Bool + completion(.success(result)) + } + } + } + + /// Returns the passed int, to test serialization and deserialization. + func flutterEchoInt( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anInt anIntArg: Int64, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoInt" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, anIntArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! Int64 + completion(.success(result)) + } + } + } + + /// Returns the passed double, to test serialization and deserialization. + func flutterEchoDouble( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aDouble aDoubleArg: Double, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoDouble" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aDoubleArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! Double + completion(.success(result)) + } + } + } + + /// Returns the passed string, to test serialization and deserialization. + func flutterEchoString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoString" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aStringArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! String + completion(.success(result)) + } + } + } + + /// Returns the passed byte list, to test serialization and deserialization. + func flutterEchoUint8List( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: FlutterStandardTypedData, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoUint8List" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! FlutterStandardTypedData + completion(.success(result)) + } + } + } + + /// Returns the passed list, to test serialization and deserialization. + func flutterEchoList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [Any?], + completion: @escaping (Result<[Any?], ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoList" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! [Any?] + completion(.success(result)) + } + } + } + + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + func flutterEchoProxyApiList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [ProxyApiTestClass?], + completion: @escaping (Result<[ProxyApiTestClass?], ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiList" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! [ProxyApiTestClass?] + completion(.success(result)) + } + } + } + + /// Returns the passed map, to test serialization and deserialization. + func flutterEchoMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aMap aMapArg: [String?: Any?], + completion: @escaping (Result<[String?: Any?], ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoMap" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aMapArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! [String?: Any?] + completion(.success(result)) + } + } + } + + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + func flutterEchoProxyApiMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + aMap aMapArg: [String?: ProxyApiTestClass?], + completion: @escaping (Result<[String?: ProxyApiTestClass?], ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiMap" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aMapArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! [String?: ProxyApiTestClass?] + completion(.success(result)) + } + } + } + + /// Returns the passed enum to test serialization and deserialization. + func flutterEchoEnum( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anEnum anEnumArg: ProxyApiTestEnum, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, anEnumArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! ProxyApiTestEnum + completion(.success(result)) + } + } + } + + /// Returns the passed ProxyApi to test serialization and deserialization. + func flutterEchoProxyApi( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aProxyApi aProxyApiArg: ProxyApiSuperClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApi" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aProxyApiArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! ProxyApiSuperClass + completion(.success(result)) + } + } + } + + /// Returns the passed boolean, to test serialization and deserialization. + func flutterEchoNullableBool( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aBool aBoolArg: Bool?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableBool" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aBoolArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: Bool? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed int, to test serialization and deserialization. + func flutterEchoNullableInt( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anInt anIntArg: Int64?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableInt" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, anIntArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: Int64? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed double, to test serialization and deserialization. + func flutterEchoNullableDouble( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aDouble aDoubleArg: Double?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableDouble" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aDoubleArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: Double? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed string, to test serialization and deserialization. + func flutterEchoNullableString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableString" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aStringArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: String? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed byte list, to test serialization and deserialization. + func flutterEchoNullableUint8List( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableUint8List" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: FlutterStandardTypedData? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed list, to test serialization and deserialization. + func flutterEchoNullableList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [Any?]?, + completion: @escaping (Result<[Any?]?, ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableList" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: [Any?]? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed map, to test serialization and deserialization. + func flutterEchoNullableMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aMap aMapArg: [String?: Any?]?, + completion: @escaping (Result<[String?: Any?]?, ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableMap" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aMapArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: [String?: Any?]? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed enum to test serialization and deserialization. + func flutterEchoNullableEnum( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anEnum anEnumArg: ProxyApiTestEnum?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableEnum" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, anEnumArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: ProxyApiTestEnum? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed ProxyApi to test serialization and deserialization. + func flutterEchoNullableProxyApi( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + aProxyApi aProxyApiArg: ProxyApiSuperClass?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableProxyApi" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aProxyApiArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: ProxyApiSuperClass? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + func flutterNoopAsync( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoopAsync" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Returns the passed in generic Object asynchronously. + func flutterEchoAsyncString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoAsyncString" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aStringArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! String + completion(.success(result)) + } + } + } + +} +protocol PigeonApiDelegateProxyApiSuperClass { + func pigeonDefaultConstructor(pigeonApi: PigeonApiProxyApiSuperClass) throws -> ProxyApiSuperClass + func aSuperMethod(pigeonApi: PigeonApiProxyApiSuperClass, pigeonInstance: ProxyApiSuperClass) + throws +} + +protocol PigeonApiProtocolProxyApiSuperClass { +} + +final class PigeonApiProxyApiSuperClass: PigeonApiProtocolProxyApiSuperClass { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateProxyApiSuperClass + init( + pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateProxyApiSuperClass + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiProxyApiSuperClass? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + let aSuperMethodChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.aSuperMethod", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + aSuperMethodChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiSuperClass + do { + try api.pigeonDelegate.aSuperMethod(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + aSuperMethodChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of ProxyApiSuperClass and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: ProxyApiSuperClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +open class PigeonApiDelegateProxyApiInterface { +} + +protocol PigeonApiProtocolProxyApiInterface { + func anInterfaceMethod( + pigeonInstance pigeonInstanceArg: ProxyApiInterface, + completion: @escaping (Result) -> Void) +} + +final class PigeonApiProxyApiInterface: PigeonApiProtocolProxyApiInterface { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateProxyApiInterface + init( + pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateProxyApiInterface + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of ProxyApiInterface and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: ProxyApiInterface, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + func anInterfaceMethod( + pigeonInstance pigeonInstanceArg: ProxyApiInterface, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.anInterfaceMethod" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + +} +protocol PigeonApiDelegateClassWithApiRequirement { + @available(iOS 15.0.0, macOS 10.0.0, *) + func pigeonDefaultConstructor(pigeonApi: PigeonApiClassWithApiRequirement) throws + -> ClassWithApiRequirement + @available(iOS 15.0.0, macOS 10.0.0, *) + func aMethod(pigeonApi: PigeonApiClassWithApiRequirement, pigeonInstance: ClassWithApiRequirement) + throws +} + +protocol PigeonApiProtocolClassWithApiRequirement { +} + +final class PigeonApiClassWithApiRequirement: PigeonApiProtocolClassWithApiRequirement { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateClassWithApiRequirement + init( + pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateClassWithApiRequirement + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiClassWithApiRequirement? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + if #available(iOS 15.0.0, macOS 10.0.0, *) { + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + } else { + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if api != nil { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + reply( + wrapError( + FlutterError( + code: "PigeonUnsupportedOperationError", + message: + "Call to pigeonDefaultConstructor requires @available(iOS 15.0.0, macOS 10.0.0, *).", + details: nil + ))) + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + } + if #available(iOS 15.0.0, macOS 10.0.0, *) { + let aMethodChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.aMethod", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + aMethodChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ClassWithApiRequirement + do { + try api.pigeonDelegate.aMethod(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + aMethodChannel.setMessageHandler(nil) + } + } else { + let aMethodChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.aMethod", + binaryMessenger: binaryMessenger, codec: codec) + if api != nil { + aMethodChannel.setMessageHandler { message, reply in + reply( + wrapError( + FlutterError( + code: "PigeonUnsupportedOperationError", + message: "Call to aMethod requires @available(iOS 15.0.0, macOS 10.0.0, *).", + details: nil + ))) + } + } else { + aMethodChannel.setMessageHandler(nil) + } + } + } + + ///Creates a Dart instance of ClassWithApiRequirement and attaches it to [pigeonInstance]. + @available(iOS 15.0.0, macOS 10.0.0, *) + func pigeonNewInstance( + pigeonInstance: ClassWithApiRequirement, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index f94d0be9eff..b4238de3be9 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -12,12 +12,14 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { var flutterAPI: FlutterIntegrationCoreApi var flutterSmallApiOne: FlutterSmallApi var flutterSmallApiTwo: FlutterSmallApi + var proxyApiRegistrar: ProxyApiTestsPigeonProxyApiRegistrar? public static func register(with registrar: FlutterPluginRegistrar) { let plugin = TestPlugin(binaryMessenger: registrar.messenger()) HostIntegrationCoreApiSetup.setUp(binaryMessenger: registrar.messenger(), api: plugin) TestPluginWithSuffix.register(with: registrar, suffix: "suffixOne") TestPluginWithSuffix.register(with: registrar, suffix: "suffixTwo") + registrar.publish(plugin) } init(binaryMessenger: FlutterBinaryMessenger) { @@ -26,6 +28,14 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { binaryMessenger: binaryMessenger, messageChannelSuffix: "suffixOne") flutterSmallApiTwo = FlutterSmallApi( binaryMessenger: binaryMessenger, messageChannelSuffix: "suffixTwo") + proxyApiRegistrar = ProxyApiTestsPigeonProxyApiRegistrar( + binaryMessenger: binaryMessenger, apiDelegate: ProxyApiDelegate()) + proxyApiRegistrar!.setUp() + } + + public func detachFromEngine(for registrar: FlutterPluginRegistrar) { + proxyApiRegistrar!.tearDown() + proxyApiRegistrar = nil } // MARK: HostIntegrationCoreApi implementation @@ -1203,3 +1213,902 @@ public class TestPluginWithSuffix: HostSmallApi { } } + +class ProxyApiDelegate: ProxyApiTestsPigeonProxyApiDelegate { + func pigeonApiProxyApiTestClass(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiTestClass + { + class ProxyApiTestClassDelegate: PigeonApiDelegateProxyApiTestClass { + func pigeonDefaultConstructor( + pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double, + aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?], + anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?, + aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?, + aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?, + aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: ProxyApiSuperClass?, boolParam: Bool, intParam: Int64, + doubleParam: Double, stringParam: String, aUint8ListParam: FlutterStandardTypedData, + listParam: [Any?], mapParam: [String?: Any?], enumParam: ProxyApiTestEnum, + proxyApiParam: ProxyApiSuperClass, nullableBoolParam: Bool?, nullableIntParam: Int64?, + nullableDoubleParam: Double?, nullableStringParam: String?, + nullableUint8ListParam: FlutterStandardTypedData?, nullableListParam: [Any?]?, + nullableMapParam: [String?: Any?]?, nullableEnumParam: ProxyApiTestEnum?, + nullableProxyApiParam: ProxyApiSuperClass? + ) throws -> ProxyApiTestClass { + return ProxyApiTestClass() + } + + func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiSuperClass + { + return ProxyApiSuperClass() + } + + func staticAttachedField(pigeonApi: PigeonApiProxyApiTestClass) throws -> ProxyApiSuperClass { + return ProxyApiSuperClass() + } + + func aBool(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Bool + { + return true + } + + func anInt(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Int64 + { + return 0 + } + + func aDouble(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Double + { + return 0.0 + } + + func aString(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> String + { + return "" + } + + func aUint8List(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> FlutterStandardTypedData + { + return FlutterStandardTypedData(bytes: Data()) + } + + func aList(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [Any?] + { + return [] + } + + func aMap(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [String?: Any?] + { + return [:] + } + + func anEnum(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> ProxyApiTestEnum + { + return ProxyApiTestEnum.one + } + + func aProxyApi(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiSuperClass + { + return ProxyApiSuperClass() + } + + func aNullableBool(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Bool? + { + return nil + } + + func aNullableInt(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Int64? + { + return nil + } + + func aNullableDouble(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Double? + { + return nil + } + + func aNullableString(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> String? + { + return nil + } + + func aNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass + ) throws -> FlutterStandardTypedData? { + return nil + } + + func aNullableList(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> [Any?]? + { + return nil + } + + func aNullableMap(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> [String?: Any?]? + { + return nil + } + + func aNullableEnum(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiTestEnum? + { + return nil + } + + func aNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass + ) throws -> ProxyApiSuperClass? { + return nil + } + + func noop(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws { + } + + func throwError(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Any? + { + throw ProxyApiTestsError(code: "code", message: "message", details: "details") + } + + func throwErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass + ) throws { + throw ProxyApiTestsError(code: "code", message: "message", details: "details") + } + + func throwFlutterError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass + ) throws -> Any? { + throw ProxyApiTestsError(code: "code", message: "message", details: "details") + } + + func echoInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64 + ) throws -> Int64 { + return anInt + } + + func echoDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double + ) throws -> Double { + return aDouble + } + + func echoBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool + ) throws -> Bool { + return aBool + } + + func echoString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String + ) throws -> String { + return aString + } + + func echoUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData + ) throws -> FlutterStandardTypedData { + return aUint8List + } + + func echoObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any + ) throws -> Any { + return anObject + } + + func echoList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?] + ) throws -> [Any?] { + return aList + } + + func echoProxyApiList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aList: [ProxyApiTestClass] + ) throws -> [ProxyApiTestClass] { + return aList + } + + func echoMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?] + ) throws -> [String?: Any?] { + return aMap + } + + func echoProxyApiMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String: ProxyApiTestClass] + ) throws -> [String: ProxyApiTestClass] { + return aMap + } + + func echoEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum + ) throws -> ProxyApiTestEnum { + return anEnum + } + + func echoProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass + ) throws -> ProxyApiSuperClass { + return aProxyApi + } + + func echoNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableInt: Int64? + ) throws -> Int64? { + return aNullableInt + } + + func echoNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableDouble: Double? + ) throws -> Double? { + return aNullableDouble + } + + func echoNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableBool: Bool? + ) throws -> Bool? { + return aNullableBool + } + + func echoNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableString: String? + ) throws -> String? { + return aNullableString + } + + func echoNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableUint8List: FlutterStandardTypedData? + ) throws -> FlutterStandardTypedData? { + return aNullableUint8List + } + + func echoNullableObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableObject: Any? + ) throws -> Any? { + return aNullableObject + } + + func echoNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableList: [Any?]? + ) throws -> [Any?]? { + return aNullableList + } + + func echoNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableMap: [String?: Any?]? + ) throws -> [String?: Any?]? { + return aNullableMap + } + + func echoNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableEnum: ProxyApiTestEnum? + ) throws -> ProxyApiTestEnum? { + return aNullableEnum + } + + func echoNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableProxyApi: ProxyApiSuperClass? + ) throws -> ProxyApiSuperClass? { + return aNullableProxyApi + } + + func noopAsync( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + completion(.success(Void())) + } + + func echoAsyncInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64, + completion: @escaping (Result) -> Void + ) { + completion(.success(anInt)) + } + + func echoAsyncDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double, + completion: @escaping (Result) -> Void + ) { + completion(.success(aDouble)) + } + + func echoAsyncBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool, + completion: @escaping (Result) -> Void + ) { + completion(.success(aBool)) + } + + func echoAsyncString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void + ) { + completion(.success(aString)) + } + + func echoAsyncUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData, + completion: @escaping (Result) -> Void + ) { + completion(.success(aUint8List)) + } + + func echoAsyncObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any, + completion: @escaping (Result) -> Void + ) { + completion(.success(anObject)) + } + + func echoAsyncList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?], + completion: @escaping (Result<[Any?], Error>) -> Void + ) { + completion(.success(aList)) + } + + func echoAsyncMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void + ) { + completion(.success(aMap)) + } + + func echoAsyncEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum, completion: @escaping (Result) -> Void + ) { + completion(.success(anEnum)) + } + + func throwAsyncError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + completion( + .failure(ProxyApiTestsError(code: "code", message: "message", details: "details"))) + } + + func throwAsyncErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + completion( + .failure(ProxyApiTestsError(code: "code", message: "message", details: "details"))) + } + + func throwAsyncFlutterError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + completion( + .failure(ProxyApiTestsError(code: "code", message: "message", details: "details"))) + } + + func echoAsyncNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64?, + completion: @escaping (Result) -> Void + ) { + completion(.success(anInt)) + } + + func echoAsyncNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double?, + completion: @escaping (Result) -> Void + ) { + completion(.success(aDouble)) + } + + func echoAsyncNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool?, + completion: @escaping (Result) -> Void + ) { + completion(.success(aBool)) + } + + func echoAsyncNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String?, + completion: @escaping (Result) -> Void + ) { + completion(.success(aString)) + } + + func echoAsyncNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void + ) { + completion(.success(aUint8List)) + } + + func echoAsyncNullableObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any?, + completion: @escaping (Result) -> Void + ) { + completion(.success(anObject)) + } + + func echoAsyncNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?]?, + completion: @escaping (Result<[Any?]?, Error>) -> Void + ) { + completion(.success(aList)) + } + + func echoAsyncNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void + ) { + completion(.success(aMap)) + } + + func echoAsyncNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum?, completion: @escaping (Result) -> Void + ) { + completion(.success(anEnum)) + } + + func staticNoop(pigeonApi: PigeonApiProxyApiTestClass) throws { + + } + + func echoStaticString(pigeonApi: PigeonApiProxyApiTestClass, aString: String) throws -> String + { + return aString + } + + func staticAsyncNoop( + pigeonApi: PigeonApiProxyApiTestClass, completion: @escaping (Result) -> Void + ) { + completion(.success(Void())) + } + + func callFlutterNoop( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterNoop(pigeonInstance: pigeonInstance) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterThrowError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterThrowError(pigeonInstance: pigeonInstance) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterThrowErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterThrowErrorFromVoid(pigeonInstance: pigeonInstance) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoBool(pigeonInstance: pigeonInstance, aBool: aBool) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoInt(pigeonInstance: pigeonInstance, anInt: anInt) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoDouble(pigeonInstance: pigeonInstance, aDouble: aDouble) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoString(pigeonInstance: pigeonInstance, aString: aString) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoUint8List(pigeonInstance: pigeonInstance, aList: aUint8List) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?], + completion: @escaping (Result<[Any?], Error>) -> Void + ) { + pigeonApi.flutterEchoList(pigeonInstance: pigeonInstance, aList: aList) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoProxyApiList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aList: [ProxyApiTestClass?], + completion: @escaping (Result<[ProxyApiTestClass?], Error>) -> Void + ) { + pigeonApi.flutterEchoProxyApiList(pigeonInstance: pigeonInstance, aList: aList) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void + ) { + pigeonApi.flutterEchoMap(pigeonInstance: pigeonInstance, aMap: aMap) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoProxyApiMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: ProxyApiTestClass?], + completion: @escaping (Result<[String?: ProxyApiTestClass?], Error>) -> Void + ) { + pigeonApi.flutterEchoProxyApiMap(pigeonInstance: pigeonInstance, aMap: aMap) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum, completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoEnum(pigeonInstance: pigeonInstance, anEnum: anEnum) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoProxyApi(pigeonInstance: pigeonInstance, aProxyApi: aProxyApi) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableBool(pigeonInstance: pigeonInstance, aBool: aBool) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableInt(pigeonInstance: pigeonInstance, anInt: anInt) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableDouble(pigeonInstance: pigeonInstance, aDouble: aDouble) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableString(pigeonInstance: pigeonInstance, aString: aString) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableUint8List(pigeonInstance: pigeonInstance, aList: aUint8List) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?]?, + completion: @escaping (Result<[Any?]?, Error>) -> Void + ) { + pigeonApi.flutterEchoNullableList(pigeonInstance: pigeonInstance, aList: aList) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void + ) { + pigeonApi.flutterEchoNullableMap(pigeonInstance: pigeonInstance, aMap: aMap) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum?, completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableEnum(pigeonInstance: pigeonInstance, anEnum: anEnum) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableProxyApi(pigeonInstance: pigeonInstance, aProxyApi: aProxyApi) + { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterNoopAsync( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterNoopAsync(pigeonInstance: pigeonInstance) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoAsyncString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoAsyncString(pigeonInstance: pigeonInstance, aString: aString) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + } + return PigeonApiProxyApiTestClass( + pigeonRegistrar: registrar, delegate: ProxyApiTestClassDelegate()) + } + + func pigeonApiProxyApiSuperClass(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiSuperClass + { + class ProxyApiSuperClassDelegate: PigeonApiDelegateProxyApiSuperClass { + func pigeonDefaultConstructor(pigeonApi: PigeonApiProxyApiSuperClass) throws + -> ProxyApiSuperClass + { + return ProxyApiSuperClass() + } + + func aSuperMethod(pigeonApi: PigeonApiProxyApiSuperClass, pigeonInstance: ProxyApiSuperClass) + throws + {} + } + return PigeonApiProxyApiSuperClass( + pigeonRegistrar: registrar, delegate: ProxyApiSuperClassDelegate()) + } + + func pigeonApiClassWithApiRequirement(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiClassWithApiRequirement + { + class ClassWithApiRequirementDelegate: PigeonApiDelegateClassWithApiRequirement { + @available(iOS 15, *) + func pigeonDefaultConstructor(pigeonApi: PigeonApiClassWithApiRequirement) throws + -> ClassWithApiRequirement + { + return ClassWithApiRequirement() + } + + @available(iOS 15, *) + func aMethod( + pigeonApi: PigeonApiClassWithApiRequirement, pigeonInstance: ClassWithApiRequirement + ) throws { + + } + } + + return PigeonApiClassWithApiRequirement( + pigeonRegistrar: registrar, delegate: ClassWithApiRequirementDelegate()) + } +} diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/.gitignore b/packages/pigeon/platform_tests/test_plugin/macos/Classes/.gitignore index 65eaa145c8a..7a58c79195b 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/.gitignore +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/.gitignore @@ -2,4 +2,8 @@ # changes on generated files. This will need a way to avoid unnecessary churn, # such as a flag to suppress version stamp generation. *.gen.swift -!CoreTests.gen.swift \ No newline at end of file +!CoreTests.gen.swift +# Keeping this makes it easier to review changes to ProxyApi generation. +!ProxyApiTests.gen.swift +# Contains the class declartions for testing ProxyApis. +!ProxyApiTestClass.swift \ No newline at end of file diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTestClass.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTestClass.swift new file mode 100644 index 00000000000..f6e7eed44cb --- /dev/null +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTestClass.swift @@ -0,0 +1,14 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Foundation + +class ProxyApiTestClass: ProxyApiSuperClass, ProxyApiInterface {} + +open class ProxyApiSuperClass {} + +protocol ProxyApiInterface {} + +@available(macOS 10, *) +class ClassWithApiRequirement {} diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTests.gen.swift new file mode 100644 index 00000000000..d3a699ca47a --- /dev/null +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTests.gen.swift @@ -0,0 +1,4191 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Autogenerated from Pigeon, do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +/// Error class for passing custom error details to Dart side. +final class ProxyApiTestsError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "ProxyApiTestsError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? ProxyApiTestsError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details, + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)", + ] +} + +private func createConnectionError(withChannelName channelName: String) -> ProxyApiTestsError { + return ProxyApiTestsError( + code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", + details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} +/// Handles the callback when an object is deallocated. +protocol ProxyApiTestsPigeonInternalFinalizerDelegate: AnyObject { + /// Invoked when the strong reference of an object is deallocated in an `InstanceManager`. + func onDeinit(identifier: Int64) +} + +// Attaches to an object to receive a callback when the object is deallocated. +internal final class ProxyApiTestsPigeonInternalFinalizer { + private static let associatedObjectKey = malloc(1)! + + private let identifier: Int64 + // Reference to the delegate is weak because the callback should be ignored if the + // `InstanceManager` is deallocated. + private weak var delegate: ProxyApiTestsPigeonInternalFinalizerDelegate? + + private init(identifier: Int64, delegate: ProxyApiTestsPigeonInternalFinalizerDelegate) { + self.identifier = identifier + self.delegate = delegate + } + + internal static func attach( + to instance: AnyObject, identifier: Int64, + delegate: ProxyApiTestsPigeonInternalFinalizerDelegate + ) { + let finalizer = ProxyApiTestsPigeonInternalFinalizer(identifier: identifier, delegate: delegate) + objc_setAssociatedObject(instance, associatedObjectKey, finalizer, .OBJC_ASSOCIATION_RETAIN) + } + + static func detach(from instance: AnyObject) { + objc_setAssociatedObject(instance, associatedObjectKey, nil, .OBJC_ASSOCIATION_ASSIGN) + } + + deinit { + delegate?.onDeinit(identifier: identifier) + } +} + +/// Maintains instances used to communicate with the corresponding objects in Dart. +/// +/// Objects stored in this container are represented by an object in Dart that is also stored in +/// an InstanceManager with the same identifier. +/// +/// When an instance is added with an identifier, either can be used to retrieve the other. +/// +/// Added instances are added as a weak reference and a strong reference. When the strong +/// reference is removed and the weak reference is deallocated,`ProxyApiTestsPigeonInternalFinalizerDelegate.onDeinit` +/// is called with the instance's identifier. However, if the strong reference is removed and then the identifier is +/// retrieved with the intention to pass the identifier to Dart (e.g. by calling `identifierWithStrongReference`), +/// the strong reference to the instance is re-added. The strong reference will then need to be removed manually +/// again. +/// +/// Accessing and inserting to an InstanceManager is thread safe. +final class ProxyApiTestsPigeonInstanceManager { + // Identifiers are locked to a specific range to avoid collisions with objects + // created simultaneously from Dart. + // Host uses identifiers >= 2^16 and Dart is expected to use values n where, + // 0 <= n < 2^16. + private static let minHostCreatedIdentifier: Int64 = 65536 + + private let lockQueue = DispatchQueue(label: "ProxyApiTestsPigeonInstanceManager") + private let identifiers: NSMapTable = NSMapTable( + keyOptions: [.weakMemory, .objectPointerPersonality], valueOptions: .strongMemory) + private let weakInstances: NSMapTable = NSMapTable( + keyOptions: .strongMemory, valueOptions: [.weakMemory, .objectPointerPersonality]) + private let strongInstances: NSMapTable = NSMapTable( + keyOptions: .strongMemory, valueOptions: [.strongMemory, .objectPointerPersonality]) + private let finalizerDelegate: ProxyApiTestsPigeonInternalFinalizerDelegate + private var nextIdentifier: Int64 = minHostCreatedIdentifier + + public init(finalizerDelegate: ProxyApiTestsPigeonInternalFinalizerDelegate) { + self.finalizerDelegate = finalizerDelegate + } + + /// Adds a new instance that was instantiated from Dart. + /// + /// The same instance can be added multiple times, but each identifier must be unique. This allows + /// two objects that are equivalent (e.g. conforms to `Equatable`) to both be added. + /// + /// - Parameters: + /// - instance: the instance to be stored + /// - identifier: the identifier to be paired with instance. This value must be >= 0 and unique + func addDartCreatedInstance(_ instance: AnyObject, withIdentifier identifier: Int64) { + lockQueue.async { + self.addInstance(instance, withIdentifier: identifier) + } + } + + /// Adds a new instance that was instantiated from the host platform. + /// + /// - Parameters: + /// - instance: the instance to be stored. This must be unique to all other added instances. + /// - Returns: the unique identifier (>= 0) stored with instance + func addHostCreatedInstance(_ instance: AnyObject) -> Int64 { + assert(!containsInstance(instance), "Instance of \(instance) has already been added.") + var identifier: Int64 = -1 + lockQueue.sync { + identifier = nextIdentifier + nextIdentifier += 1 + self.addInstance(instance, withIdentifier: identifier) + } + return identifier + } + + /// Removes `instanceIdentifier` and its associated strongly referenced instance, if present, from the manager. + /// + /// - Parameters: + /// - instanceIdentifier: the identifier paired to an instance. + /// - Returns: removed instance if the manager contains the given identifier, otherwise `nil` if + /// the manager doesn't contain the value + func removeInstance(withIdentifier instanceIdentifier: Int64) throws -> T? { + var instance: AnyObject? = nil + lockQueue.sync { + instance = strongInstances.object(forKey: NSNumber(value: instanceIdentifier)) + strongInstances.removeObject(forKey: NSNumber(value: instanceIdentifier)) + } + return instance as? T + } + + /// Retrieves the instance associated with identifier. + /// + /// - Parameters: + /// - instanceIdentifier: the identifier associated with an instance + /// - Returns: the instance associated with `instanceIdentifier` if the manager contains the value, otherwise + /// `nil` if the manager doesn't contain the value + func instance(forIdentifier instanceIdentifier: Int64) -> T? { + var instance: AnyObject? = nil + lockQueue.sync { + instance = weakInstances.object(forKey: NSNumber(value: instanceIdentifier)) + } + return instance as? T + } + + private func addInstance(_ instance: AnyObject, withIdentifier identifier: Int64) { + assert(identifier >= 0) + assert( + weakInstances.object(forKey: identifier as NSNumber) == nil, + "Identifier has already been added: \(identifier)") + identifiers.setObject(NSNumber(value: identifier), forKey: instance) + weakInstances.setObject(instance, forKey: NSNumber(value: identifier)) + strongInstances.setObject(instance, forKey: NSNumber(value: identifier)) + ProxyApiTestsPigeonInternalFinalizer.attach( + to: instance, identifier: identifier, delegate: finalizerDelegate) + } + + /// Retrieves the identifier paired with an instance. + /// + /// If the manager contains a strong reference to `instance`, it will return the identifier + /// associated with `instance`. If the manager contains only a weak reference to `instance`, a new + /// strong reference to `instance` will be added and will need to be removed again with `removeInstance`. + /// + /// If this method returns a nonnull identifier, this method also expects the Dart + /// `ProxyApiTestsPigeonInstanceManager` to have, or recreate, a weak reference to the Dart instance the + /// identifier is associated with. + /// + /// - Parameters: + /// - instance: an instance that may be stored in the manager + /// - Returns: the identifier associated with `instance` if the manager contains the value, otherwise + /// `nil` if the manager doesn't contain the value + func identifierWithStrongReference(forInstance instance: AnyObject) -> Int64? { + var identifier: Int64? = nil + lockQueue.sync { + if let existingIdentifier = identifiers.object(forKey: instance)?.int64Value { + strongInstances.setObject(instance, forKey: NSNumber(value: existingIdentifier)) + identifier = existingIdentifier + } + } + return identifier + } + + /// Whether this manager contains the given `instance`. + /// + /// - Parameters: + /// - instance: the instance whose presence in this manager is to be tested + /// - Returns: whether this manager contains the given `instance` + func containsInstance(_ instance: AnyObject) -> Bool { + var containsInstance = false + lockQueue.sync { + containsInstance = identifiers.object(forKey: instance) != nil + } + return containsInstance + } + + /// Removes all of the instances from this manager. + /// + /// The manager will be empty after this call returns. + func removeAllObjects() throws { + lockQueue.sync { + identifiers.removeAllObjects() + weakInstances.removeAllObjects() + strongInstances.removeAllObjects() + nextIdentifier = ProxyApiTestsPigeonInstanceManager.minHostCreatedIdentifier + } + } + + /// The number of instances stored as a strong reference. + /// + /// For debugging and testing purposes. + internal var strongInstanceCount: Int { + var count: Int = 0 + lockQueue.sync { + count = strongInstances.count + } + return count + } + + /// The number of instances stored as a weak reference. + /// + /// For debugging and testing purposes. NSMapTables that store keys or objects as weak + /// reference will be reclaimed non-deterministically. + internal var weakInstanceCount: Int { + var count: Int = 0 + lockQueue.sync { + count = weakInstances.count + } + return count + } +} + +private class ProxyApiTestsPigeonInstanceManagerApi { + /// The codec used for serializing messages. + var codec: FlutterStandardMessageCodec { ProxyApiTestsPigeonCodec.shared } + + /// Handles sending and receiving messages with Dart. + unowned let binaryMessenger: FlutterBinaryMessenger + + init(binaryMessenger: FlutterBinaryMessenger) { + self.binaryMessenger = binaryMessenger + } + + /// Sets up an instance of `ProxyApiTestsPigeonInstanceManagerApi` to handle messages through the `binaryMessenger`. + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, instanceManager: ProxyApiTestsPigeonInstanceManager? + ) { + let codec = ProxyApiTestsPigeonCodec.shared + let removeStrongReferenceChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.PigeonInternalInstanceManager.removeStrongReference", + binaryMessenger: binaryMessenger, codec: codec) + if let instanceManager = instanceManager { + removeStrongReferenceChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let identifierArg = args[0] as! Int64 + do { + let _: AnyObject? = try instanceManager.removeInstance(withIdentifier: identifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + removeStrongReferenceChannel.setMessageHandler(nil) + } + let clearChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.PigeonInternalInstanceManager.clear", + binaryMessenger: binaryMessenger, codec: codec) + if let instanceManager = instanceManager { + clearChannel.setMessageHandler { _, reply in + do { + try instanceManager.removeAllObjects() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + clearChannel.setMessageHandler(nil) + } + } + + /// Sends a message to the Dart `InstanceManager` to remove the strong reference of the instance associated with `identifier`. + func removeStrongReference( + identifier identifierArg: Int64, + completion: @escaping (Result) -> Void + ) { + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.PigeonInternalInstanceManager.removeStrongReference" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([identifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol ProxyApiTestsPigeonProxyApiDelegate { + /// An implementation of [PigeonApiProxyApiTestClass] used to add a new Dart instance of + /// `ProxyApiTestClass` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiProxyApiTestClass(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiTestClass + /// An implementation of [PigeonApiProxyApiSuperClass] used to add a new Dart instance of + /// `ProxyApiSuperClass` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiProxyApiSuperClass(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiSuperClass + /// An implementation of [PigeonApiProxyApiInterface] used to add a new Dart instance of + /// `ProxyApiInterface` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiProxyApiInterface(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiInterface + /// An implementation of [PigeonApiClassWithApiRequirement] used to add a new Dart instance of + /// `ClassWithApiRequirement` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiClassWithApiRequirement(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiClassWithApiRequirement +} + +extension ProxyApiTestsPigeonProxyApiDelegate { + func pigeonApiProxyApiInterface(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiInterface + { + return PigeonApiProxyApiInterface( + pigeonRegistrar: registrar, delegate: PigeonApiDelegateProxyApiInterface()) + } +} + +open class ProxyApiTestsPigeonProxyApiRegistrar { + let binaryMessenger: FlutterBinaryMessenger + let apiDelegate: ProxyApiTestsPigeonProxyApiDelegate + let instanceManager: ProxyApiTestsPigeonInstanceManager + /// Whether APIs should ignore calling to Dart. + public var ignoreCallsToDart = false + private var _codec: FlutterStandardMessageCodec? + var codec: FlutterStandardMessageCodec { + if _codec == nil { + _codec = FlutterStandardMessageCodec( + readerWriter: ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter(pigeonRegistrar: self)) + } + return _codec! + } + + private class InstanceManagerApiFinalizerDelegate: ProxyApiTestsPigeonInternalFinalizerDelegate { + let api: ProxyApiTestsPigeonInstanceManagerApi + + init(_ api: ProxyApiTestsPigeonInstanceManagerApi) { + self.api = api + } + + public func onDeinit(identifier: Int64) { + api.removeStrongReference(identifier: identifier) { + _ in + } + } + } + + init(binaryMessenger: FlutterBinaryMessenger, apiDelegate: ProxyApiTestsPigeonProxyApiDelegate) { + self.binaryMessenger = binaryMessenger + self.apiDelegate = apiDelegate + self.instanceManager = ProxyApiTestsPigeonInstanceManager( + finalizerDelegate: InstanceManagerApiFinalizerDelegate( + ProxyApiTestsPigeonInstanceManagerApi(binaryMessenger: binaryMessenger))) + } + + func setUp() { + ProxyApiTestsPigeonInstanceManagerApi.setUpMessageHandlers( + binaryMessenger: binaryMessenger, instanceManager: instanceManager) + PigeonApiProxyApiTestClass.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiProxyApiTestClass(self)) + PigeonApiProxyApiSuperClass.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiProxyApiSuperClass(self)) + PigeonApiClassWithApiRequirement.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiClassWithApiRequirement(self)) + } + func tearDown() { + ProxyApiTestsPigeonInstanceManagerApi.setUpMessageHandlers( + binaryMessenger: binaryMessenger, instanceManager: nil) + PigeonApiProxyApiTestClass.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiProxyApiSuperClass.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiClassWithApiRequirement.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: nil) + } +} +private class ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter: FlutterStandardReaderWriter { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + + private class ProxyApiTestsPigeonInternalProxyApiCodecReader: ProxyApiTestsPigeonCodecReader { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + + init(data: Data, pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar) { + self.pigeonRegistrar = pigeonRegistrar + super.init(data: data) + } + + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 128: + let identifier = self.readValue() + let instance: AnyObject? = pigeonRegistrar.instanceManager.instance( + forIdentifier: identifier is Int64 ? identifier as! Int64 : Int64(identifier as! Int32)) + return instance + default: + return super.readValue(ofType: type) + } + } + } + + private class ProxyApiTestsPigeonInternalProxyApiCodecWriter: ProxyApiTestsPigeonCodecWriter { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + + init(data: NSMutableData, pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar) { + self.pigeonRegistrar = pigeonRegistrar + super.init(data: data) + } + + override func writeValue(_ value: Any) { + if value is [Any] || value is Bool || value is Data || value is [AnyHashable: Any] + || value is Double || value is FlutterStandardTypedData || value is Int64 || value is String + || value is ProxyApiTestEnum + { + super.writeValue(value) + return + } + + if let instance = value as? ProxyApiTestClass { + pigeonRegistrar.apiDelegate.pigeonApiProxyApiTestClass(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? ProxyApiSuperClass { + pigeonRegistrar.apiDelegate.pigeonApiProxyApiSuperClass(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? ProxyApiInterface { + pigeonRegistrar.apiDelegate.pigeonApiProxyApiInterface(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if #available(iOS 15.0.0, macOS 10.0.0, *), let instance = value as? ClassWithApiRequirement { + pigeonRegistrar.apiDelegate.pigeonApiClassWithApiRequirement(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as AnyObject?, + pigeonRegistrar.instanceManager.containsInstance(instance) + { + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference(forInstance: instance)!) + } else { + print("Unsupported value: \(value) of \(type(of: value))") + assert(false, "Unsupported value for ProxyApiTestsPigeonInternalProxyApiCodecWriter") + } + + } + } + + init(pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar) { + self.pigeonRegistrar = pigeonRegistrar + } + + override func reader(with data: Data) -> FlutterStandardReader { + return ProxyApiTestsPigeonInternalProxyApiCodecReader( + data: data, pigeonRegistrar: pigeonRegistrar) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return ProxyApiTestsPigeonInternalProxyApiCodecWriter( + data: data, pigeonRegistrar: pigeonRegistrar) + } +} + +enum ProxyApiTestEnum: Int { + case one = 0 + case two = 1 + case three = 2 +} + +private class ProxyApiTestsPigeonCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 129: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return ProxyApiTestEnum(rawValue: enumResultAsInt) + } + return nil + default: + return super.readValue(ofType: type) + } + } +} + +private class ProxyApiTestsPigeonCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? ProxyApiTestEnum { + super.writeByte(129) + super.writeValue(value.rawValue) + } else { + super.writeValue(value) + } + } +} + +private class ProxyApiTestsPigeonCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return ProxyApiTestsPigeonCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return ProxyApiTestsPigeonCodecWriter(data: data) + } +} + +class ProxyApiTestsPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = ProxyApiTestsPigeonCodec(readerWriter: ProxyApiTestsPigeonCodecReaderWriter()) +} + +protocol PigeonApiDelegateProxyApiTestClass { + func pigeonDefaultConstructor( + pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double, + aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?], + anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?, + aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?, + aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?, + aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: ProxyApiSuperClass?, boolParam: Bool, intParam: Int64, doubleParam: Double, + stringParam: String, aUint8ListParam: FlutterStandardTypedData, listParam: [Any?], + mapParam: [String?: Any?], enumParam: ProxyApiTestEnum, proxyApiParam: ProxyApiSuperClass, + nullableBoolParam: Bool?, nullableIntParam: Int64?, nullableDoubleParam: Double?, + nullableStringParam: String?, nullableUint8ListParam: FlutterStandardTypedData?, + nullableListParam: [Any?]?, nullableMapParam: [String?: Any?]?, + nullableEnumParam: ProxyApiTestEnum?, nullableProxyApiParam: ProxyApiSuperClass? + ) throws -> ProxyApiTestClass + func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiSuperClass + func staticAttachedField(pigeonApi: PigeonApiProxyApiTestClass) throws -> ProxyApiSuperClass + func aBool(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Bool + func anInt(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Int64 + func aDouble(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Double + func aString(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> String + func aUint8List(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> FlutterStandardTypedData + func aList(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [Any?] + func aMap(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [String?: Any?] + func anEnum(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> ProxyApiTestEnum + func aProxyApi(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> ProxyApiSuperClass + func aNullableBool(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Bool? + func aNullableInt(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Int64? + func aNullableDouble(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Double? + func aNullableString(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> String? + func aNullableUint8List(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> FlutterStandardTypedData? + func aNullableList(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> [Any?]? + func aNullableMap(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [String?: Any?]? + func aNullableEnum(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiTestEnum? + func aNullableProxyApi(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiSuperClass? + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + func noop(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + /// Returns an error, to test error handling. + func throwError(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Any? + /// Returns an error from a void function, to test error handling. + func throwErrorFromVoid(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws + /// Returns a Flutter error, to test error handling. + func throwFlutterError(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Any? + /// Returns passed in int. + func echoInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64 + ) throws -> Int64 + /// Returns passed in double. + func echoDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double + ) throws -> Double + /// Returns the passed in boolean. + func echoBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool + ) throws -> Bool + /// Returns the passed in string. + func echoString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String + ) throws -> String + /// Returns the passed in Uint8List. + func echoUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData + ) throws -> FlutterStandardTypedData + /// Returns the passed in generic Object. + func echoObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any + ) throws -> Any + /// Returns the passed list, to test serialization and deserialization. + func echoList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?] + ) throws -> [Any?] + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + func echoProxyApiList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aList: [ProxyApiTestClass] + ) throws -> [ProxyApiTestClass] + /// Returns the passed map, to test serialization and deserialization. + func echoMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aMap: [String?: Any?] + ) throws -> [String?: Any?] + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + func echoProxyApiMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String: ProxyApiTestClass] + ) throws -> [String: ProxyApiTestClass] + /// Returns the passed enum to test serialization and deserialization. + func echoEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum + ) throws -> ProxyApiTestEnum + /// Returns the passed ProxyApi to test serialization and deserialization. + func echoProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass + ) throws -> ProxyApiSuperClass + /// Returns passed in int. + func echoNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aNullableInt: Int64? + ) throws -> Int64? + /// Returns passed in double. + func echoNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableDouble: Double? + ) throws -> Double? + /// Returns the passed in boolean. + func echoNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aNullableBool: Bool? + ) throws -> Bool? + /// Returns the passed in string. + func echoNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableString: String? + ) throws -> String? + /// Returns the passed in Uint8List. + func echoNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableUint8List: FlutterStandardTypedData? + ) throws -> FlutterStandardTypedData? + /// Returns the passed in generic Object. + func echoNullableObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aNullableObject: Any? + ) throws -> Any? + /// Returns the passed list, to test serialization and deserialization. + func echoNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aNullableList: [Any?]? + ) throws -> [Any?]? + /// Returns the passed map, to test serialization and deserialization. + func echoNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableMap: [String?: Any?]? + ) throws -> [String?: Any?]? + func echoNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableEnum: ProxyApiTestEnum? + ) throws -> ProxyApiTestEnum? + /// Returns the passed ProxyApi to test serialization and deserialization. + func echoNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableProxyApi: ProxyApiSuperClass? + ) throws -> ProxyApiSuperClass? + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + func noopAsync( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Returns passed in int asynchronously. + func echoAsyncInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64, + completion: @escaping (Result) -> Void) + /// Returns passed in double asynchronously. + func echoAsyncDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double, + completion: @escaping (Result) -> Void) + /// Returns the passed in boolean asynchronously. + func echoAsyncBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool, + completion: @escaping (Result) -> Void) + /// Returns the passed string asynchronously. + func echoAsyncString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void) + /// Returns the passed in Uint8List asynchronously. + func echoAsyncUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData, + completion: @escaping (Result) -> Void) + /// Returns the passed in generic Object asynchronously. + func echoAsyncObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any, + completion: @escaping (Result) -> Void) + /// Returns the passed list, to test asynchronous serialization and deserialization. + func echoAsyncList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?], + completion: @escaping (Result<[Any?], Error>) -> Void) + /// Returns the passed map, to test asynchronous serialization and deserialization. + func echoAsyncMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aMap: [String?: Any?], + completion: @escaping (Result<[String?: Any?], Error>) -> Void) + /// Returns the passed enum, to test asynchronous serialization and deserialization. + func echoAsyncEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum, completion: @escaping (Result) -> Void) + /// Responds with an error from an async function returning a value. + func throwAsyncError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Responds with an error from an async void function. + func throwAsyncErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Responds with a Flutter error from an async function returning a value. + func throwAsyncFlutterError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Returns passed in int asynchronously. + func echoAsyncNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64?, + completion: @escaping (Result) -> Void) + /// Returns passed in double asynchronously. + func echoAsyncNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double?, + completion: @escaping (Result) -> Void) + /// Returns the passed in boolean asynchronously. + func echoAsyncNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool?, + completion: @escaping (Result) -> Void) + /// Returns the passed string asynchronously. + func echoAsyncNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String?, + completion: @escaping (Result) -> Void) + /// Returns the passed in Uint8List asynchronously. + func echoAsyncNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void) + /// Returns the passed in generic Object asynchronously. + func echoAsyncNullableObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any?, + completion: @escaping (Result) -> Void) + /// Returns the passed list, to test asynchronous serialization and deserialization. + func echoAsyncNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?]?, + completion: @escaping (Result<[Any?]?, Error>) -> Void) + /// Returns the passed map, to test asynchronous serialization and deserialization. + func echoAsyncNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) + /// Returns the passed enum, to test asynchronous serialization and deserialization. + func echoAsyncNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum?, completion: @escaping (Result) -> Void) + func staticNoop(pigeonApi: PigeonApiProxyApiTestClass) throws + func echoStaticString(pigeonApi: PigeonApiProxyApiTestClass, aString: String) throws -> String + func staticAsyncNoop( + pigeonApi: PigeonApiProxyApiTestClass, completion: @escaping (Result) -> Void) + func callFlutterNoop( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + func callFlutterThrowError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + func callFlutterThrowErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + func callFlutterEchoBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool, + completion: @escaping (Result) -> Void) + func callFlutterEchoInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64, + completion: @escaping (Result) -> Void) + func callFlutterEchoDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double, + completion: @escaping (Result) -> Void) + func callFlutterEchoString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void) + func callFlutterEchoUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData, + completion: @escaping (Result) -> Void) + func callFlutterEchoList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?], + completion: @escaping (Result<[Any?], Error>) -> Void) + func callFlutterEchoProxyApiList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aList: [ProxyApiTestClass?], completion: @escaping (Result<[ProxyApiTestClass?], Error>) -> Void + ) + func callFlutterEchoMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aMap: [String?: Any?], + completion: @escaping (Result<[String?: Any?], Error>) -> Void) + func callFlutterEchoProxyApiMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: ProxyApiTestClass?], + completion: @escaping (Result<[String?: ProxyApiTestClass?], Error>) -> Void) + func callFlutterEchoEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum, completion: @escaping (Result) -> Void) + func callFlutterEchoProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass, completion: @escaping (Result) -> Void + ) + func callFlutterEchoNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void) + func callFlutterEchoNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?]?, + completion: @escaping (Result<[Any?]?, Error>) -> Void) + func callFlutterEchoNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) + func callFlutterEchoNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass?, + completion: @escaping (Result) -> Void) + func callFlutterNoopAsync( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + func callFlutterEchoAsyncString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void) +} + +protocol PigeonApiProtocolProxyApiTestClass { + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + func flutterNoop( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Responds with an error from an async function returning a value. + func flutterThrowError( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Responds with an error from an async void function. + func flutterThrowErrorFromVoid( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Returns the passed boolean, to test serialization and deserialization. + func flutterEchoBool( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aBool aBoolArg: Bool, + completion: @escaping (Result) -> Void) + /// Returns the passed int, to test serialization and deserialization. + func flutterEchoInt( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anInt anIntArg: Int64, + completion: @escaping (Result) -> Void) + /// Returns the passed double, to test serialization and deserialization. + func flutterEchoDouble( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aDouble aDoubleArg: Double, + completion: @escaping (Result) -> Void) + /// Returns the passed string, to test serialization and deserialization. + func flutterEchoString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String, + completion: @escaping (Result) -> Void) + /// Returns the passed byte list, to test serialization and deserialization. + func flutterEchoUint8List( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: FlutterStandardTypedData, + completion: @escaping (Result) -> Void) + /// Returns the passed list, to test serialization and deserialization. + func flutterEchoList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [Any?], + completion: @escaping (Result<[Any?], ProxyApiTestsError>) -> Void) + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + func flutterEchoProxyApiList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [ProxyApiTestClass?], + completion: @escaping (Result<[ProxyApiTestClass?], ProxyApiTestsError>) -> Void) + /// Returns the passed map, to test serialization and deserialization. + func flutterEchoMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aMap aMapArg: [String?: Any?], + completion: @escaping (Result<[String?: Any?], ProxyApiTestsError>) -> Void) + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + func flutterEchoProxyApiMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + aMap aMapArg: [String?: ProxyApiTestClass?], + completion: @escaping (Result<[String?: ProxyApiTestClass?], ProxyApiTestsError>) -> Void) + /// Returns the passed enum to test serialization and deserialization. + func flutterEchoEnum( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anEnum anEnumArg: ProxyApiTestEnum, + completion: @escaping (Result) -> Void) + /// Returns the passed ProxyApi to test serialization and deserialization. + func flutterEchoProxyApi( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aProxyApi aProxyApiArg: ProxyApiSuperClass, + completion: @escaping (Result) -> Void) + /// Returns the passed boolean, to test serialization and deserialization. + func flutterEchoNullableBool( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aBool aBoolArg: Bool?, + completion: @escaping (Result) -> Void) + /// Returns the passed int, to test serialization and deserialization. + func flutterEchoNullableInt( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anInt anIntArg: Int64?, + completion: @escaping (Result) -> Void) + /// Returns the passed double, to test serialization and deserialization. + func flutterEchoNullableDouble( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aDouble aDoubleArg: Double?, + completion: @escaping (Result) -> Void) + /// Returns the passed string, to test serialization and deserialization. + func flutterEchoNullableString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String?, + completion: @escaping (Result) -> Void) + /// Returns the passed byte list, to test serialization and deserialization. + func flutterEchoNullableUint8List( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void) + /// Returns the passed list, to test serialization and deserialization. + func flutterEchoNullableList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [Any?]?, + completion: @escaping (Result<[Any?]?, ProxyApiTestsError>) -> Void) + /// Returns the passed map, to test serialization and deserialization. + func flutterEchoNullableMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aMap aMapArg: [String?: Any?]?, + completion: @escaping (Result<[String?: Any?]?, ProxyApiTestsError>) -> Void) + /// Returns the passed enum to test serialization and deserialization. + func flutterEchoNullableEnum( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anEnum anEnumArg: ProxyApiTestEnum?, + completion: @escaping (Result) -> Void) + /// Returns the passed ProxyApi to test serialization and deserialization. + func flutterEchoNullableProxyApi( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + aProxyApi aProxyApiArg: ProxyApiSuperClass?, + completion: @escaping (Result) -> Void) + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + func flutterNoopAsync( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void) + /// Returns the passed in generic Object asynchronously. + func flutterEchoAsyncString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String, + completion: @escaping (Result) -> Void) +} + +final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateProxyApiTestClass + ///An implementation of [ProxyApiSuperClass] used to access callback methods + var pigeonApiProxyApiSuperClass: PigeonApiProxyApiSuperClass { + return pigeonRegistrar.apiDelegate.pigeonApiProxyApiSuperClass(pigeonRegistrar) + } + + ///An implementation of [ProxyApiInterface] used to access callback methods + var pigeonApiProxyApiInterface: PigeonApiProxyApiInterface { + return pigeonRegistrar.apiDelegate.pigeonApiProxyApiInterface(pigeonRegistrar) + } + + init( + pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateProxyApiTestClass + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiProxyApiTestClass? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let aBoolArg = args[1] as! Bool + let anIntArg = args[2] as! Int64 + let aDoubleArg = args[3] as! Double + let aStringArg = args[4] as! String + let aUint8ListArg = args[5] as! FlutterStandardTypedData + let aListArg = args[6] as! [Any?] + let aMapArg = args[7] as! [String?: Any?] + let anEnumArg = args[8] as! ProxyApiTestEnum + let aProxyApiArg = args[9] as! ProxyApiSuperClass + let aNullableBoolArg: Bool? = nilOrValue(args[10]) + let aNullableIntArg: Int64? = nilOrValue(args[11]) + let aNullableDoubleArg: Double? = nilOrValue(args[12]) + let aNullableStringArg: String? = nilOrValue(args[13]) + let aNullableUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[14]) + let aNullableListArg: [Any?]? = nilOrValue(args[15]) + let aNullableMapArg: [String?: Any?]? = nilOrValue(args[16]) + let aNullableEnumArg: ProxyApiTestEnum? = nilOrValue(args[17]) + let aNullableProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[18]) + let boolParamArg = args[19] as! Bool + let intParamArg = args[20] as! Int64 + let doubleParamArg = args[21] as! Double + let stringParamArg = args[22] as! String + let aUint8ListParamArg = args[23] as! FlutterStandardTypedData + let listParamArg = args[24] as! [Any?] + let mapParamArg = args[25] as! [String?: Any?] + let enumParamArg = args[26] as! ProxyApiTestEnum + let proxyApiParamArg = args[27] as! ProxyApiSuperClass + let nullableBoolParamArg: Bool? = nilOrValue(args[28]) + let nullableIntParamArg: Int64? = nilOrValue(args[29]) + let nullableDoubleParamArg: Double? = nilOrValue(args[30]) + let nullableStringParamArg: String? = nilOrValue(args[31]) + let nullableUint8ListParamArg: FlutterStandardTypedData? = nilOrValue(args[32]) + let nullableListParamArg: [Any?]? = nilOrValue(args[33]) + let nullableMapParamArg: [String?: Any?]? = nilOrValue(args[34]) + let nullableEnumParamArg: ProxyApiTestEnum? = nilOrValue(args[35]) + let nullableProxyApiParamArg: ProxyApiSuperClass? = nilOrValue(args[36]) + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, aBool: aBoolArg, anInt: anIntArg, aDouble: aDoubleArg, + aString: aStringArg, aUint8List: aUint8ListArg, aList: aListArg, aMap: aMapArg, + anEnum: anEnumArg, aProxyApi: aProxyApiArg, aNullableBool: aNullableBoolArg, + aNullableInt: aNullableIntArg, aNullableDouble: aNullableDoubleArg, + aNullableString: aNullableStringArg, aNullableUint8List: aNullableUint8ListArg, + aNullableList: aNullableListArg, aNullableMap: aNullableMapArg, + aNullableEnum: aNullableEnumArg, aNullableProxyApi: aNullableProxyApiArg, + boolParam: boolParamArg, intParam: intParamArg, doubleParam: doubleParamArg, + stringParam: stringParamArg, aUint8ListParam: aUint8ListParamArg, + listParam: listParamArg, mapParam: mapParamArg, enumParam: enumParamArg, + proxyApiParam: proxyApiParamArg, nullableBoolParam: nullableBoolParamArg, + nullableIntParam: nullableIntParamArg, nullableDoubleParam: nullableDoubleParamArg, + nullableStringParam: nullableStringParamArg, + nullableUint8ListParam: nullableUint8ListParamArg, + nullableListParam: nullableListParamArg, nullableMapParam: nullableMapParamArg, + nullableEnumParam: nullableEnumParamArg, + nullableProxyApiParam: nullableProxyApiParamArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + let attachedFieldChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.attachedField", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + attachedFieldChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let pigeonIdentifierArg = args[1] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.attachedField(pigeonApi: api, pigeonInstance: pigeonInstanceArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + attachedFieldChannel.setMessageHandler(nil) + } + let staticAttachedFieldChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticAttachedField", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + staticAttachedFieldChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.staticAttachedField(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + staticAttachedFieldChannel.setMessageHandler(nil) + } + let noopChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.noop", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + noopChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + do { + try api.pigeonDelegate.noop(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + noopChannel.setMessageHandler(nil) + } + let throwErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + do { + let result = try api.pigeonDelegate.throwError( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + throwErrorChannel.setMessageHandler(nil) + } + let throwErrorFromVoidChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwErrorFromVoid", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwErrorFromVoidChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + do { + try api.pigeonDelegate.throwErrorFromVoid( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + throwErrorFromVoidChannel.setMessageHandler(nil) + } + let throwFlutterErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwFlutterError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwFlutterErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + do { + let result = try api.pigeonDelegate.throwFlutterError( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + throwFlutterErrorChannel.setMessageHandler(nil) + } + let echoIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg = args[1] as! Int64 + do { + let result = try api.pigeonDelegate.echoInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoIntChannel.setMessageHandler(nil) + } + let echoDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg = args[1] as! Double + do { + let result = try api.pigeonDelegate.echoDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoDoubleChannel.setMessageHandler(nil) + } + let echoBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg = args[1] as! Bool + do { + let result = try api.pigeonDelegate.echoBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoBoolChannel.setMessageHandler(nil) + } + let echoStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg = args[1] as! String + do { + let result = try api.pigeonDelegate.echoString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoStringChannel.setMessageHandler(nil) + } + let echoUint8ListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg = args[1] as! FlutterStandardTypedData + do { + let result = try api.pigeonDelegate.echoUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoUint8ListChannel.setMessageHandler(nil) + } + let echoObjectChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoObject", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anObjectArg = args[1]! + do { + let result = try api.pigeonDelegate.echoObject( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anObject: anObjectArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoObjectChannel.setMessageHandler(nil) + } + let echoListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [Any?] + do { + let result = try api.pigeonDelegate.echoList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoListChannel.setMessageHandler(nil) + } + let echoProxyApiListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoProxyApiList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoProxyApiListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [ProxyApiTestClass] + do { + let result = try api.pigeonDelegate.echoProxyApiList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoProxyApiListChannel.setMessageHandler(nil) + } + let echoMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String?: Any?] + do { + let result = try api.pigeonDelegate.echoMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoMapChannel.setMessageHandler(nil) + } + let echoProxyApiMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoProxyApiMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoProxyApiMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String: ProxyApiTestClass] + do { + let result = try api.pigeonDelegate.echoProxyApiMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoProxyApiMapChannel.setMessageHandler(nil) + } + let echoEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg = args[1] as! ProxyApiTestEnum + do { + let result = try api.pigeonDelegate.echoEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoEnumChannel.setMessageHandler(nil) + } + let echoProxyApiChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoProxyApi", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoProxyApiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aProxyApiArg = args[1] as! ProxyApiSuperClass + do { + let result = try api.pigeonDelegate.echoProxyApi( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aProxyApi: aProxyApiArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoProxyApiChannel.setMessageHandler(nil) + } + let echoNullableIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableIntArg: Int64? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableInt: aNullableIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableIntChannel.setMessageHandler(nil) + } + let echoNullableDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableDoubleArg: Double? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableDouble: aNullableDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableDoubleChannel.setMessageHandler(nil) + } + let echoNullableBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableBoolArg: Bool? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableBool: aNullableBoolArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableBoolChannel.setMessageHandler(nil) + } + let echoNullableStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableStringArg: String? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableString: aNullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableStringChannel.setMessageHandler(nil) + } + let echoNullableUint8ListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, + aNullableUint8List: aNullableUint8ListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableUint8ListChannel.setMessageHandler(nil) + } + let echoNullableObjectChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableObject", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableObjectArg: Any? = args[1] + do { + let result = try api.pigeonDelegate.echoNullableObject( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableObject: aNullableObjectArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableObjectChannel.setMessageHandler(nil) + } + let echoNullableListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableListArg: [Any?]? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableList: aNullableListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableListChannel.setMessageHandler(nil) + } + let echoNullableMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableMapArg: [String?: Any?]? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableMap: aNullableMapArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableMapChannel.setMessageHandler(nil) + } + let echoNullableEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableEnumArg: ProxyApiTestEnum? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aNullableEnum: aNullableEnumArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableEnumChannel.setMessageHandler(nil) + } + let echoNullableProxyApiChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoNullableProxyApi", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableProxyApiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aNullableProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[1]) + do { + let result = try api.pigeonDelegate.echoNullableProxyApi( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, + aNullableProxyApi: aNullableProxyApiArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoNullableProxyApiChannel.setMessageHandler(nil) + } + let noopAsyncChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.noopAsync", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + noopAsyncChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.noopAsync(pigeonApi: api, pigeonInstance: pigeonInstanceArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + noopAsyncChannel.setMessageHandler(nil) + } + let echoAsyncIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg = args[1] as! Int64 + api.pigeonDelegate.echoAsyncInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncIntChannel.setMessageHandler(nil) + } + let echoAsyncDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg = args[1] as! Double + api.pigeonDelegate.echoAsyncDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncDoubleChannel.setMessageHandler(nil) + } + let echoAsyncBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg = args[1] as! Bool + api.pigeonDelegate.echoAsyncBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncBoolChannel.setMessageHandler(nil) + } + let echoAsyncStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg = args[1] as! String + api.pigeonDelegate.echoAsyncString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncStringChannel.setMessageHandler(nil) + } + let echoAsyncUint8ListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg = args[1] as! FlutterStandardTypedData + api.pigeonDelegate.echoAsyncUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncUint8ListChannel.setMessageHandler(nil) + } + let echoAsyncObjectChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncObject", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anObjectArg = args[1]! + api.pigeonDelegate.echoAsyncObject( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anObject: anObjectArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncObjectChannel.setMessageHandler(nil) + } + let echoAsyncListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [Any?] + api.pigeonDelegate.echoAsyncList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncListChannel.setMessageHandler(nil) + } + let echoAsyncMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String?: Any?] + api.pigeonDelegate.echoAsyncMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncMapChannel.setMessageHandler(nil) + } + let echoAsyncEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg = args[1] as! ProxyApiTestEnum + api.pigeonDelegate.echoAsyncEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncEnumChannel.setMessageHandler(nil) + } + let throwAsyncErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwAsyncError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwAsyncErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.throwAsyncError(pigeonApi: api, pigeonInstance: pigeonInstanceArg) { + result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + throwAsyncErrorChannel.setMessageHandler(nil) + } + let throwAsyncErrorFromVoidChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwAsyncErrorFromVoid", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwAsyncErrorFromVoidChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.throwAsyncErrorFromVoid( + pigeonApi: api, pigeonInstance: pigeonInstanceArg + ) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + throwAsyncErrorFromVoidChannel.setMessageHandler(nil) + } + let throwAsyncFlutterErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.throwAsyncFlutterError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwAsyncFlutterErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.throwAsyncFlutterError(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + throwAsyncFlutterErrorChannel.setMessageHandler(nil) + } + let echoAsyncNullableIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg: Int64? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableIntChannel.setMessageHandler(nil) + } + let echoAsyncNullableDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg: Double? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableDoubleChannel.setMessageHandler(nil) + } + let echoAsyncNullableBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg: Bool? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableBoolChannel.setMessageHandler(nil) + } + let echoAsyncNullableStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg: String? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableStringChannel.setMessageHandler(nil) + } + let echoAsyncNullableUint8ListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableUint8ListChannel.setMessageHandler(nil) + } + let echoAsyncNullableObjectChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableObject", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anObjectArg: Any? = args[1] + api.pigeonDelegate.echoAsyncNullableObject( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anObject: anObjectArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableObjectChannel.setMessageHandler(nil) + } + let echoAsyncNullableListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg: [Any?]? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableListChannel.setMessageHandler(nil) + } + let echoAsyncNullableMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg: [String?: Any?]? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableMapChannel.setMessageHandler(nil) + } + let echoAsyncNullableEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoAsyncNullableEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoAsyncNullableEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg: ProxyApiTestEnum? = nilOrValue(args[1]) + api.pigeonDelegate.echoAsyncNullableEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + echoAsyncNullableEnumChannel.setMessageHandler(nil) + } + let staticNoopChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticNoop", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + staticNoopChannel.setMessageHandler { _, reply in + do { + try api.pigeonDelegate.staticNoop(pigeonApi: api) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + staticNoopChannel.setMessageHandler(nil) + } + let echoStaticStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.echoStaticString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoStaticStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aStringArg = args[0] as! String + do { + let result = try api.pigeonDelegate.echoStaticString(pigeonApi: api, aString: aStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + echoStaticStringChannel.setMessageHandler(nil) + } + let staticAsyncNoopChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.staticAsyncNoop", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + staticAsyncNoopChannel.setMessageHandler { _, reply in + api.pigeonDelegate.staticAsyncNoop(pigeonApi: api) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + staticAsyncNoopChannel.setMessageHandler(nil) + } + let callFlutterNoopChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterNoop", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterNoopChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.callFlutterNoop(pigeonApi: api, pigeonInstance: pigeonInstanceArg) { + result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterNoopChannel.setMessageHandler(nil) + } + let callFlutterThrowErrorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterThrowError", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterThrowErrorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.callFlutterThrowError(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterThrowErrorChannel.setMessageHandler(nil) + } + let callFlutterThrowErrorFromVoidChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterThrowErrorFromVoid", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterThrowErrorFromVoidChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.callFlutterThrowErrorFromVoid( + pigeonApi: api, pigeonInstance: pigeonInstanceArg + ) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterThrowErrorFromVoidChannel.setMessageHandler(nil) + } + let callFlutterEchoBoolChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg = args[1] as! Bool + api.pigeonDelegate.callFlutterEchoBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoBoolChannel.setMessageHandler(nil) + } + let callFlutterEchoIntChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg = args[1] as! Int64 + api.pigeonDelegate.callFlutterEchoInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoIntChannel.setMessageHandler(nil) + } + let callFlutterEchoDoubleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg = args[1] as! Double + api.pigeonDelegate.callFlutterEchoDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoDoubleChannel.setMessageHandler(nil) + } + let callFlutterEchoStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg = args[1] as! String + api.pigeonDelegate.callFlutterEchoString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoStringChannel.setMessageHandler(nil) + } + let callFlutterEchoUint8ListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg = args[1] as! FlutterStandardTypedData + api.pigeonDelegate.callFlutterEchoUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoUint8ListChannel.setMessageHandler(nil) + } + let callFlutterEchoListChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [Any?] + api.pigeonDelegate.callFlutterEchoList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoListChannel.setMessageHandler(nil) + } + let callFlutterEchoProxyApiListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoProxyApiList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoProxyApiListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg = args[1] as! [ProxyApiTestClass?] + api.pigeonDelegate.callFlutterEchoProxyApiList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoProxyApiListChannel.setMessageHandler(nil) + } + let callFlutterEchoMapChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String?: Any?] + api.pigeonDelegate.callFlutterEchoMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoMapChannel.setMessageHandler(nil) + } + let callFlutterEchoProxyApiMapChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoProxyApiMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoProxyApiMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg = args[1] as! [String?: ProxyApiTestClass?] + api.pigeonDelegate.callFlutterEchoProxyApiMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoProxyApiMapChannel.setMessageHandler(nil) + } + let callFlutterEchoEnumChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg = args[1] as! ProxyApiTestEnum + api.pigeonDelegate.callFlutterEchoEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoEnumChannel.setMessageHandler(nil) + } + let callFlutterEchoProxyApiChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoProxyApi", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoProxyApiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aProxyApiArg = args[1] as! ProxyApiSuperClass + api.pigeonDelegate.callFlutterEchoProxyApi( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aProxyApi: aProxyApiArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoProxyApiChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableBoolChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableBool", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aBoolArg: Bool? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableBool( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aBool: aBoolArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableBoolChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableIntChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableInt", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anIntArg: Int64? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableInt( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anInt: anIntArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableIntChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableDoubleChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableDouble", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aDoubleArg: Double? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableDouble( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aDouble: aDoubleArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableDoubleChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableStringChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg: String? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableStringChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableUint8ListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableUint8List", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableUint8List( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aUint8List: aUint8ListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableUint8ListChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableListChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableList", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aListArg: [Any?]? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableList( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aList: aListArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableListChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableMapChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableMap", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableMapChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aMapArg: [String?: Any?]? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableMap( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aMap: aMapArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableMapChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableEnumChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableEnum", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableEnumChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let anEnumArg: ProxyApiTestEnum? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableEnum( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, anEnum: anEnumArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableEnumChannel.setMessageHandler(nil) + } + let callFlutterEchoNullableProxyApiChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoNullableProxyApi", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoNullableProxyApiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[1]) + api.pigeonDelegate.callFlutterEchoNullableProxyApi( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aProxyApi: aProxyApiArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoNullableProxyApiChannel.setMessageHandler(nil) + } + let callFlutterNoopAsyncChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterNoopAsync", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterNoopAsyncChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + api.pigeonDelegate.callFlutterNoopAsync(pigeonApi: api, pigeonInstance: pigeonInstanceArg) { + result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterNoopAsyncChannel.setMessageHandler(nil) + } + let callFlutterEchoAsyncStringChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.callFlutterEchoAsyncString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + callFlutterEchoAsyncStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiTestClass + let aStringArg = args[1] as! String + api.pigeonDelegate.callFlutterEchoAsyncString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, aString: aStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + callFlutterEchoAsyncStringChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of ProxyApiTestClass and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let aBoolArg = try! pigeonDelegate.aBool(pigeonApi: self, pigeonInstance: pigeonInstance) + let anIntArg = try! pigeonDelegate.anInt(pigeonApi: self, pigeonInstance: pigeonInstance) + let aDoubleArg = try! pigeonDelegate.aDouble(pigeonApi: self, pigeonInstance: pigeonInstance) + let aStringArg = try! pigeonDelegate.aString(pigeonApi: self, pigeonInstance: pigeonInstance) + let aUint8ListArg = try! pigeonDelegate.aUint8List( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aListArg = try! pigeonDelegate.aList(pigeonApi: self, pigeonInstance: pigeonInstance) + let aMapArg = try! pigeonDelegate.aMap(pigeonApi: self, pigeonInstance: pigeonInstance) + let anEnumArg = try! pigeonDelegate.anEnum(pigeonApi: self, pigeonInstance: pigeonInstance) + let aProxyApiArg = try! pigeonDelegate.aProxyApi( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableBoolArg = try! pigeonDelegate.aNullableBool( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableIntArg = try! pigeonDelegate.aNullableInt( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableDoubleArg = try! pigeonDelegate.aNullableDouble( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableStringArg = try! pigeonDelegate.aNullableString( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableUint8ListArg = try! pigeonDelegate.aNullableUint8List( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableListArg = try! pigeonDelegate.aNullableList( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableMapArg = try! pigeonDelegate.aNullableMap( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableEnumArg = try! pigeonDelegate.aNullableEnum( + pigeonApi: self, pigeonInstance: pigeonInstance) + let aNullableProxyApiArg = try! pigeonDelegate.aNullableProxyApi( + pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage( + [ + pigeonIdentifierArg, aBoolArg, anIntArg, aDoubleArg, aStringArg, aUint8ListArg, aListArg, + aMapArg, anEnumArg, aProxyApiArg, aNullableBoolArg, aNullableIntArg, aNullableDoubleArg, + aNullableStringArg, aNullableUint8ListArg, aNullableListArg, aNullableMapArg, + aNullableEnumArg, aNullableProxyApiArg, + ] as [Any?] + ) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic calling. + func flutterNoop( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoop" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Responds with an error from an async function returning a value. + func flutterThrowError( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowError" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: Any? = listResponse[0] + completion(.success(result)) + } + } + } + + /// Responds with an error from an async void function. + func flutterThrowErrorFromVoid( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterThrowErrorFromVoid" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Returns the passed boolean, to test serialization and deserialization. + func flutterEchoBool( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aBool aBoolArg: Bool, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoBool" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aBoolArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! Bool + completion(.success(result)) + } + } + } + + /// Returns the passed int, to test serialization and deserialization. + func flutterEchoInt( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anInt anIntArg: Int64, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoInt" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, anIntArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! Int64 + completion(.success(result)) + } + } + } + + /// Returns the passed double, to test serialization and deserialization. + func flutterEchoDouble( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aDouble aDoubleArg: Double, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoDouble" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aDoubleArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! Double + completion(.success(result)) + } + } + } + + /// Returns the passed string, to test serialization and deserialization. + func flutterEchoString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoString" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aStringArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! String + completion(.success(result)) + } + } + } + + /// Returns the passed byte list, to test serialization and deserialization. + func flutterEchoUint8List( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: FlutterStandardTypedData, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoUint8List" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! FlutterStandardTypedData + completion(.success(result)) + } + } + } + + /// Returns the passed list, to test serialization and deserialization. + func flutterEchoList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [Any?], + completion: @escaping (Result<[Any?], ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoList" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! [Any?] + completion(.success(result)) + } + } + } + + /// Returns the passed list with ProxyApis, to test serialization and + /// deserialization. + func flutterEchoProxyApiList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [ProxyApiTestClass?], + completion: @escaping (Result<[ProxyApiTestClass?], ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiList" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! [ProxyApiTestClass?] + completion(.success(result)) + } + } + } + + /// Returns the passed map, to test serialization and deserialization. + func flutterEchoMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aMap aMapArg: [String?: Any?], + completion: @escaping (Result<[String?: Any?], ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoMap" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aMapArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! [String?: Any?] + completion(.success(result)) + } + } + } + + /// Returns the passed map with ProxyApis, to test serialization and + /// deserialization. + func flutterEchoProxyApiMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + aMap aMapArg: [String?: ProxyApiTestClass?], + completion: @escaping (Result<[String?: ProxyApiTestClass?], ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApiMap" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aMapArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! [String?: ProxyApiTestClass?] + completion(.success(result)) + } + } + } + + /// Returns the passed enum to test serialization and deserialization. + func flutterEchoEnum( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anEnum anEnumArg: ProxyApiTestEnum, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoEnum" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, anEnumArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! ProxyApiTestEnum + completion(.success(result)) + } + } + } + + /// Returns the passed ProxyApi to test serialization and deserialization. + func flutterEchoProxyApi( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aProxyApi aProxyApiArg: ProxyApiSuperClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoProxyApi" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aProxyApiArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! ProxyApiSuperClass + completion(.success(result)) + } + } + } + + /// Returns the passed boolean, to test serialization and deserialization. + func flutterEchoNullableBool( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aBool aBoolArg: Bool?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableBool" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aBoolArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: Bool? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed int, to test serialization and deserialization. + func flutterEchoNullableInt( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anInt anIntArg: Int64?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableInt" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, anIntArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: Int64? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed double, to test serialization and deserialization. + func flutterEchoNullableDouble( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aDouble aDoubleArg: Double?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableDouble" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aDoubleArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: Double? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed string, to test serialization and deserialization. + func flutterEchoNullableString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableString" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aStringArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: String? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed byte list, to test serialization and deserialization. + func flutterEchoNullableUint8List( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableUint8List" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: FlutterStandardTypedData? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed list, to test serialization and deserialization. + func flutterEchoNullableList( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aList aListArg: [Any?]?, + completion: @escaping (Result<[Any?]?, ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableList" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aListArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: [Any?]? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed map, to test serialization and deserialization. + func flutterEchoNullableMap( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aMap aMapArg: [String?: Any?]?, + completion: @escaping (Result<[String?: Any?]?, ProxyApiTestsError>) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableMap" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aMapArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: [String?: Any?]? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed enum to test serialization and deserialization. + func flutterEchoNullableEnum( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, anEnum anEnumArg: ProxyApiTestEnum?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableEnum" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, anEnumArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: ProxyApiTestEnum? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// Returns the passed ProxyApi to test serialization and deserialization. + func flutterEchoNullableProxyApi( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + aProxyApi aProxyApiArg: ProxyApiSuperClass?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoNullableProxyApi" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aProxyApiArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + let result: ProxyApiSuperClass? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + + /// A no-op function taking no arguments and returning no value, to sanity + /// test basic asynchronous calling. + func flutterNoopAsync( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterNoopAsync" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Returns the passed in generic Object asynchronously. + func flutterEchoAsyncString( + pigeonInstance pigeonInstanceArg: ProxyApiTestClass, aString aStringArg: String, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.flutterEchoAsyncString" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, aStringArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + ProxyApiTestsError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! String + completion(.success(result)) + } + } + } + +} +protocol PigeonApiDelegateProxyApiSuperClass { + func pigeonDefaultConstructor(pigeonApi: PigeonApiProxyApiSuperClass) throws -> ProxyApiSuperClass + func aSuperMethod(pigeonApi: PigeonApiProxyApiSuperClass, pigeonInstance: ProxyApiSuperClass) + throws +} + +protocol PigeonApiProtocolProxyApiSuperClass { +} + +final class PigeonApiProxyApiSuperClass: PigeonApiProtocolProxyApiSuperClass { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateProxyApiSuperClass + init( + pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateProxyApiSuperClass + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiProxyApiSuperClass? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + let aSuperMethodChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.aSuperMethod", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + aSuperMethodChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ProxyApiSuperClass + do { + try api.pigeonDelegate.aSuperMethod(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + aSuperMethodChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of ProxyApiSuperClass and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: ProxyApiSuperClass, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +open class PigeonApiDelegateProxyApiInterface { +} + +protocol PigeonApiProtocolProxyApiInterface { + func anInterfaceMethod( + pigeonInstance pigeonInstanceArg: ProxyApiInterface, + completion: @escaping (Result) -> Void) +} + +final class PigeonApiProxyApiInterface: PigeonApiProtocolProxyApiInterface { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateProxyApiInterface + init( + pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateProxyApiInterface + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of ProxyApiInterface and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: ProxyApiInterface, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + func anInterfaceMethod( + pigeonInstance pigeonInstanceArg: ProxyApiInterface, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiInterface.anInterfaceMethod" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + +} +protocol PigeonApiDelegateClassWithApiRequirement { + @available(iOS 15.0.0, macOS 10.0.0, *) + func pigeonDefaultConstructor(pigeonApi: PigeonApiClassWithApiRequirement) throws + -> ClassWithApiRequirement + @available(iOS 15.0.0, macOS 10.0.0, *) + func aMethod(pigeonApi: PigeonApiClassWithApiRequirement, pigeonInstance: ClassWithApiRequirement) + throws +} + +protocol PigeonApiProtocolClassWithApiRequirement { +} + +final class PigeonApiClassWithApiRequirement: PigeonApiProtocolClassWithApiRequirement { + unowned let pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateClassWithApiRequirement + init( + pigeonRegistrar: ProxyApiTestsPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateClassWithApiRequirement + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiClassWithApiRequirement? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: ProxyApiTestsPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + if #available(iOS 15.0.0, macOS 10.0.0, *) { + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + } else { + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if api != nil { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + reply( + wrapError( + FlutterError( + code: "PigeonUnsupportedOperationError", + message: + "Call to pigeonDefaultConstructor requires @available(iOS 15.0.0, macOS 10.0.0, *).", + details: nil + ))) + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + } + if #available(iOS 15.0.0, macOS 10.0.0, *) { + let aMethodChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.aMethod", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + aMethodChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! ClassWithApiRequirement + do { + try api.pigeonDelegate.aMethod(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + aMethodChannel.setMessageHandler(nil) + } + } else { + let aMethodChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.aMethod", + binaryMessenger: binaryMessenger, codec: codec) + if api != nil { + aMethodChannel.setMessageHandler { message, reply in + reply( + wrapError( + FlutterError( + code: "PigeonUnsupportedOperationError", + message: "Call to aMethod requires @available(iOS 15.0.0, macOS 10.0.0, *).", + details: nil + ))) + } + } else { + aMethodChannel.setMessageHandler(nil) + } + } + } + + ///Creates a Dart instance of ClassWithApiRequirement and attaches it to [pigeonInstance]. + @available(iOS 15.0.0, macOS 10.0.0, *) + func pigeonNewInstance( + pigeonInstance: ClassWithApiRequirement, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + ProxyApiTestsError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.pigeon_integration_tests.ClassWithApiRequirement.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 3244d62b838..fb5c21dabf1 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -11,12 +11,14 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { var flutterAPI: FlutterIntegrationCoreApi var flutterSmallApiOne: FlutterSmallApi var flutterSmallApiTwo: FlutterSmallApi + var proxyApiRegistrar: ProxyApiTestsPigeonProxyApiRegistrar? public static func register(with registrar: FlutterPluginRegistrar) { let plugin = TestPlugin(binaryMessenger: registrar.messenger) HostIntegrationCoreApiSetup.setUp(binaryMessenger: registrar.messenger, api: plugin) TestPluginWithSuffix.register(with: registrar, suffix: "suffixOne") TestPluginWithSuffix.register(with: registrar, suffix: "suffixTwo") + registrar.publish(plugin) } init(binaryMessenger: FlutterBinaryMessenger) { @@ -25,6 +27,14 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { binaryMessenger: binaryMessenger, messageChannelSuffix: "suffixOne") flutterSmallApiTwo = FlutterSmallApi( binaryMessenger: binaryMessenger, messageChannelSuffix: "suffixTwo") + proxyApiRegistrar = ProxyApiTestsPigeonProxyApiRegistrar( + binaryMessenger: binaryMessenger, apiDelegate: ProxyApiDelegate()) + proxyApiRegistrar!.setUp() + } + + public func detachFromEngine(for registrar: FlutterPluginRegistrar) { + proxyApiRegistrar!.tearDown() + proxyApiRegistrar = nil } // MARK: HostIntegrationCoreApi implementation @@ -1202,3 +1212,910 @@ public class TestPluginWithSuffix: HostSmallApi { } } + +class ProxyApiDelegate: ProxyApiTestsPigeonProxyApiDelegate { + func pigeonApiProxyApiTestClass(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiTestClass + { + class ProxyApiTestClassDelegate: PigeonApiDelegateProxyApiTestClass { + func pigeonDefaultConstructor( + pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double, + aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?], + anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?, + aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?, + aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?, + aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: ProxyApiSuperClass?, boolParam: Bool, intParam: Int64, + doubleParam: Double, stringParam: String, aUint8ListParam: FlutterStandardTypedData, + listParam: [Any?], mapParam: [String?: Any?], enumParam: ProxyApiTestEnum, + proxyApiParam: ProxyApiSuperClass, nullableBoolParam: Bool?, nullableIntParam: Int64?, + nullableDoubleParam: Double?, nullableStringParam: String?, + nullableUint8ListParam: FlutterStandardTypedData?, nullableListParam: [Any?]?, + nullableMapParam: [String?: Any?]?, nullableEnumParam: ProxyApiTestEnum?, + nullableProxyApiParam: ProxyApiSuperClass? + ) throws -> ProxyApiTestClass { + return ProxyApiTestClass() + } + + func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiSuperClass + { + return ProxyApiSuperClass() + } + + func staticAttachedField(pigeonApi: PigeonApiProxyApiTestClass) throws -> ProxyApiSuperClass { + return ProxyApiSuperClass() + } + + func aBool(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Bool + { + return true + } + + func anInt(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Int64 + { + return 0 + } + + func aDouble(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> Double + { + return 0.0 + } + + func aString(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> String + { + return "" + } + + func aUint8List(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> FlutterStandardTypedData + { + return FlutterStandardTypedData(bytes: Data()) + } + + func aList(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [Any?] + { + return [] + } + + func aMap(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> [String?: Any?] + { + return [:] + } + + func anEnum(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws + -> ProxyApiTestEnum + { + return ProxyApiTestEnum.one + } + + func aProxyApi(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiSuperClass + { + return ProxyApiSuperClass() + } + + func aNullableBool(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Bool? + { + return nil + } + + func aNullableInt(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Int64? + { + return nil + } + + func aNullableDouble(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Double? + { + return nil + } + + func aNullableString(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> String? + { + return nil + } + + func aNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass + ) throws -> FlutterStandardTypedData? { + return nil + } + + func aNullableList(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> [Any?]? + { + return nil + } + + func aNullableMap(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> [String?: Any?]? + { + return nil + } + + func aNullableEnum(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> ProxyApiTestEnum? + { + return nil + } + + func aNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass + ) throws -> ProxyApiSuperClass? { + return nil + } + + func noop(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws { + } + + func throwError(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) + throws -> Any? + { + throw ProxyApiTestsError(code: "code", message: "message", details: "details") + } + + func throwErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass + ) throws { + throw ProxyApiTestsError(code: "code", message: "message", details: "details") + } + + func throwFlutterError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass + ) throws -> Any? { + throw ProxyApiTestsError(code: "code", message: "message", details: "details") + } + + func echoInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64 + ) throws -> Int64 { + return anInt + } + + func echoDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double + ) throws -> Double { + return aDouble + } + + func echoBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool + ) throws -> Bool { + return aBool + } + + func echoString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String + ) throws -> String { + return aString + } + + func echoUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData + ) throws -> FlutterStandardTypedData { + return aUint8List + } + + func echoObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any + ) throws -> Any { + return anObject + } + + func echoList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?] + ) throws -> [Any?] { + return aList + } + + func echoProxyApiList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aList: [ProxyApiTestClass] + ) throws -> [ProxyApiTestClass] { + return aList + } + + func echoMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?] + ) throws -> [String?: Any?] { + return aMap + } + + func echoProxyApiMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String: ProxyApiTestClass] + ) throws -> [String: ProxyApiTestClass] { + return aMap + } + + func echoEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum + ) throws -> ProxyApiTestEnum { + return anEnum + } + + func echoProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass + ) throws -> ProxyApiSuperClass { + return aProxyApi + } + + func echoNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableInt: Int64? + ) throws -> Int64? { + return aNullableInt + } + + func echoNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableDouble: Double? + ) throws -> Double? { + return aNullableDouble + } + + func echoNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableBool: Bool? + ) throws -> Bool? { + return aNullableBool + } + + func echoNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableString: String? + ) throws -> String? { + return aNullableString + } + + func echoNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableUint8List: FlutterStandardTypedData? + ) throws -> FlutterStandardTypedData? { + return aNullableUint8List + } + + func echoNullableObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableObject: Any? + ) throws -> Any? { + return aNullableObject + } + + func echoNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableList: [Any?]? + ) throws -> [Any?]? { + return aNullableList + } + + func echoNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableMap: [String?: Any?]? + ) throws -> [String?: Any?]? { + return aNullableMap + } + + func echoNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableEnum: ProxyApiTestEnum? + ) throws -> ProxyApiTestEnum? { + return aNullableEnum + } + + func echoNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aNullableProxyApi: ProxyApiSuperClass? + ) throws -> ProxyApiSuperClass? { + return aNullableProxyApi + } + + func noopAsync( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + completion(.success(Void())) + } + + func echoAsyncInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64, + completion: @escaping (Result) -> Void + ) { + completion(.success(anInt)) + } + + func echoAsyncDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double, + completion: @escaping (Result) -> Void + ) { + completion(.success(aDouble)) + } + + func echoAsyncBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool, + completion: @escaping (Result) -> Void + ) { + completion(.success(aBool)) + } + + func echoAsyncString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void + ) { + completion(.success(aString)) + } + + func echoAsyncUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData, + completion: @escaping (Result) -> Void + ) { + completion(.success(aUint8List)) + } + + func echoAsyncObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any, + completion: @escaping (Result) -> Void + ) { + completion(.success(anObject)) + } + + func echoAsyncList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?], + completion: @escaping (Result<[Any?], Error>) -> Void + ) { + completion(.success(aList)) + } + + func echoAsyncMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void + ) { + completion(.success(aMap)) + } + + func echoAsyncEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum, completion: @escaping (Result) -> Void + ) { + completion(.success(anEnum)) + } + + func throwAsyncError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + completion( + .failure(ProxyApiTestsError(code: "code", message: "message", details: "details"))) + } + + func throwAsyncErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + completion( + .failure(ProxyApiTestsError(code: "code", message: "message", details: "details"))) + } + + func throwAsyncFlutterError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + completion( + .failure(ProxyApiTestsError(code: "code", message: "message", details: "details"))) + } + + func echoAsyncNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64?, + completion: @escaping (Result) -> Void + ) { + completion(.success(anInt)) + } + + func echoAsyncNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double?, + completion: @escaping (Result) -> Void + ) { + completion(.success(aDouble)) + } + + func echoAsyncNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool?, + completion: @escaping (Result) -> Void + ) { + completion(.success(aBool)) + } + + func echoAsyncNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String?, + completion: @escaping (Result) -> Void + ) { + completion(.success(aString)) + } + + func echoAsyncNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void + ) { + completion(.success(aUint8List)) + } + + func echoAsyncNullableObject( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anObject: Any?, + completion: @escaping (Result) -> Void + ) { + completion(.success(anObject)) + } + + func echoAsyncNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?]?, + completion: @escaping (Result<[Any?]?, Error>) -> Void + ) { + completion(.success(aList)) + } + + func echoAsyncNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void + ) { + completion(.success(aMap)) + } + + func echoAsyncNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum?, completion: @escaping (Result) -> Void + ) { + completion(.success(anEnum)) + } + + func staticNoop(pigeonApi: PigeonApiProxyApiTestClass) throws { + + } + + func echoStaticString(pigeonApi: PigeonApiProxyApiTestClass, aString: String) throws -> String + { + return aString + } + + func staticAsyncNoop( + pigeonApi: PigeonApiProxyApiTestClass, completion: @escaping (Result) -> Void + ) { + completion(.success(Void())) + } + + func callFlutterNoop( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterNoop(pigeonInstance: pigeonInstance) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterThrowError( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterThrowError(pigeonInstance: pigeonInstance) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterThrowErrorFromVoid( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterThrowErrorFromVoid(pigeonInstance: pigeonInstance) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoBool(pigeonInstance: pigeonInstance, aBool: aBool) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoInt(pigeonInstance: pigeonInstance, anInt: anInt) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoDouble(pigeonInstance: pigeonInstance, aDouble: aDouble) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoString(pigeonInstance: pigeonInstance, aString: aString) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoUint8List(pigeonInstance: pigeonInstance, aList: aUint8List) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?], + completion: @escaping (Result<[Any?], Error>) -> Void + ) { + pigeonApi.flutterEchoList(pigeonInstance: pigeonInstance, aList: aList) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoProxyApiList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aList: [ProxyApiTestClass?], + completion: @escaping (Result<[ProxyApiTestClass?], Error>) -> Void + ) { + pigeonApi.flutterEchoProxyApiList(pigeonInstance: pigeonInstance, aList: aList) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void + ) { + pigeonApi.flutterEchoMap(pigeonInstance: pigeonInstance, aMap: aMap) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoProxyApiMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: ProxyApiTestClass?], + completion: @escaping (Result<[String?: ProxyApiTestClass?], Error>) -> Void + ) { + pigeonApi.flutterEchoProxyApiMap(pigeonInstance: pigeonInstance, aMap: aMap) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum, completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoEnum(pigeonInstance: pigeonInstance, anEnum: anEnum) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoProxyApi(pigeonInstance: pigeonInstance, aProxyApi: aProxyApi) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableBool( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aBool: Bool?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableBool(pigeonInstance: pigeonInstance, aBool: aBool) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableInt( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, anInt: Int64?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableInt(pigeonInstance: pigeonInstance, anInt: anInt) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableDouble( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aDouble: Double?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableDouble(pigeonInstance: pigeonInstance, aDouble: aDouble) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableString(pigeonInstance: pigeonInstance, aString: aString) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableUint8List( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aUint8List: FlutterStandardTypedData?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableUint8List(pigeonInstance: pigeonInstance, aList: aUint8List) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableList( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aList: [Any?]?, + completion: @escaping (Result<[Any?]?, Error>) -> Void + ) { + pigeonApi.flutterEchoNullableList(pigeonInstance: pigeonInstance, aList: aList) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableMap( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void + ) { + pigeonApi.flutterEchoNullableMap(pigeonInstance: pigeonInstance, aMap: aMap) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableEnum( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + anEnum: ProxyApiTestEnum?, completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableEnum(pigeonInstance: pigeonInstance, anEnum: anEnum) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoNullableProxyApi( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + aProxyApi: ProxyApiSuperClass?, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoNullableProxyApi(pigeonInstance: pigeonInstance, aProxyApi: aProxyApi) + { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterNoopAsync( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterNoopAsync(pigeonInstance: pigeonInstance) { response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func callFlutterEchoAsyncString( + pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass, aString: String, + completion: @escaping (Result) -> Void + ) { + pigeonApi.flutterEchoAsyncString(pigeonInstance: pigeonInstance, aString: aString) { + response in + switch response { + case .success(let res): + completion(.success(res)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + } + return PigeonApiProxyApiTestClass( + pigeonRegistrar: registrar, delegate: ProxyApiTestClassDelegate()) + } + + func pigeonApiProxyApiSuperClass(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiSuperClass + { + class ProxyApiSuperClassDelegate: PigeonApiDelegateProxyApiSuperClass { + func pigeonDefaultConstructor(pigeonApi: PigeonApiProxyApiSuperClass) throws + -> ProxyApiSuperClass + { + return ProxyApiSuperClass() + } + + func aSuperMethod(pigeonApi: PigeonApiProxyApiSuperClass, pigeonInstance: ProxyApiSuperClass) + throws + {} + } + return PigeonApiProxyApiSuperClass( + pigeonRegistrar: registrar, delegate: ProxyApiSuperClassDelegate()) + } + + func pigeonApiProxyApiInterface(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiProxyApiInterface + { + class ProxyApiInterfaceDelegate: PigeonApiDelegateProxyApiInterface {} + return PigeonApiProxyApiInterface( + pigeonRegistrar: registrar, delegate: ProxyApiInterfaceDelegate()) + } + + func pigeonApiClassWithApiRequirement(_ registrar: ProxyApiTestsPigeonProxyApiRegistrar) + -> PigeonApiClassWithApiRequirement + { + class ClassWithApiRequirementDelegate: PigeonApiDelegateClassWithApiRequirement { + @available(macOS 10, *) + func pigeonDefaultConstructor(pigeonApi: PigeonApiClassWithApiRequirement) throws + -> ClassWithApiRequirement + { + return ClassWithApiRequirement() + } + + @available(macOS 10, *) + func aMethod( + pigeonApi: PigeonApiClassWithApiRequirement, pigeonInstance: ClassWithApiRequirement + ) throws { + + } + } + + return PigeonApiClassWithApiRequirement( + pigeonRegistrar: registrar, delegate: ClassWithApiRequirementDelegate()) + } +} diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 2dae3a41b7d..df2a2009fec 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22 -version: 22.4.2 # This must match the version in lib/generator_tools.dart +version: 22.5.0 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.3.0 @@ -16,6 +16,7 @@ dependencies: graphs: ^2.3.1 meta: ^1.9.0 path: ^1.8.0 + pub_semver: ^2.1.4 yaml: ^3.1.1 dev_dependencies: diff --git a/packages/pigeon/test/swift/proxy_api_test.dart b/packages/pigeon/test/swift/proxy_api_test.dart new file mode 100644 index 00000000000..18df858f81e --- /dev/null +++ b/packages/pigeon/test/swift/proxy_api_test.dart @@ -0,0 +1,974 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:pigeon/ast.dart'; +import 'package:pigeon/swift_generator.dart'; +import 'package:test/test.dart'; + +const String DEFAULT_PACKAGE_NAME = 'test_package'; + +void main() { + group('ProxyApi', () { + test('one api', () { + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + swiftOptions: const SwiftProxyApiOptions( + name: 'MyLibraryApi', import: 'MyLibrary'), + constructors: [ + Constructor( + name: 'name', + parameters: [ + Parameter( + type: const TypeDeclaration( + baseName: 'Input', + isNullable: false, + ), + name: 'input', + ), + ], + ), + ], + fields: [ + ApiField( + name: 'someField', + type: const TypeDeclaration( + baseName: 'int', + isNullable: false, + ), + ) + ], + methods: [ + Method( + name: 'doSomething', + location: ApiLocation.host, + parameters: [ + Parameter( + type: const TypeDeclaration( + baseName: 'Input', + isNullable: false, + ), + name: 'input', + ) + ], + returnType: const TypeDeclaration( + baseName: 'String', + isNullable: false, + ), + ), + Method( + name: 'doSomethingElse', + location: ApiLocation.flutter, + isRequired: false, + parameters: [ + Parameter( + type: const TypeDeclaration( + baseName: 'Input', + isNullable: false, + ), + name: 'input', + ), + ], + returnType: const TypeDeclaration( + baseName: 'String', + isNullable: false, + ), + ), + ], + ) + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(fileSpecificClassNameComponent: 'MyFile'), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + + // import + expect(code, contains('import MyLibrary')); + + // Instance Manager + expect( + code, + contains( + r'final class MyFilePigeonInstanceManager', + ), + ); + expect( + code, + contains( + r'private class MyFilePigeonInstanceManagerApi', + ), + ); + + // ProxyApi Delegate + expect(code, contains(r'protocol MyFilePigeonProxyApiDelegate')); + expect( + collapsedCode, + contains( + r'func pigeonApiApi(_ registrar: MyFilePigeonProxyApiRegistrar) -> PigeonApiApi'), + ); + + // API registrar + expect( + code, + contains('open class MyFilePigeonProxyApiRegistrar'), + ); + + // ReaderWriter + expect( + code, + contains( + 'private class MyFilePigeonInternalProxyApiCodecReaderWriter: FlutterStandardReaderWriter', + ), + ); + + // Delegate and class + expect(code, contains('protocol PigeonApiDelegateApi')); + expect(code, contains('protocol PigeonApiProtocolApi')); + expect( + code, + contains( + r'class PigeonApiApi: PigeonApiProtocolApi', + ), + ); + + // Constructors + expect( + collapsedCode, + contains( + r'func name(pigeonApi: PigeonApiApi, someField: Int64, input: Input) throws -> MyLibraryApi', + ), + ); + expect( + collapsedCode, + contains( + r'func pigeonNewInstance(pigeonInstance: MyLibraryApi, completion: @escaping (Result) -> Void) ', + ), + ); + + // Field + expect( + code, + contains( + 'func someField(pigeonApi: PigeonApiApi, pigeonInstance: MyLibraryApi) throws -> Int64', + ), + ); + + // Dart -> Host method + expect( + collapsedCode, + contains( + 'func doSomething(pigeonApi: PigeonApiApi, pigeonInstance: MyLibraryApi, input: Input) throws -> String', + ), + ); + + // Host -> Dart method + expect( + code, + contains( + r'static func setUpMessageHandlers(binaryMessenger: FlutterBinaryMessenger, api: PigeonApiApi?)', + ), + ); + expect( + code, + contains( + 'func doSomethingElse(pigeonInstance pigeonInstanceArg: MyLibraryApi, input inputArg: Input, completion: @escaping (Result) -> Void)', + ), + ); + }); + + group('inheritance', () { + test('extends', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + superClass: TypeDeclaration( + baseName: api2.name, + isNullable: false, + associatedProxyApi: api2, + ), + ), + api2, + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect( + code, + contains('var pigeonApiApi2: PigeonApiApi2'), + ); + }); + + test('implements', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + interfaces: { + TypeDeclaration( + baseName: api2.name, + isNullable: false, + associatedProxyApi: api2, + ) + }, + ), + api2, + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect(code, contains('var pigeonApiApi2: PigeonApiApi2')); + }); + + test('implements 2 ProxyApis', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final AstProxyApi api3 = AstProxyApi( + name: 'Api3', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [], + interfaces: { + TypeDeclaration( + baseName: api2.name, + isNullable: false, + associatedProxyApi: api2, + ), + TypeDeclaration( + baseName: api3.name, + isNullable: false, + associatedProxyApi: api3, + ), + }, + ), + api2, + api3, + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect(code, contains('var pigeonApiApi2: PigeonApiApi2')); + expect(code, contains('var pigeonApiApi3: PigeonApiApi3')); + }); + }); + + group('Constructors', () { + test('empty name and no params constructor', () { + final Root root = Root( + apis: [ + AstProxyApi(name: 'Api', constructors: [ + Constructor( + name: '', + parameters: [], + ) + ], fields: [], methods: []), + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect( + code, + contains('class PigeonApiApi: PigeonApiProtocolApi '), + ); + expect( + collapsedCode, + contains( + 'func pigeonDefaultConstructor(pigeonApi: PigeonApiApi) throws -> Api'), + ); + expect( + collapsedCode, + contains( + r'let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.test_package.Api.pigeon_defaultConstructor", binaryMessenger: binaryMessenger, codec: codec)', + ), + ); + expect( + collapsedCode, + contains( + r'api.pigeonRegistrar.instanceManager.addDartCreatedInstance(', + ), + ); + }); + + test('multiple params constructor', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); + final Root root = Root( + apis: [ + AstProxyApi(name: 'Api', constructors: [ + Constructor( + name: 'name', + parameters: [ + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'int', + ), + name: 'validType', + ), + Parameter( + type: TypeDeclaration( + isNullable: false, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'enumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'Api2', + ), + name: 'proxyApiType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'int', + ), + name: 'nullableValidType', + ), + Parameter( + type: TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'nullableEnumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', + ), + ], + ) + ], fields: [], methods: []), + AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ), + ], + classes: [], + enums: [anEnum], + ); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect( + code, + contains( + 'class PigeonApiApi: PigeonApiProtocolApi ', + ), + ); + expect( + collapsedCode, + contains( + 'func name(pigeonApi: PigeonApiApi, validType: Int64, enumType: AnEnum, proxyApiType: Api2, nullableValidType: Int64?, nullableEnumType: AnEnum?, nullableProxyApiType: Api2?) throws -> Api', + ), + ); + expect( + collapsedCode, + contains( + r'api.pigeonRegistrar.instanceManager.addDartCreatedInstance( ' + r'try api.pigeonDelegate.name(pigeonApi: api, validType: validTypeArg, enumType: enumTypeArg, proxyApiType: ' + r'proxyApiTypeArg, nullableValidType: nullableValidTypeArg, nullableEnumType: nullableEnumTypeArg, ' + r'nullableProxyApiType: nullableProxyApiTypeArg)', + ), + ); + }); + }); + + group('Fields', () { + test('constructor with fields', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [ + Constructor( + name: 'name', + parameters: [], + ) + ], + fields: [ + ApiField( + type: const TypeDeclaration( + isNullable: false, + baseName: 'int', + ), + name: 'validType', + ), + ApiField( + type: TypeDeclaration( + isNullable: false, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'enumType', + ), + ApiField( + type: const TypeDeclaration( + isNullable: false, + baseName: 'Api2', + ), + name: 'proxyApiType', + ), + ApiField( + type: const TypeDeclaration( + isNullable: true, + baseName: 'int', + ), + name: 'nullableValidType', + ), + ApiField( + type: TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'nullableEnumType', + ), + ApiField( + type: const TypeDeclaration( + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', + ), + ], + methods: [], + ), + AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ), + ], + classes: [], + enums: [anEnum], + ); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect( + collapsedCode, + contains( + 'func name(pigeonApi: ' + 'PigeonApiApi, validType: Int64, enumType: AnEnum, proxyApiType: Api2, nullableValidType: Int64?, nullableEnumType: AnEnum?, ' + 'nullableProxyApiType: Api2?) throws -> Api func validType(pigeonApi: PigeonApiApi, pigeonInstance: Api) throws -> Int64 ', + ), + ); + expect( + collapsedCode, + contains( + r'api.pigeonRegistrar.instanceManager.addDartCreatedInstance( try api.pigeonDelegate.name(pigeonApi: api, ' + r'validType: validTypeArg, enumType: enumTypeArg, proxyApiType: proxyApiTypeArg, nullableValidType: nullableValidTypeArg, ' + r'nullableEnumType: nullableEnumTypeArg, nullableProxyApiType: nullableProxyApiTypeArg)', + ), + ); + expect( + collapsedCode, + contains( + 'channel.sendMessage([pigeonIdentifierArg, validTypeArg, enumTypeArg, ' + 'proxyApiTypeArg, nullableValidTypeArg, nullableEnumTypeArg, nullableProxyApiTypeArg] as [Any?])'), + ); + expect( + code, + contains( + r'func validType(pigeonApi: PigeonApiApi, pigeonInstance: Api) throws -> Int64'), + ); + expect( + code, + contains( + r'func enumType(pigeonApi: PigeonApiApi, pigeonInstance: Api) throws -> AnEnum'), + ); + expect( + code, + contains( + r'func proxyApiType(pigeonApi: PigeonApiApi, pigeonInstance: Api) throws -> Api2'), + ); + expect( + code, + contains( + r'func nullableValidType(pigeonApi: PigeonApiApi, pigeonInstance: Api) throws -> Int64?', + ), + ); + expect( + code, + contains( + r'func nullableEnumType(pigeonApi: PigeonApiApi, pigeonInstance: Api) throws -> AnEnum?', + ), + ); + expect( + code, + contains( + r'func nullableProxyApiType(pigeonApi: PigeonApiApi, pigeonInstance: Api) throws -> Api2?', + ), + ); + }); + + test('attached field', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [ + ApiField( + name: 'aField', + isAttached: true, + type: TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: api2, + ), + ), + ], + methods: [], + ), + api2, + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect( + code, + contains( + r'func aField(pigeonApi: PigeonApiApi, pigeonInstance: Api) throws -> Api2'), + ); + expect( + code, + contains( + r'api.pigeonRegistrar.instanceManager.addDartCreatedInstance(try api.pigeonDelegate.aField(pigeonApi: api, pigeonInstance: pigeonInstanceArg), withIdentifier: pigeonIdentifierArg)', + ), + ); + }); + + test('static attached field', () { + final AstProxyApi api2 = AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ); + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [ + ApiField( + name: 'aField', + isStatic: true, + isAttached: true, + type: TypeDeclaration( + baseName: 'Api2', + isNullable: false, + associatedProxyApi: api2, + ), + ), + ], + methods: [], + ), + api2, + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect( + code, + contains(r'func aField(pigeonApi: PigeonApiApi) throws -> Api2'), + ); + expect( + code, + contains( + r'api.pigeonRegistrar.instanceManager.addDartCreatedInstance(try api.pigeonDelegate.aField(pigeonApi: api), withIdentifier: pigeonIdentifierArg)', + ), + ); + }); + }); + + group('Host methods', () { + test('multiple params method', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [ + Method( + name: 'doSomething', + location: ApiLocation.host, + parameters: [ + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'int', + ), + name: 'validType', + ), + Parameter( + type: TypeDeclaration( + isNullable: false, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'enumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'Api2', + ), + name: 'proxyApiType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'int', + ), + name: 'nullableValidType', + ), + Parameter( + type: TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'nullableEnumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + ), + ], + ), + AstProxyApi( + name: 'Api2', + constructors: [], + fields: [], + methods: [], + ), + ], + classes: [], + enums: [anEnum], + ); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect( + collapsedCode, + contains( + 'func doSomething(pigeonApi: ' + 'PigeonApiApi, pigeonInstance: Api, validType: Int64, enumType: AnEnum, proxyApiType: Api2, nullableValidType: Int64?, ' + 'nullableEnumType: AnEnum?, nullableProxyApiType: Api2?) throws', + ), + ); + expect( + collapsedCode, + contains( + r'try api.pigeonDelegate.doSomething(pigeonApi: ' + r'api, pigeonInstance: pigeonInstanceArg, validType: validTypeArg, enumType: enumTypeArg, proxyApiType: ' + r'proxyApiTypeArg, nullableValidType: nullableValidTypeArg, nullableEnumType: nullableEnumTypeArg, nullableProxyApiType: ' + r'nullableProxyApiTypeArg)', + ), + ); + }); + + test('static method', () { + final Root root = Root( + apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [ + Method( + name: 'doSomething', + location: ApiLocation.host, + isStatic: true, + parameters: [], + returnType: const TypeDeclaration.voidDeclaration(), + ), + ], + ), + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect( + collapsedCode, + contains('func doSomething(pigeonApi: PigeonApiApi) throws'), + ); + expect( + collapsedCode, + contains(r'try api.pigeonDelegate.doSomething(pigeonApi: api)'), + ); + }); + }); + + group('Flutter methods', () { + test('multiple params flutter method', () { + final Enum anEnum = Enum( + name: 'AnEnum', + members: [EnumMember(name: 'one')], + ); + final Root root = Root(apis: [ + AstProxyApi( + name: 'Api', + constructors: [], + fields: [], + methods: [ + Method( + name: 'doSomething', + location: ApiLocation.flutter, + parameters: [ + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'int', + ), + name: 'validType', + ), + Parameter( + type: TypeDeclaration( + isNullable: false, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'enumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: false, + baseName: 'Api2', + ), + name: 'proxyApiType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'int', + ), + name: 'nullableValidType', + ), + Parameter( + type: TypeDeclaration( + isNullable: true, + baseName: 'AnEnum', + associatedEnum: anEnum, + ), + name: 'nullableEnumType', + ), + Parameter( + type: const TypeDeclaration( + isNullable: true, + baseName: 'Api2', + ), + name: 'nullableProxyApiType', + ), + ], + returnType: const TypeDeclaration.voidDeclaration(), + ) + ]) + ], classes: [], enums: [ + anEnum + ]); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect( + collapsedCode, + contains( + 'func doSomething(pigeonInstance pigeonInstanceArg: Api, validType validTypeArg: Int64, enumType ' + 'enumTypeArg: AnEnum, proxyApiType proxyApiTypeArg: Api2, nullableValidType nullableValidTypeArg: Int64?, nullableEnumType ' + 'nullableEnumTypeArg: AnEnum?, nullableProxyApiType nullableProxyApiTypeArg: Api2?, ' + 'completion: @escaping (Result) -> Void)', + ), + ); + expect( + collapsedCode, + contains( + r'channel.sendMessage([pigeonInstanceArg, validTypeArg, ' + r'enumTypeArg, proxyApiTypeArg, nullableValidTypeArg, ' + r'nullableEnumTypeArg, nullableProxyApiTypeArg] as [Any?])', + ), + ); + }); + }); + }); +} + +/// Replaces a new line and the indentation with a single white space +/// +/// This +/// +/// ```dart +/// void method( +/// int param1, +/// int param2, +/// ) +/// ``` +/// +/// converts to +/// +/// ```dart +/// void method( int param1, int param2, ) +/// ``` +String _collapseNewlineAndIndentation(String string) { + final StringBuffer result = StringBuffer(); + for (final String line in string.split('\n')) { + result.write('${line.trimLeft()} '); + } + return result.toString().trim(); +} diff --git a/script/configs/allowed_unpinned_deps.yaml b/script/configs/allowed_unpinned_deps.yaml index c0b3b84cd0f..fead5f119d4 100644 --- a/script/configs/allowed_unpinned_deps.yaml +++ b/script/configs/allowed_unpinned_deps.yaml @@ -47,6 +47,7 @@ - mockito - path - platform +- pub_semver - shelf - shelf_static - source_gen