1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import IceObjc
import PromiseKit
public extension Connection {
func flushBatchRequestsAsync(_ compress: CompressBatch,
sentOn: DispatchQueue? = PromiseKit.conf.Q.return,
sentFlags: DispatchWorkItemFlags? = nil,
sent: ((Bool) -> Void)? = nil) -> Promise<Void> {
let impl = self as! ConnectionI
let sentCB = createSentCallback(sentOn: sentOn, sentFlags: sentFlags, sent: sent)
return Promise<Void> { seal in
impl.handle.flushBatchRequestsAsync(compress.rawValue,
exception: { error in seal.reject(error) },
sent: {
seal.fulfill(())
if let sentCB = sentCB {
sentCB($0)
}
})
}
}
func heartbeatAsync(sentOn: DispatchQueue? = PromiseKit.conf.Q.return,
sentFlags: DispatchWorkItemFlags? = nil,
sent: ((Bool) -> Void)? = nil) -> Promise<Void> {
let impl = self as! ConnectionI
return Promise<Void> { seal in
impl.handle.heartbeatAsync(exception: { error in seal.reject(error) },
sent: createSentCallback(sentOn: sentOn,
sentFlags: sentFlags,
sent: sent))
}
}
// CustomStringConvertible implementation
var description: String {
return toString()
}
}
class ConnectionI: LocalObject<ICEConnection>, Connection {
func close(_ mode: ConnectionClose) {
handle.close(mode.rawValue)
}
func createProxy(_ id: Identity) throws -> ObjectPrx {
precondition(!id.name.isEmpty, "Identity cannot have an empty name")
return try autoreleasepool {
let handle = try self.handle.createProxy(id.name, category: id.category)
let communicator = handle.ice_getCommunicator().getCachedSwiftObject(CommunicatorI.self)
return ObjectPrxI(handle: handle, communicator: communicator)
}
}
func setAdapter(_ oa: ObjectAdapter?) throws {
try autoreleasepool {
try handle.setAdapter((oa as? ObjectAdapterI)?.handle)
}
}
func getAdapter() -> ObjectAdapter? {
guard let handle = handle.getAdapter() else {
return nil
}
return handle.getCachedSwiftObject(ObjectAdapterI.self)
}
func getEndpoint() -> Endpoint {
let handle = self.handle.getEndpoint()
return handle.getSwiftObject(EndpointI.self) {
EndpointI(handle: handle)
}
}
func flushBatchRequests(_ compress: CompressBatch) throws {
return try autoreleasepool {
try handle.flushBatchRequests(compress.rawValue)
}
}
func setCloseCallback(_ callback: CloseCallback?) throws {
return try autoreleasepool {
guard let cb = callback else {
try handle.setCloseCallback(nil)
return
}
try handle.setCloseCallback { c in
precondition(c.getCachedSwiftObject(ConnectionI.self) === self)
cb(self)
}
}
}
func setHeartbeatCallback(_ callback: HeartbeatCallback?) {
guard let cb = callback else {
handle.setHeartbeatCallback(nil)
return
}
handle.setHeartbeatCallback { c in
precondition(c.getCachedSwiftObject(ConnectionI.self) === self)
cb(self)
}
}
func heartbeat() throws {
return try autoreleasepool {
try handle.heartbeat()
}
}
func setACM(timeout: Int32?, close: ACMClose?, heartbeat: ACMHeartbeat?) {
precondition(timeout ?? 0 >= 0, "Invalid negative ACM timeout value")
handle.setACM(timeout as NSNumber?,
close: close != nil ? close.unsafelyUnwrapped.rawValue as NSNumber : nil,
heartbeat: heartbeat != nil ? heartbeat.unsafelyUnwrapped.rawValue as NSNumber : nil)
}
func getACM() -> ACM {
var timeout = Int32()
var close = UInt8()
var heartbeat = UInt8()
handle.getACM(&timeout, close: &close, heartbeat: &heartbeat)
return ACM(timeout: timeout, close: ACMClose(rawValue: close)!, heartbeat: ACMHeartbeat(rawValue: heartbeat)!)
}
func type() -> String {
return handle.type()
}
func timeout() -> Int32 {
return handle.timeout()
}
func toString() -> String {
return handle.toString()
}
func getInfo() throws -> ConnectionInfo {
// swiftlint:disable force_cast
return try handle.getInfo() as! ConnectionInfo
}
func setBufferSize(rcvSize: Int32, sndSize: Int32) throws {
return try autoreleasepool {
try handle.setBufferSize(rcvSize, sndSize: sndSize)
}
}
func throwException() throws {
return try autoreleasepool {
try handle.throwException()
}
}
}
|