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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import IceImpl
import PromiseKit
class CommunicatorI: LocalObject<ICECommunicator>, Communicator {
private let valueFactoryManager: ValueFactoryManager = ValueFactoryManagerI()
let defaultsAndOverrides: DefaultsAndOverrides
let initData: InitializationData
let classGraphDepthMax: Int32
let traceSlicing: Bool
let acceptClassCycles: Bool
init(handle: ICECommunicator, initData: InitializationData) {
defaultsAndOverrides = DefaultsAndOverrides(handle: handle)
self.initData = initData
let num = initData.properties!.getPropertyAsIntWithDefault(key: "Ice.ClassGraphDepthMax", value: 50)
if num < 1 || num > 0x7FFF_FFFF {
classGraphDepthMax = 0x7FFF_FFFF
} else {
classGraphDepthMax = num
}
traceSlicing = initData.properties!.getPropertyAsIntWithDefault(key: "Ice.Trace.Slicing", value: 0) > 0
acceptClassCycles = initData.properties!.getPropertyAsIntWithDefault(key: "Ice.AcceptClassCycles", value: 0) > 0
super.init(handle: handle)
}
func destroy() {
handle.destroy()
}
func shutdown() {
handle.shutdown()
}
func waitForShutdown() {
handle.waitForShutdown()
}
func isShutdown() -> Bool {
return handle.isShutdown()
}
func stringToProxy(_ str: String) throws -> ObjectPrx? {
return try autoreleasepool {
guard let prxHandle = try handle.stringToProxy(str: str) as? ICEObjectPrx else {
return nil
}
return ObjectPrxI(handle: prxHandle, communicator: self)
}
}
func proxyToString(_ obj: ObjectPrx?) -> String {
return obj?.ice_toString() ?? ""
}
func propertyToProxy(_ property: String) throws -> ObjectPrx? {
return try autoreleasepool {
guard let handle = try handle.propertyToProxy(property: property) as? ICEObjectPrx else {
return nil
}
return ObjectPrxI(handle: handle, communicator: self)
}
}
func proxyToProperty(proxy: ObjectPrx, property: String) -> PropertyDict {
precondition(!proxy.ice_isFixed(), "Cannot create property for fixed proxy")
do {
return try autoreleasepool {
try handle.proxyToProperty(prx: proxy._impl.handle, property: property)
}
} catch is CommunicatorDestroyedException {
return PropertyDict()
} catch {
fatalError("\(error)")
}
}
func identityToString(_ id: Identity) -> String {
return Ice.identityToString(id: id)
}
func createObjectAdapter(_ name: String) throws -> ObjectAdapter {
return try autoreleasepool {
let handle = try self.handle.createObjectAdapter(name)
return ObjectAdapterI(handle: handle, communicator: self)
}
}
func createObjectAdapterWithEndpoints(name: String, endpoints: String) throws -> ObjectAdapter {
return try autoreleasepool {
let handle = try self.handle.createObjectAdapterWithEndpoints(name: name, endpoints: endpoints)
return ObjectAdapterI(handle: handle, communicator: self)
}
}
func createObjectAdapterWithRouter(name: String, rtr: RouterPrx) throws -> ObjectAdapter {
return try autoreleasepool {
let handle = try self.handle.createObjectAdapterWithRouter(name: name, router: rtr._impl.handle)
return ObjectAdapterI(handle: handle, communicator: self)
}
}
func getImplicitContext() -> ImplicitContext {
let handle = self.handle.getImplicitContext()
return handle.getSwiftObject(ImplicitContextI.self) {
ImplicitContextI(handle: handle)
}
}
func getProperties() -> Properties {
return initData.properties!
}
func getLogger() -> Logger {
return initData.logger!
}
func getDefaultRouter() -> RouterPrx? {
guard let handle = handle.getDefaultRouter() else {
return nil
}
return RouterPrxI.fromICEObjectPrx(handle: handle, communicator: self)
}
func setDefaultRouter(_ rtr: RouterPrx?) {
do {
try autoreleasepool {
try handle.setDefaultRouter((rtr as? ObjectPrxI)?.handle)
}
} catch is CommunicatorDestroyedException {
// Ignored
} catch {
fatalError("\(error)")
}
}
func getDefaultLocator() -> LocatorPrx? {
guard let handle = handle.getDefaultLocator() else {
return nil
}
return LocatorPrxI.fromICEObjectPrx(handle: handle, communicator: self)
}
func setDefaultLocator(_ loc: LocatorPrx?) {
do {
try autoreleasepool {
try handle.setDefaultLocator((loc as? ObjectPrxI)?.handle)
}
} catch is CommunicatorDestroyedException {
// Ignored
} catch {
fatalError("\(error)")
}
}
func getValueFactoryManager() -> ValueFactoryManager {
return valueFactoryManager
}
func flushBatchRequests(_ compress: CompressBatch) throws {
try autoreleasepool {
try handle.flushBatchRequests(compress.rawValue)
}
}
func createAdmin(adminAdapter: ObjectAdapter?, adminId: Identity) throws -> ObjectPrx {
return try autoreleasepool {
let handle = try self.handle.createAdmin((adminAdapter as? ObjectAdapterI)?.handle,
name: adminId.name,
category: adminId.category)
if let adapter = adminAdapter {
// Register the admin OA's id with the servant manager. This is used to distingish between
// ObjectNotExistException and FacetNotExistException when a servant is not found on
// a Swift Admin OA.
(adapter as! ObjectAdapterI).servantManager.setAdminId(adminId)
}
return ObjectPrxI(handle: handle, communicator: self)
}
}
func getAdmin() throws -> ObjectPrx? {
return try autoreleasepool {
guard let handle = try handle.getAdmin() as? ICEObjectPrx else {
return nil
}
return ObjectPrxI(handle: handle, communicator: self)
}
}
func addAdminFacet(servant disp: Disp, facet: String) throws {
try autoreleasepool {
try handle.addAdminFacet(AdminFacetFacade(communicator: self, disp: disp), facet: facet)
}
}
func removeAdminFacet(_ facet: String) throws -> Disp {
return try autoreleasepool {
guard let facade = try handle.removeAdminFacet(facet) as? AdminFacetFacade else {
preconditionFailure()
}
return facade.disp
}
}
func findAdminFacet(_ facet: String) -> Disp? {
do {
return try autoreleasepool {
guard let facade = try handle.findAdminFacet(facet) as? AdminFacetFacade else {
return nil
}
return facade.disp
}
} catch is CommunicatorDestroyedException {
// Ignored
return nil
} catch {
fatalError("\(error)")
}
}
func findAllAdminFacets() -> FacetMap {
do {
return try autoreleasepool {
try handle.findAllAdminFacets().mapValues { facade in
(facade as! AdminFacetFacade).disp
}
}
} catch is CommunicatorDestroyedException {
// Ignored
return FacetMap()
} catch {
fatalError("\(error)")
}
}
func getClientDispatchQueue() throws -> DispatchQueue {
return try autoreleasepool {
try handle.getClientDispatchQueue()
}
}
func getServerDispatchQueue() throws -> DispatchQueue {
return try autoreleasepool {
try handle.getServerDispatchQueue()
}
}
}
public extension Communicator {
func flushBatchRequestsAsync(_ compress: CompressBatch,
sentOn: DispatchQueue? = nil,
sentFlags: DispatchWorkItemFlags? = nil,
sent: ((Bool) -> Void)? = nil) -> Promise<Void> {
let impl = self as! CommunicatorI
let sentCB = createSentCallback(sentOn: sentOn, sentFlags: sentFlags, sent: sent)
return Promise<Void> { seal in
impl.handle.flushBatchRequestsAsync(compress.rawValue,
exception: { seal.reject($0) },
sent: {
seal.fulfill(())
if let sentCB = sentCB {
sentCB($0)
}
})
}
}
/// Establish the password prompt object. This must be done before
/// the IceSSL plug-in is initialized.
///
/// - parameter prompt: `(() -> String)` - The password prompt.
func setSslPasswordPrompt(prompt: @escaping (() -> String)) {
(self as! CommunicatorI).handle.setSslPasswordPrompt(prompt)
}
/// Establish the certificate verifier objet. This must be done before
/// any connection are established.
///
/// - parameter prompt: `((SSLConnectionInfo) -> Bool)` The certificate verifier.
func setSslCertificateVerifier(verifier: @escaping ((SSLConnectionInfo) -> Bool)) {
(self as! CommunicatorI).handle.setSslCertificateVerifier { info in
verifier(info as! SSLConnectionInfo)
}
}
/// Initialize the configured plug-ins. The communicator automatically initializes
/// the plug-ins by default, but an application may need to interact directly with
/// a plug-in prior to initialization. In this case, the application must set
/// `Ice.InitPlugins=0` and then invoke `initializePlugins` manually. The plug-ins are
/// initialized in the order in which they are loaded. If a plug-in raises an exception
/// during initialization, the communicator invokes destroy on the plug-ins that have
/// already been initialized.
///
/// - throws: `InitializationException` Raised if the plug-ins have already been
/// initialized.
func initializePlugins() throws {
try autoreleasepool {
try (self as! CommunicatorI).handle.initializePlugins()
}
}
}
struct DefaultsAndOverrides {
init(handle: ICECommunicator) {
var defaultEncoding = EncodingVersion()
handle.getDefaultEncoding(major: &defaultEncoding.major, minor: &defaultEncoding.minor)
self.defaultEncoding = defaultEncoding
defaultFormat = FormatType(rawValue: handle.getDefaultFormat())!
}
let defaultEncoding: EncodingVersion
let defaultFormat: FormatType
}
|