// Autogenerated from Pigeon (v9.1.0), 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 private func wrapResult(_ result: Any?) -> [Any?] { return [result] } private func wrapError(_ error: Any) -> [Any?] { if let flutterError = error as? FlutterError { return [ flutterError.code, flutterError.message, flutterError.details ] } return [ "\(error)", "\(type(of: error))", "Stacktrace: \(Thread.callStackSymbols)" ] } /// Generated class from Pigeon that represents data sent in messages. struct Orientation { var x: Double? = nil var y: Double? = nil var z: Double? = nil static func fromList(_ list: [Any]) -> Orientation? { let x = list[0] as! Double? let y = list[1] as! Double? let z = list[2] as! Double? return Orientation( x: x, y: y, z: z ) } func toList() -> [Any?] { return [ x, y, z, ] } } /// Generated class from Pigeon that represents data sent in messages. struct Position { var latitude: Double? = nil var longitude: Double? = nil var altitude: Double? = nil var bearing: Double? = nil var accuracy: Double? = nil /// the speed at the time of this location in meters per second. var speed: Double? = nil var timeMs: Int64? = nil static func fromList(_ list: [Any]) -> Position? { let latitude = list[0] as! Double? let longitude = list[1] as! Double? let altitude = list[2] as! Double? let bearing = list[3] as! Double? let accuracy = list[4] as! Double? let speed = list[5] as! Double? let timeMs = list[6] as! Int64? return Position( latitude: latitude, longitude: longitude, altitude: altitude, bearing: bearing, accuracy: accuracy, speed: speed, timeMs: timeMs ) } func toList() -> [Any?] { return [ latitude, longitude, altitude, bearing, accuracy, speed, timeMs, ] } } /// Generated class from Pigeon that represents data sent in messages. struct SportWear { var address: String? = nil var name: String? = nil var rssi: Int64? = nil var batteryLevel: Int64? = nil static func fromList(_ list: [Any]) -> SportWear? { let address = list[0] as! String? let name = list[1] as! String? let rssi = list[2] as! Int64? let batteryLevel = list[3] as! Int64? return SportWear( address: address, name: name, rssi: rssi, batteryLevel: batteryLevel ) } func toList() -> [Any?] { return [ address, name, rssi, batteryLevel, ] } } /// Generated class from Pigeon that represents data sent in messages. struct HeartRateMeasurement { var deviceMac: String? = nil var heartRate: Int64? = nil var contactDetected: Bool? = nil var rrIntervals: [Int64?]? = nil var timestampMill: Int64? = nil static func fromList(_ list: [Any]) -> HeartRateMeasurement? { let deviceMac = list[0] as! String? let heartRate = list[1] as! Int64? let contactDetected = list[2] as! Bool? let rrIntervals = list[3] as! [Int64?]? let timestampMill = list[4] as! Int64? return HeartRateMeasurement( deviceMac: deviceMac, heartRate: heartRate, contactDetected: contactDetected, rrIntervals: rrIntervals, timestampMill: timestampMill ) } func toList() -> [Any?] { return [ deviceMac, heartRate, contactDetected, rrIntervals, timestampMill, ] } } private class SensorApiCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { case 128: return HeartRateMeasurement.fromList(self.readValue() as! [Any]) case 129: return Orientation.fromList(self.readValue() as! [Any]) case 130: return Position.fromList(self.readValue() as! [Any]) case 131: return SportWear.fromList(self.readValue() as! [Any]) default: return super.readValue(ofType: type) } } } private class SensorApiCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { if let value = value as? HeartRateMeasurement { super.writeByte(128) super.writeValue(value.toList()) } else if let value = value as? Orientation { super.writeByte(129) super.writeValue(value.toList()) } else if let value = value as? Position { super.writeByte(130) super.writeValue(value.toList()) } else if let value = value as? SportWear { super.writeByte(131) super.writeValue(value.toList()) } else { super.writeValue(value) } } } private class SensorApiCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { return SensorApiCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { return SensorApiCodecWriter(data: data) } } class SensorApiCodec: FlutterStandardMessageCodec { static let shared = SensorApiCodec(readerWriter: SensorApiCodecReaderWriter()) } /// Generated protocol from Pigeon that represents a handler of messages from Flutter. protocol SensorApi { /// 获取当前位置,[force]为 false 时, /// 优先使用 lastPosition,为 true 强制重新获取当前位置。 func getCurrentPosition(force: Bool, completion: @escaping (Result) -> Void) func locationStart(minTimeMs: Int64, minDistanceM: Double) throws func locationStop() throws func sportWearScanStart() throws func sportWearScanStop() throws func askEnableBluetooth(completion: @escaping (Result) -> Void) func sportWearConnect(wear: SportWear, completion: @escaping (Result) -> Void) func sportWearDisconnect(wear: SportWear, completion: @escaping (Result) -> Void) /// 是否开启位置服务 func isLocationServiceOpen() throws -> Bool func getYDPI() throws -> Double func getXDPI() throws -> Double /// 只需要空实现即可,class必须有函数引用才会生成代码 func toGenAllClass(orientation: Orientation, hrm: HeartRateMeasurement, position: Position) throws } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class SensorApiSetup { /// The codec used by SensorApi. static var codec: FlutterStandardMessageCodec { SensorApiCodec.shared } /// Sets up an instance of `SensorApi` to handle messages through the `binaryMessenger`. static func setUp(binaryMessenger: FlutterBinaryMessenger, api: SensorApi?) { /// 获取当前位置,[force]为 false 时, /// 优先使用 lastPosition,为 true 强制重新获取当前位置。 let getCurrentPositionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.getCurrentPosition", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getCurrentPositionChannel.setMessageHandler { message, reply in let args = message as! [Any] let forceArg = args[0] as! Bool api.getCurrentPosition(force: forceArg) { result in switch result { case .success(let res): reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } } } } else { getCurrentPositionChannel.setMessageHandler(nil) } let locationStartChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.locationStart", binaryMessenger: binaryMessenger, codec: codec) if let api = api { locationStartChannel.setMessageHandler { message, reply in let args = message as! [Any] let minTimeMsArg = (args[0] is Int) ? Int64(args[0] as! Int) : args[0] as! Int64 let minDistanceMArg = args[1] as! Double do { try api.locationStart(minTimeMs: minTimeMsArg, minDistanceM: minDistanceMArg) reply(wrapResult(nil)) } catch { reply(wrapError(error)) } } } else { locationStartChannel.setMessageHandler(nil) } let locationStopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.locationStop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { locationStopChannel.setMessageHandler { _, reply in do { try api.locationStop() reply(wrapResult(nil)) } catch { reply(wrapError(error)) } } } else { locationStopChannel.setMessageHandler(nil) } let sportWearScanStartChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.sportWearScanStart", binaryMessenger: binaryMessenger, codec: codec) if let api = api { sportWearScanStartChannel.setMessageHandler { _, reply in do { try api.sportWearScanStart() reply(wrapResult(nil)) } catch { reply(wrapError(error)) } } } else { sportWearScanStartChannel.setMessageHandler(nil) } let sportWearScanStopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.sportWearScanStop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { sportWearScanStopChannel.setMessageHandler { _, reply in do { try api.sportWearScanStop() reply(wrapResult(nil)) } catch { reply(wrapError(error)) } } } else { sportWearScanStopChannel.setMessageHandler(nil) } let askEnableBluetoothChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.askEnableBluetooth", binaryMessenger: binaryMessenger, codec: codec) if let api = api { askEnableBluetoothChannel.setMessageHandler { _, reply in api.askEnableBluetooth() { result in switch result { case .success(let res): reply(wrapResult(res)) case .failure(let error): reply(wrapError(error)) } } } } else { askEnableBluetoothChannel.setMessageHandler(nil) } let sportWearConnectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.sportWearConnect", binaryMessenger: binaryMessenger, codec: codec) if let api = api { sportWearConnectChannel.setMessageHandler { message, reply in let args = message as! [Any] let wearArg = args[0] as! SportWear api.sportWearConnect(wear: wearArg) { result in switch result { case .success: reply(wrapResult(nil)) case .failure(let error): reply(wrapError(error)) } } } } else { sportWearConnectChannel.setMessageHandler(nil) } let sportWearDisconnectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.sportWearDisconnect", binaryMessenger: binaryMessenger, codec: codec) if let api = api { sportWearDisconnectChannel.setMessageHandler { message, reply in let args = message as! [Any] let wearArg = args[0] as! SportWear api.sportWearDisconnect(wear: wearArg) { result in switch result { case .success: reply(wrapResult(nil)) case .failure(let error): reply(wrapError(error)) } } } } else { sportWearDisconnectChannel.setMessageHandler(nil) } /// 是否开启位置服务 let isLocationServiceOpenChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.isLocationServiceOpen", binaryMessenger: binaryMessenger, codec: codec) if let api = api { isLocationServiceOpenChannel.setMessageHandler { _, reply in do { let result = try api.isLocationServiceOpen() reply(wrapResult(result)) } catch { reply(wrapError(error)) } } } else { isLocationServiceOpenChannel.setMessageHandler(nil) } let getYDPIChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.getYDPI", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getYDPIChannel.setMessageHandler { _, reply in do { let result = try api.getYDPI() reply(wrapResult(result)) } catch { reply(wrapError(error)) } } } else { getYDPIChannel.setMessageHandler(nil) } let getXDPIChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.getXDPI", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getXDPIChannel.setMessageHandler { _, reply in do { let result = try api.getXDPI() reply(wrapResult(result)) } catch { reply(wrapError(error)) } } } else { getXDPIChannel.setMessageHandler(nil) } /// 只需要空实现即可,class必须有函数引用才会生成代码 let toGenAllClassChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.toGenAllClass", binaryMessenger: binaryMessenger, codec: codec) if let api = api { toGenAllClassChannel.setMessageHandler { message, reply in let args = message as! [Any] let orientationArg = args[0] as! Orientation let hrmArg = args[1] as! HeartRateMeasurement let positionArg = args[2] as! Position do { try api.toGenAllClass(orientation: orientationArg, hrm: hrmArg, position: positionArg) reply(wrapResult(nil)) } catch { reply(wrapError(error)) } } } else { toGenAllClassChannel.setMessageHandler(nil) } } }