From 8e47f37a02f57d5cce17791ecfa562f678a9ab26 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Tue, 26 Nov 2024 12:02:35 -0500 Subject: [PATCH 1/2] Refactor EndpointInfo in Swift --- swift/src/Ice/CommunicatorI.swift | 6 +- swift/src/Ice/Endpoint.swift | 144 ++++++++++++++++++------ swift/src/Ice/EndpointI.swift | 138 ----------------------- swift/src/Ice/EndpointInfoFactory.swift | 115 +++++++------------ swift/src/Ice/IAPEndpointInfo.swift | 34 +++++- swift/src/Ice/PropertiesI.swift | 2 +- swift/src/Ice/SSLEndpointInfo.swift | 3 +- swift/src/IceImpl/Endpoint.mm | 103 ++++++----------- swift/src/IceImpl/include/Endpoint.h | 60 +++------- 9 files changed, 237 insertions(+), 368 deletions(-) diff --git a/swift/src/Ice/CommunicatorI.swift b/swift/src/Ice/CommunicatorI.swift index bcf6209d647..fc022deae46 100644 --- a/swift/src/Ice/CommunicatorI.swift +++ b/swift/src/Ice/CommunicatorI.swift @@ -15,10 +15,12 @@ class CommunicatorI: LocalObject, Communicator { self.initData = initData do { classGraphDepthMax = try initData.properties!.getIcePropertyAsInt("Ice.ClassGraphDepthMax") - precondition(classGraphDepthMax >= 1 && classGraphDepthMax <= 0x7FFF_FFFF, "Ice.ClassGraphDepthMax must be >= 0 and <= 0x7FFF_FFFF") + precondition( + classGraphDepthMax >= 1 && classGraphDepthMax <= 0x7FFF_FFFF, + "Ice.ClassGraphDepthMax must be >= 0 and <= 0x7FFF_FFFF") traceSlicing = try initData.properties!.getIcePropertyAsInt("Ice.Trace.Slicing") > 0 acceptClassCycles = try initData.properties!.getIcePropertyAsInt("Ice.AcceptClassCycles") > 0 - } catch { + } catch { fatalError("\(error)") } diff --git a/swift/src/Ice/Endpoint.swift b/swift/src/Ice/Endpoint.swift index b7a400d77d1..ecc24d214b4 100644 --- a/swift/src/Ice/Endpoint.swift +++ b/swift/src/Ice/Endpoint.swift @@ -2,77 +2,155 @@ import Foundation +/// The user-level interface to an endpoint. +public protocol Endpoint: AnyObject, CustomStringConvertible { + /// Return a string representation of the endpoint. + /// + /// - returns: `String` - The string representation of the endpoint. + func toString() -> String + + /// Returns the endpoint information. + /// + /// - returns: `EndpointInfo?` - The endpoint information class. + func getInfo() -> EndpointInfo? +} + +public typealias EndpointSeq = [Endpoint] + /// Base class providing access to the endpoint details. -public protocol EndpointInfo: AnyObject { +open class EndpointInfo { /// The information of the underlying endpoint or null if there's no underlying endpoint. - var underlying: EndpointInfo? { get set } + public let underlying: EndpointInfo? /// The timeout for the endpoint in milliseconds. 0 means non-blocking, -1 means no timeout. - var timeout: Int32 { get set } + public let timeout: Int32 /// Specifies whether or not compression should be used if available when using this endpoint. - var compress: Bool { get set } + public let compress: Bool /// Returns the type of the endpoint. /// /// - returns: `Int16` - The endpoint type. - func type() -> Int16 + public func type() -> Int16 { + underlying?.type() ?? -1 + } /// Returns true if this endpoint is a datagram endpoint. /// /// - returns: `Bool` - True for a datagram endpoint. - func datagram() -> Bool + public func datagram() -> Bool { + underlying?.datagram() ?? false + } /// Returns true if this endpoint is a secure endpoint. /// /// - returns: `Bool` - True for a secure endpoint. - func secure() -> Bool -} + public func secure() -> Bool { + underlying?.secure() ?? false + } -/// The user-level interface to an endpoint. -public protocol Endpoint: AnyObject, CustomStringConvertible { - /// Return a string representation of the endpoint. - /// - /// - returns: `String` - The string representation of the endpoint. - func toString() -> String + public init(underlying: EndpointInfo) { + self.underlying = underlying + self.timeout = underlying.timeout + self.compress = underlying.compress + } - /// Returns the endpoint information. - /// - /// - returns: `EndpointInfo?` - The endpoint information class. - func getInfo() -> EndpointInfo? + public init(timeout: Int32, compress: Bool) { + self.underlying = nil + self.timeout = timeout + self.compress = compress + } } /// Provides access to the address details of a IP endpoint. -public protocol IPEndpointInfo: EndpointInfo { +open class IPEndpointInfo: EndpointInfo { /// The host or address configured with the endpoint. - var host: String { get set } + public let host: String /// The port number. - var port: Int32 { get set } + public let port: Int32 /// The source IP address. - var sourceAddress: String { get set } + public let sourceAddress: String + + public init(timeout: Int32, compress: Bool, host: String, port: Int32, sourceAddress: String) { + self.host = host + self.port = port + self.sourceAddress = sourceAddress + super.init(timeout: timeout, compress: compress) + } } /// Provides access to a TCP endpoint information. -public protocol TCPEndpointInfo: IPEndpointInfo {} +public final class TCPEndpointInfo: IPEndpointInfo { + private let _type: Int16 + private let _secure: Bool + + public override func type() -> Int16 { + _type + } + + public override func secure() -> Bool { + _secure + } + + internal init( + timeout: Int32, compress: Bool, host: String, port: Int32, sourceAddress: String, type: Int16, secure: Bool + ) { + self._type = type + self._secure = secure + super.init(timeout: timeout, compress: compress, host: host, port: port, sourceAddress: sourceAddress) + } +} /// Provides access to an UDP endpoint information. -public protocol UDPEndpointInfo: IPEndpointInfo { +public final class UDPEndpointInfo: IPEndpointInfo { /// The multicast interface. - var mcastInterface: String { get set } + public let mcastInterface: String /// The multicast time-to-live (or hops). - var mcastTtl: Int32 { get set } + public let mcastTtl: Int32 + + public override func type() -> Int16 { + UDPEndpointType + } + + public override func datagram() -> Bool { + true + } + + internal init( + compress: Bool, host: String, port: Int32, sourceAddress: String, mcastInterface: String, mcastTtl: Int32 + ) { + self.mcastInterface = mcastInterface + self.mcastTtl = mcastTtl + super.init(timeout: -1, compress: compress, host: host, port: port, sourceAddress: sourceAddress) + } } /// Provides access to a WebSocket endpoint information. -public protocol WSEndpointInfo: EndpointInfo { +public final class WSEndpointInfo: EndpointInfo { /// The URI configured with the endpoint. - var resource: String { get set } + public let resource: String + + internal init(underlying: EndpointInfo, resource: String) { + self.resource = resource + super.init(underlying: underlying) + } } /// Provides access to the details of an opaque endpoint. -public protocol OpaqueEndpointInfo: EndpointInfo { +public final class OpaqueEndpointInfo: EndpointInfo { /// The encoding version of the opaque endpoint (to decode or encode the rawBytes). - var rawEncoding: EncodingVersion { get set } + public let rawEncoding: EncodingVersion /// The raw encoding of the opaque endpoint. - var rawBytes: ByteSeq { get set } -} + public let rawBytes: ByteSeq -public typealias EndpointSeq = [Endpoint] + private let _type: Int16 + + public override func type() -> Int16 { + _type + } + + internal init(type: Int16, rawEncoding: EncodingVersion, rawBytes: ByteSeq) { + self.rawEncoding = rawEncoding + self.rawBytes = rawBytes + self._type = type + super.init(timeout: -1, compress: false) + } +} diff --git a/swift/src/Ice/EndpointI.swift b/swift/src/Ice/EndpointI.swift index 56c3a3af2f4..cb49c9567f8 100644 --- a/swift/src/Ice/EndpointI.swift +++ b/swift/src/Ice/EndpointI.swift @@ -35,144 +35,6 @@ public func == (lhs: Endpoint?, rhs: Endpoint?) -> Bool { } } -// We implement EndpointInfo as a LocalObject that delegates to an ObjC/C++ object. -// The alternative - delegating to the Endpoint object - is not practical since the public API -// of Endpoint in C++ does not expose type, datagram or secure. -class EndpointInfoI: LocalObject, EndpointInfo { - var underlying: EndpointInfo? - var timeout: Int32 - var compress: Bool - - init(handle: ICEEndpointInfo, underlying: EndpointInfo?, timeout: Int32, compress: Bool) { - self.underlying = underlying - self.timeout = timeout - self.compress = compress - super.init(handle: handle) - } - - func type() -> Int16 { - return handle.getType() - } - - func datagram() -> Bool { - return handle.getDatagram() - } - - func secure() -> Bool { - return handle.getSecure() - } -} - -// This class is logically abstract and only derived classes should be created. -class IPEndpointInfoI: EndpointInfoI, IPEndpointInfo { - var host: String - var port: Int32 - var sourceAddress: String - - init( - handle: ICEEndpointInfo, - underlying: EndpointInfo?, - timeout: Int32, - compress: Bool, - host: String, - port: Int32, - sourceAddress: String - ) { - self.host = host - self.port = port - self.sourceAddress = sourceAddress - super.init(handle: handle, underlying: underlying, timeout: timeout, compress: compress) - } -} - -class TCPEndpointInfoI: IPEndpointInfoI, TCPEndpointInfo {} - -class UDPEndpointInfoI: IPEndpointInfoI, UDPEndpointInfo { - var mcastInterface: String - var mcastTtl: Int32 - - init( - handle: ICEEndpointInfo, - underlying: EndpointInfo?, - timeout: Int32, - compress: Bool, - host: String, - port: Int32, - sourceAddress: String, - mcastInterface: String, - mcastTtl: Int32 - ) { - self.mcastInterface = mcastInterface - self.mcastTtl = mcastTtl - super.init( - handle: handle, - underlying: underlying, - timeout: timeout, - compress: compress, - host: host, - port: port, - sourceAddress: sourceAddress) - } -} - -class WSEndpointInfoI: EndpointInfoI, WSEndpointInfo { - var resource: String - - init( - handle: ICEEndpointInfo, underlying: EndpointInfo?, timeout: Int32, compress: Bool, - resource: String - ) { - self.resource = resource - super.init(handle: handle, underlying: underlying, timeout: timeout, compress: compress) - } -} - -class OpaqueEndpointInfoI: EndpointInfoI, OpaqueEndpointInfo { - var rawEncoding: EncodingVersion - var rawBytes: ByteSeq - - init( - handle: ICEEndpointInfo, - underlying: EndpointInfo?, - timeout: Int32, - compress: Bool, - rawEncoding: EncodingVersion, - rawBytes: ByteSeq - ) { - self.rawEncoding = rawEncoding - self.rawBytes = rawBytes - super.init(handle: handle, underlying: underlying, timeout: timeout, compress: compress) - } -} - -// -// IceSSL -// -class SSLEndpointInfoI: EndpointInfoI, SSLEndpointInfo {} - -#if os(iOS) || os(watchOS) || os(tvOS) - - // IceIAP (iOS only) - class IAPEndpointInfoI: EndpointInfoI, IAPEndpointInfo { - var manufacturer: String - var modelNumber: String - var name: String - var `protocol`: String - - init( - handle: ICEEndpointInfo, underlying: EndpointInfo?, timeout: Int32, compress: Bool, - manufacturer: String, modelNumber: String, name: String, protocol: String - ) { - self.manufacturer = manufacturer - self.modelNumber = modelNumber - self.name = name - self.protocol = `protocol` - super.init(handle: handle, underlying: underlying, timeout: timeout, compress: compress) - } - } - -#endif - // // Internal helpers to convert from ObjC to Swift objects // diff --git a/swift/src/Ice/EndpointInfoFactory.swift b/swift/src/Ice/EndpointInfoFactory.swift index 24e6c0c4bfe..45e6248d889 100644 --- a/swift/src/Ice/EndpointInfoFactory.swift +++ b/swift/src/Ice/EndpointInfoFactory.swift @@ -4,39 +4,33 @@ import IceImpl class EndpointInfoFactory: ICEEndpointInfoFactory { static func createTCPEndpointInfo( - _ handle: ICEEndpointInfo, - underlying: Any, - timeout: Int32, + _ timeout: Int32, compress: Bool, host: String, port: Int32, - sourceAddress: String + sourceAddress: String, + type: Int16, + secure: Bool ) -> Any { - return TCPEndpointInfoI( - handle: handle, - underlying: getUnderlying(underlying), + TCPEndpointInfo( timeout: timeout, compress: compress, host: host, port: port, - sourceAddress: sourceAddress) + sourceAddress: sourceAddress, + type: type, + secure: secure) } static func createUDPEndpointInfo( - _ handle: ICEEndpointInfo, - underlying: Any, - timeout: Int32, - compress: Bool, + _ compress: Bool, host: String, port: Int32, sourceAddress: String, mcastInterface: String, mcastTtl: Int32 ) -> Any { - return UDPEndpointInfoI( - handle: handle, - underlying: getUnderlying(underlying), - timeout: timeout, + UDPEndpointInfo( compress: compress, host: host, port: port, @@ -46,77 +40,48 @@ class EndpointInfoFactory: ICEEndpointInfoFactory { } static func createWSEndpointInfo( - _ handle: ICEEndpointInfo, - underlying: Any, - timeout: Int32, - compress: Bool, + _ underlying: Any, resource: String ) -> Any { - return WSEndpointInfoI( - handle: handle, - underlying: getUnderlying(underlying), + WSEndpointInfo( + underlying: underlying as! EndpointInfo, + resource: resource) + } + + static func createSSLEndpointInfo(_ underlying: Any) -> Any { + SSLEndpointInfo(underlying: underlying as! EndpointInfo) + } + + static func createIAPEndpointInfo( + _ timeout: Int32, + compress: Bool, + manufacturer: String, + modelNumber: String, + name: String, + protocol: String, + type: Int16, + secure: Bool + ) -> Any { + IAPEndpointInfo( timeout: timeout, compress: compress, - resource: resource) + manufacturer: manufacturer, + modelNumber: modelNumber, + name: name, + protocol: `protocol`, + type: type, + secure: secure) } static func createOpaqueEndpointInfo( - _ handle: ICEEndpointInfo, - underlying: Any, - timeout: Int32, - compress: Bool, + _ type: Int16, encodingMajor: UInt8, encodingMinor: UInt8, rawBytes: Data ) -> Any { - return OpaqueEndpointInfoI( - handle: handle, - underlying: getUnderlying(underlying), - timeout: timeout, - compress: compress, + OpaqueEndpointInfo( + type: type, rawEncoding: EncodingVersion(major: encodingMajor, minor: encodingMinor), rawBytes: rawBytes) } - - static func createSSLEndpointInfo( - _ handle: ICEEndpointInfo, - underlying: Any, - timeout: Int32, - compress: Bool - ) -> Any { - return SSLEndpointInfoI( - handle: handle, - underlying: getUnderlying(underlying), - timeout: timeout, - compress: compress) - } - - #if os(iOS) || os(watchOS) || os(tvOS) - - static func createIAPEndpointInfo( - _ handle: ICEEndpointInfo, - underlying: Any, - timeout: Int32, - compress: Bool, - manufacturer: String, - modelNumber: String, - name: String, - protocol: String - ) -> Any { - return IAPEndpointInfoI( - handle: handle, - underlying: getUnderlying(underlying), - timeout: timeout, - compress: compress, - manufacturer: manufacturer, - modelNumber: modelNumber, - name: name, - protocol: `protocol`) - } - - #endif - - static func getUnderlying(_ info: Any) -> EndpointInfo? { - return info as? EndpointInfo - } } diff --git a/swift/src/Ice/IAPEndpointInfo.swift b/swift/src/Ice/IAPEndpointInfo.swift index e3f5f1f4a05..2ab594ec229 100644 --- a/swift/src/Ice/IAPEndpointInfo.swift +++ b/swift/src/Ice/IAPEndpointInfo.swift @@ -3,13 +3,37 @@ import Foundation /// Provides access to an IAP endpoint information. -public protocol IAPEndpointInfo: EndpointInfo { +public final class IAPEndpointInfo: EndpointInfo { /// The accessory manufacturer or empty to not match against a manufacturer. - var manufacturer: String { get set } + public let manufacturer: String /// The accessory model number or empty to not match against a model number. - var modelNumber: String { get set } + public let modelNumber: String /// The accessory name or empty to not match against the accessory name. - var name: String { get set } + public let name: String /// The protocol supported by the accessory. - var `protocol`: String { get set } + public let `protocol`: String + + private let _type: Int16 + private let _secure: Bool + + public override func type() -> Int16 { + _type + } + + public override func secure() -> Bool { + _secure + } + + internal init( + timeout: Int32, compress: Bool, manufacturer: String, modelNumber: String, name: String, protocol: String, + type: Int16, secure: Bool + ) { + self.manufacturer = manufacturer + self.modelNumber = modelNumber + self.name = name + self.`protocol` = `protocol` + self._type = type + self._secure = secure + super.init(timeout: timeout, compress: compress) + } } diff --git a/swift/src/Ice/PropertiesI.swift b/swift/src/Ice/PropertiesI.swift index cef232bc2c1..c27af85d6ef 100644 --- a/swift/src/Ice/PropertiesI.swift +++ b/swift/src/Ice/PropertiesI.swift @@ -15,7 +15,7 @@ class PropertiesI: LocalObject, Properties { handle.getPropertyWithDefault(key, value: value) } - public func getPropertyAsInt(_ key: String) throws -> Int32 { + public func getPropertyAsInt(_ key: String) throws -> Int32 { return try autoreleasepool { var value: Int32 = 0 try handle.getPropertyAsInt(key, value: &value) diff --git a/swift/src/Ice/SSLEndpointInfo.swift b/swift/src/Ice/SSLEndpointInfo.swift index 44cccce95ff..91c389a624b 100644 --- a/swift/src/Ice/SSLEndpointInfo.swift +++ b/swift/src/Ice/SSLEndpointInfo.swift @@ -3,4 +3,5 @@ import Foundation /// Provides access to an SSL endpoint information. -public protocol SSLEndpointInfo: EndpointInfo {} +public final class SSLEndpointInfo: EndpointInfo { +} diff --git a/swift/src/IceImpl/Endpoint.mm b/swift/src/IceImpl/Endpoint.mm index b45c264d4fd..b9e481ad344 100644 --- a/swift/src/IceImpl/Endpoint.mm +++ b/swift/src/IceImpl/Endpoint.mm @@ -4,30 +4,6 @@ #import "Convert.h" #import "include/IceUtil.h" -@implementation ICEEndpointInfo - -- (std::shared_ptr)info -{ - return std::static_pointer_cast(self.cppObject); -} - -- (int16_t)getType -{ - return self.info->type(); -} - -- (BOOL)getDatagram -{ - return self.info->datagram(); -} - -- (BOOL)getSecure -{ - return self.info->secure(); -} - -@end - @implementation ICEEndpoint - (std::shared_ptr)endpoint @@ -53,7 +29,6 @@ - (bool)isEqual:(ICEEndpoint*)other + (id)createEndpointInfo:(std::shared_ptr)infoPtr { - ICEEndpointInfo* handle = [ICEEndpointInfo getHandle:infoPtr]; id underlying = infoPtr->underlying ? [self createEndpointInfo:infoPtr->underlying] : [NSNull null]; Class factory = [ICEUtil endpointInfoFactory]; @@ -64,28 +39,27 @@ + (id)createEndpointInfo:(std::shared_ptr)infoPtr // to use type casts instead. // - auto opaqueInfo = std::dynamic_pointer_cast(infoPtr); - if (opaqueInfo) + auto tcpInfo = std::dynamic_pointer_cast(infoPtr); + if (tcpInfo) { - NSData* rawBytes = [[NSData alloc] initWithBytes:opaqueInfo->rawBytes.data() - length:opaqueInfo->rawBytes.size()]; + return [factory createTCPEndpointInfo:tcpInfo->timeout + compress:tcpInfo->compress + host:toNSString(tcpInfo->host) + port:tcpInfo->port + sourceAddress:toNSString(tcpInfo->sourceAddress) + type:tcpInfo->type() + secure:tcpInfo->secure()]; + } - return [factory createOpaqueEndpointInfo:handle - underlying:underlying - timeout:opaqueInfo->timeout - compress:opaqueInfo->compress - encodingMajor:opaqueInfo->rawEncoding.major - encodingMinor:opaqueInfo->rawEncoding.minor - rawBytes:rawBytes]; + if (std::dynamic_pointer_cast(infoPtr)) + { + return [factory createSSLEndpointInfo:underlying]; } auto udpInfo = std::dynamic_pointer_cast(infoPtr); if (udpInfo) { - return [factory createUDPEndpointInfo:handle - underlying:underlying - timeout:udpInfo->timeout - compress:udpInfo->compress + return [factory createUDPEndpointInfo:udpInfo->compress host:toNSString(udpInfo->host) port:udpInfo->port sourceAddress:toNSString(udpInfo->sourceAddress) @@ -93,53 +67,42 @@ + (id)createEndpointInfo:(std::shared_ptr)infoPtr mcastTtl:udpInfo->mcastTtl]; } - auto ipInfo = std::dynamic_pointer_cast(infoPtr); - if (std::dynamic_pointer_cast(infoPtr)) - { - return [factory createTCPEndpointInfo:handle - underlying:underlying - timeout:ipInfo->timeout - compress:ipInfo->compress - host:toNSString(ipInfo->host) - port:ipInfo->port - sourceAddress:toNSString(ipInfo->sourceAddress)]; - } - auto wsInfo = std::dynamic_pointer_cast(infoPtr); if (wsInfo) { - return [factory createWSEndpointInfo:handle - underlying:underlying - timeout:infoPtr->timeout - compress:infoPtr->compress - resource:toNSString(wsInfo->resource)]; + return [factory createWSEndpointInfo:underlying resource:toNSString(wsInfo->resource)]; } - if (std::dynamic_pointer_cast(infoPtr)) - { - return [factory createSSLEndpointInfo:handle - underlying:underlying - timeout:infoPtr->timeout - compress:infoPtr->compress]; - } - -#if TARGET_OS_IPHONE +#if TARGET_OS_IPHONE // TODO: remove conditional auto iapInfo = std::dynamic_pointer_cast(infoPtr); if (iapInfo) { - return [factory createIAPEndpointInfo:handle - underlying:underlying - timeout:iapInfo->timeout + return [factory createIAPEndpointInfo:iapInfo->timeout compress:iapInfo->compress manufacturer:toNSString(iapInfo->manufacturer) modelNumber:toNSString(iapInfo->modelNumber) name:toNSString(iapInfo->name) - protocol:toNSString(iapInfo->protocol)]; + protocol:toNSString(iapInfo->protocol) + type:iapInfo->type() + secure:iapInfo->secure()]; } #endif + auto opaqueInfo = std::dynamic_pointer_cast(infoPtr); + if (opaqueInfo) + { + NSData* rawBytes = [[NSData alloc] initWithBytes:opaqueInfo->rawBytes.data() + length:opaqueInfo->rawBytes.size()]; + + return [factory createOpaqueEndpointInfo:opaqueInfo->type() + encodingMajor:opaqueInfo->rawEncoding.major + encodingMinor:opaqueInfo->rawEncoding.minor + rawBytes:rawBytes]; + } + + // TODO: we should never return null from this factory function. return [NSNull null]; } @end diff --git a/swift/src/IceImpl/include/Endpoint.h b/swift/src/IceImpl/include/Endpoint.h index 2b04e9f0876..dfbecb146a4 100644 --- a/swift/src/IceImpl/include/Endpoint.h +++ b/swift/src/IceImpl/include/Endpoint.h @@ -9,74 +9,48 @@ ICEIMPL_API @interface ICEEndpoint : ICELocalObject - (bool)isEqual:(ICEEndpoint* _Nullable)endpoint; @end -ICEIMPL_API @interface ICEEndpointInfo : ICELocalObject -- (int16_t)getType; -- (BOOL)getDatagram; -- (BOOL)getSecure; -@end +// TODO: revise function signatures to be proper ObjC. ICEIMPL_API @protocol ICEEndpointInfoFactory -+ (id)createTCPEndpointInfo:(ICEEndpointInfo*)handle - underlying:(id)underlying - timeout:(int32_t)timeout ++ (id)createTCPEndpointInfo:(int32_t)timeout compress:(BOOL)compress host:(NSString*)host port:(int32_t)port - sourceAddress:(NSString*)sourceAddress; + sourceAddress:(NSString*)sourceAddress + type:(int16_t)type + secure:(BOOL)secure; -+ (id)createUDPEndpointInfo:(ICEEndpointInfo*)handle - underlying:(id)underlying - timeout:(int32_t)timeout - compress:(BOOL)compress ++ (id)createUDPEndpointInfo:(BOOL)compress host:(NSString*)host port:(int32_t)port sourceAddress:(NSString*)sourceAddress mcastInterface:(NSString*)mcastInterface mcastTtl:(int32_t)mcastTtl; -+ (id)createWSEndpointInfo:(ICEEndpointInfo*)handle - underlying:(id)underlying - timeout:(int32_t)timeout - compress:(BOOL)compress - resource:(NSString*)resource; - -+ (id)createOpaqueEndpointInfo:(ICEEndpointInfo*)handle - underlying:(id)underlying - timeout:(int32_t)timeout - compress:(BOOL)compress - encodingMajor:(UInt8)encodingMajor - encodingMinor:(UInt8)encodingMinor - rawBytes:(NSData*)rawBytes; - -+ (id)createSSLEndpointInfo:(ICEEndpointInfo*)handle - underlying:(id)underlying - timeout:(int32_t)timeout - compress:(BOOL)compress; ++ (id)createWSEndpointInfo:(id)underlying resource:(NSString*)resource; -#if TARGET_OS_IPHONE ++ (id)createSSLEndpointInfo:(id)underlying; -+ (id)createIAPEndpointInfo:(ICEEndpointInfo*)handle - underlying:(id)underlying - timeout:(int32_t)timeout ++ (id)createIAPEndpointInfo:(int32_t)timeout compress:(BOOL)compress manufacturer:(NSString*)manufacturer modelNumber:(NSString*)modelNumber name:(NSString*)name - protocol:(NSString*)protocol; - -#endif + protocol:(NSString*)protocol + type:(int16_t)type + secure:(BOOL)secure; ++ (id)createOpaqueEndpointInfo:(int16_t)type + encodingMajor:(UInt8)encodingMajor + encodingMinor:(UInt8)encodingMinor + rawBytes:(NSData*)rawBytes; @end #ifdef __cplusplus @interface ICEEndpoint () @property(nonatomic, readonly) std::shared_ptr endpoint; -+ (nullable ICEEndpointInfo*)createEndpointInfo:(std::shared_ptr)infoPtr NS_RETURNS_RETAINED; -@end - -@interface ICEEndpointInfo () -@property(nonatomic, readonly) std::shared_ptr info; ++ (id)createEndpointInfo:(std::shared_ptr)infoPtr NS_RETURNS_RETAINED; @end #endif From b6c9823d8a1d2547ab5273a00daf7fec7ce4abc7 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Wed, 27 Nov 2024 09:51:37 -0500 Subject: [PATCH 2/2] Enable IAP endpoint all the time --- swift/src/Ice/Endpoint.swift | 36 ++++++++++++++++++++++++++ swift/src/Ice/IAPEndpointInfo.swift | 39 ----------------------------- swift/src/IceImpl/Endpoint.mm | 6 +---- 3 files changed, 37 insertions(+), 44 deletions(-) delete mode 100644 swift/src/Ice/IAPEndpointInfo.swift diff --git a/swift/src/Ice/Endpoint.swift b/swift/src/Ice/Endpoint.swift index ecc24d214b4..8cf5b9cdeda 100644 --- a/swift/src/Ice/Endpoint.swift +++ b/swift/src/Ice/Endpoint.swift @@ -134,6 +134,42 @@ public final class WSEndpointInfo: EndpointInfo { } } +/// Provides access to an IAP endpoint information. +public final class IAPEndpointInfo: EndpointInfo { + /// The accessory manufacturer or empty to not match against a manufacturer. + public let manufacturer: String + /// The accessory model number or empty to not match against a model number. + public let modelNumber: String + /// The accessory name or empty to not match against the accessory name. + public let name: String + /// The protocol supported by the accessory. + public let `protocol`: String + + private let _type: Int16 + private let _secure: Bool + + public override func type() -> Int16 { + _type + } + + public override func secure() -> Bool { + _secure + } + + internal init( + timeout: Int32, compress: Bool, manufacturer: String, modelNumber: String, name: String, protocol: String, + type: Int16, secure: Bool + ) { + self.manufacturer = manufacturer + self.modelNumber = modelNumber + self.name = name + self.`protocol` = `protocol` + self._type = type + self._secure = secure + super.init(timeout: timeout, compress: compress) + } +} + /// Provides access to the details of an opaque endpoint. public final class OpaqueEndpointInfo: EndpointInfo { /// The encoding version of the opaque endpoint (to decode or encode the rawBytes). diff --git a/swift/src/Ice/IAPEndpointInfo.swift b/swift/src/Ice/IAPEndpointInfo.swift deleted file mode 100644 index 2ab594ec229..00000000000 --- a/swift/src/Ice/IAPEndpointInfo.swift +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -import Foundation - -/// Provides access to an IAP endpoint information. -public final class IAPEndpointInfo: EndpointInfo { - /// The accessory manufacturer or empty to not match against a manufacturer. - public let manufacturer: String - /// The accessory model number or empty to not match against a model number. - public let modelNumber: String - /// The accessory name or empty to not match against the accessory name. - public let name: String - /// The protocol supported by the accessory. - public let `protocol`: String - - private let _type: Int16 - private let _secure: Bool - - public override func type() -> Int16 { - _type - } - - public override func secure() -> Bool { - _secure - } - - internal init( - timeout: Int32, compress: Bool, manufacturer: String, modelNumber: String, name: String, protocol: String, - type: Int16, secure: Bool - ) { - self.manufacturer = manufacturer - self.modelNumber = modelNumber - self.name = name - self.`protocol` = `protocol` - self._type = type - self._secure = secure - super.init(timeout: timeout, compress: compress) - } -} diff --git a/swift/src/IceImpl/Endpoint.mm b/swift/src/IceImpl/Endpoint.mm index b9e481ad344..93d9e08a820 100644 --- a/swift/src/IceImpl/Endpoint.mm +++ b/swift/src/IceImpl/Endpoint.mm @@ -73,9 +73,7 @@ + (id)createEndpointInfo:(std::shared_ptr)infoPtr return [factory createWSEndpointInfo:underlying resource:toNSString(wsInfo->resource)]; } -#if TARGET_OS_IPHONE // TODO: remove conditional - - auto iapInfo = std::dynamic_pointer_cast(infoPtr); + auto iapInfo = std::dynamic_pointer_cast(infoPtr); if (iapInfo) { return [factory createIAPEndpointInfo:iapInfo->timeout @@ -88,8 +86,6 @@ + (id)createEndpointInfo:(std::shared_ptr)infoPtr secure:iapInfo->secure()]; } -#endif - auto opaqueInfo = std::dynamic_pointer_cast(infoPtr); if (opaqueInfo) {