diff options
author | Joe George <joe@zeroc.com> | 2019-03-19 17:14:21 -0400 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2019-03-19 17:14:21 -0400 |
commit | 36f218d195429160d334c01ad3e2e9d0fd9a357c (patch) | |
tree | 220ce8745c2fefb710cb85d6ae9ed87aa8bac06b /swift/src | |
parent | Logger simplifications (diff) | |
download | ice-36f218d195429160d334c01ad3e2e9d0fd9a357c.tar.bz2 ice-36f218d195429160d334c01ad3e2e9d0fd9a357c.tar.xz ice-36f218d195429160d334c01ad3e2e9d0fd9a357c.zip |
Add async-oneway
Diffstat (limited to 'swift/src')
-rw-r--r-- | swift/src/Ice/CommunicatorI.swift | 19 | ||||
-rw-r--r-- | swift/src/Ice/ConnectionI.swift | 23 | ||||
-rw-r--r-- | swift/src/Ice/Proxy.swift | 46 | ||||
-rw-r--r-- | swift/src/Ice/Util.swift | 17 | ||||
-rw-r--r-- | swift/src/IceObjc/Communicator.mm | 28 | ||||
-rw-r--r-- | swift/src/IceObjc/Connection.mm | 54 | ||||
-rw-r--r-- | swift/src/IceObjc/IceObjcCommunicator.h | 4 | ||||
-rw-r--r-- | swift/src/IceObjc/IceObjcConnection.h | 7 |
8 files changed, 158 insertions, 40 deletions
diff --git a/swift/src/Ice/CommunicatorI.swift b/swift/src/Ice/CommunicatorI.swift index 8aa32f282e0..c3a2bd8cdd0 100644 --- a/swift/src/Ice/CommunicatorI.swift +++ b/swift/src/Ice/CommunicatorI.swift @@ -8,15 +8,14 @@ // ********************************************************************** import IceObjc +import PromiseKit class CommunicatorI: LocalObject<ICECommunicator>, Communicator { - let properties: Properties let logger: Logger let valueFactoryManager: ValueFactoryManager = ValueFactoryManagerI() let defaultsAndOverrides: DefaultsAndOverrides - init(handle: ICECommunicator, properties: Properties, logger: Logger) { self.properties = properties self.logger = logger @@ -131,7 +130,21 @@ class CommunicatorI: LocalObject<ICECommunicator>, Communicator { } func flushBatchRequests(_ compress: CompressBatch) throws { - try _handle.flushBatchRequests(compress.rawValue) + try autoreleasepool { + try _handle.flushBatchRequests(compress.rawValue) + } + } + + func flushBatchRequestsAsync(_ compress: CompressBatch, + sent: ((Bool) -> Void)? = nil, + sentOn: DispatchQueue? = PromiseKit.conf.Q.return) -> Promise<Void> { + return Promise<Void> { seal in + try autoreleasepool { + try _handle.flushBatchRequestsAsync(compress.rawValue, + exception: { seal.reject($0) }, + sent: createSentCallback(sent: sent, sentOn: sentOn)) + } + } } func createAdmin(adminAdapter _: ObjectAdapter, adminId _: Identity) throws -> ObjectPrx { diff --git a/swift/src/Ice/ConnectionI.swift b/swift/src/Ice/ConnectionI.swift index d47f92822aa..87d339ebaa9 100644 --- a/swift/src/Ice/ConnectionI.swift +++ b/swift/src/Ice/ConnectionI.swift @@ -8,6 +8,7 @@ // ********************************************************************** import IceObjc +import PromiseKit class ConnectionI: LocalObject<ICEConnection>, Connection { public var description: String { @@ -50,6 +51,18 @@ class ConnectionI: LocalObject<ICEConnection>, Connection { } } + public func flushBatchRequestsAsync(_ compress: CompressBatch, + sent: ((Bool) -> Void)? = nil, + sentOn: DispatchQueue? = PromiseKit.conf.Q.return) -> Promise<Void> { + return Promise<Void> { seal in + try autoreleasepool { + try _handle.flushBatchRequestsAsync(compress.rawValue, + exception: {error in seal.reject(error)}, + sent: createSentCallback(sent: sent, sentOn: sentOn)) + } + } + } + public func setCloseCallback(_ callback: CloseCallback?) throws { return try autoreleasepool { guard let cb = callback else { @@ -83,6 +96,16 @@ class ConnectionI: LocalObject<ICEConnection>, Connection { } } + func heartbeatAsync(sent: ((Bool) -> Void)? = nil, + sentOn: DispatchQueue? = PromiseKit.conf.Q.return) -> Promise<Void> { + return Promise<Void> { seal in + try autoreleasepool { + try _handle.heartbeatAsync(exception: {error in seal.reject(error)}, + sent: createSentCallback(sent: sent, sentOn: sentOn)) + } + } + } + public func setACM(timeout: Int32?, close: ACMClose?, heartbeat: ACMHeartbeat?) throws { return try autoreleasepool { try _handle.setACM(timeout as Any, close: close as Any, heartbeat: heartbeat as Any) diff --git a/swift/src/Ice/Proxy.swift b/swift/src/Ice/Proxy.swift index 4611fa265da..fa53a2a312e 100644 --- a/swift/src/Ice/Proxy.swift +++ b/swift/src/Ice/Proxy.swift @@ -665,7 +665,7 @@ open class _ObjectPrxI: ObjectPrx { hasOutParams: Bool, exceptions: [UserException.Type] = [], context: Context? = nil, - sent sendCallback: ((Bool) -> Void)? = nil, + sent: ((Bool) -> Void)? = nil, sentOn: DispatchQueue? = PromiseKit.conf.Q.map, unmarshalResult: @escaping ((InputStream) throws -> T)) -> Promise<T> { @@ -694,42 +694,14 @@ open class _ObjectPrxI: ObjectPrx { } } - // - // Exception callback - // - func exception(error: Error) { - seal.reject(error) - } - - // - // Sent callback (optional) - // - var sent: ((Bool) -> Void)? - - if let s = sendCallback { - sent = { (sentSynchronously: Bool) -> Void in - // - // Use PromiseKit's map queue if not nil, otherwise use call with the current thread - // - if let queue = PromiseKit.conf.Q.map { - queue.async { - s(sentSynchronously) - } - } - s(sentSynchronously) - } - } - - do { - try autoreleasepool { - try handle.iceInvokeAsync(op, mode: Int(mode.rawValue), - inParams: inParams?.getBytes(), - inSize: inParams?.getCount() ?? 0, - context: context, - response: response, exception: exception, sent: sent) - } - } catch let error { - seal.reject(error) + try autoreleasepool { + try handle.iceInvokeAsync(op, mode: Int(mode.rawValue), + inParams: inParams?.getBytes(), + inSize: inParams?.getCount() ?? 0, + context: context, + response: response, + exception: { error in seal.reject(error) }, + sent: createSentCallback(sent: sent, sentOn: sentOn)) } } } diff --git a/swift/src/Ice/Util.swift b/swift/src/Ice/Util.swift index 9527c3efbd6..2707abbe013 100644 --- a/swift/src/Ice/Util.swift +++ b/swift/src/Ice/Util.swift @@ -7,6 +7,8 @@ // // ********************************************************************** +import Dispatch + func stringToEncodingVersion(_ s: String) throws -> EncodingVersion { let (major, minor) = try stringToMajorMinor(s) return EncodingVersion(major: major, minor: minor) @@ -24,3 +26,18 @@ func stringToMajorMinor(_ s: String) throws -> (UInt8, UInt8) { return (major, minor) } + +func createSentCallback(sent: ((Bool) -> Void)? = nil, sentOn: DispatchQueue?) -> ((Bool) -> Void)? { + var sentCallback: ((Bool) -> Void)? + if let s = sent { + sentCallback = { (sentSynchronously: Bool) -> Void in + if let queue = sentOn { + queue.async { + s(sentSynchronously) + } + } + s(sentSynchronously) + } + } + return sentCallback +} diff --git a/swift/src/IceObjc/Communicator.mm b/swift/src/IceObjc/Communicator.mm index 2daeb182844..35045e5a061 100644 --- a/swift/src/IceObjc/Communicator.mm +++ b/swift/src/IceObjc/Communicator.mm @@ -213,6 +213,34 @@ } } +-(BOOL) flushBatchRequestsAsync:(uint8_t)compress + exception:(void (^)(NSError*))exception + sent:(void (^_Nullable)(bool))sent + error:(NSError**)error +{ + try + { + _communicator->flushBatchRequestsAsync(Ice::CompressBatch(compress), + [exception](std::exception_ptr e) + { + exception(convertException(e)); + }, + [sent](bool sentSynchronously) + { + if(sent) + { + sent(sentSynchronously); + } + }); + return YES; + } + catch(const std::exception& ex) + { + *error = convertException(ex); + return NO; + } +} + -(ICEProperties*) getProperties { auto props = _communicator->getProperties(); diff --git a/swift/src/IceObjc/Connection.mm b/swift/src/IceObjc/Connection.mm index 43ac90d352b..0e662b6c039 100644 --- a/swift/src/IceObjc/Connection.mm +++ b/swift/src/IceObjc/Connection.mm @@ -76,6 +76,34 @@ } } +-(BOOL) flushBatchRequestsAsync:(uint8_t)compress + exception:(void (^)(NSError*))exception + sent:(void (^_Nullable)(bool))sent + error:(NSError* _Nullable * _Nullable)error +{ + try + { + _connection->flushBatchRequestsAsync(Ice::CompressBatch(compress), + [exception](std::exception_ptr e) + { + exception(convertException(e)); + }, + [sent](bool sentSynchronously) + { + if(sent) + { + sent(sentSynchronously); + } + }); + return YES; + } + catch(const std::exception& ex) + { + *error = convertException(ex); + return NO; + } +} + -(BOOL) setCloseCallback:(void (^)(ICEConnection*))callback error:(NSError**)error { try @@ -142,6 +170,32 @@ } } +-(BOOL) heartbeatAsync:(void (^)(NSError*))exception + sent:(void (^_Nullable)(bool))sent + error:(NSError* _Nullable * _Nullable)error +{ + try + { + _connection->heartbeatAsync([exception](std::exception_ptr e) + { + exception(convertException(e)); + }, + [sent](bool sentSynchronously) + { + if(sent) + { + sent(sentSynchronously); + } + }); + return YES; + } + catch(const std::exception& ex) + { + *error = convertException(ex); + return NO; + } +} + -(BOOL) setACM:(id _Nonnull)timeout close:(id _Nonnull)close heartbeat:(id _Nonnull)heartbeat error:(NSError**)error { try diff --git a/swift/src/IceObjc/IceObjcCommunicator.h b/swift/src/IceObjc/IceObjcCommunicator.h index 6edafdf8d53..605d5860b7d 100644 --- a/swift/src/IceObjc/IceObjcCommunicator.h +++ b/swift/src/IceObjc/IceObjcCommunicator.h @@ -36,6 +36,10 @@ NS_SWIFT_NAME(propertyToProxy(property:)); -(nullable ICEObjectPrx*) getDefaultLocator; -(BOOL) setDefaultLocator:(ICEObjectPrx* _Nullable)locator error:(NSError**)error; -(BOOL) flushBatchRequests:(uint8_t)compress error:(NSError**)error; +-(BOOL) flushBatchRequestsAsync:(uint8_t)compress + exception:(void (^)(NSError*))exception + sent:(void (^_Nullable)(bool))sent + error:(NSError**)error; -(ICEProperties*) getProperties; diff --git a/swift/src/IceObjc/IceObjcConnection.h b/swift/src/IceObjc/IceObjcConnection.h index 575853403e5..2f1cc89e82b 100644 --- a/swift/src/IceObjc/IceObjcConnection.h +++ b/swift/src/IceObjc/IceObjcConnection.h @@ -20,9 +20,16 @@ NS_ASSUME_NONNULL_BEGIN //-(nullable ObjectAdapterI*) getAdapter; -(ICEEndpoint*) getEndpoint; -(BOOL) flushBatchRequests:(uint8_t)compress error:(NSError* _Nullable * _Nullable)error; +-(BOOL) flushBatchRequestsAsync:(uint8_t)compress + exception:(void (^)(NSError*))exception + sent:(void (^_Nullable)(bool))sent + error:(NSError* _Nullable * _Nullable)error; -(BOOL) setCloseCallback:(nullable void (^)(ICEConnection*))callback error:(NSError* _Nullable * _Nullable)error; -(BOOL) setHeartbeatCallback:(nullable void (^)(ICEConnection*))callback error:(NSError* _Nullable * _Nullable)error; -(BOOL) heartbeat:(NSError* _Nullable * _Nullable)error; +-(BOOL) heartbeatAsync:(void (^)(NSError*))exception + sent:(void (^_Nullable)(bool))sent + error:(NSError* _Nullable * _Nullable)error NS_SWIFT_NAME(heartbeatAsync(exception:sent:)); -(BOOL) setACM:(id)timeout close:(id)close heartbeat:(id)heartbeat error:(NSError* _Nullable * _Nullable)error; -(void) getACM:(int32_t*)timeout close:(uint8_t*)close heartbeat:(uint8_t*)heartbeat; -(NSString*) type; |