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
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import IceObjc
class ObjectAdapterI: LocalObject<ICEObjectAdapter>, ObjectAdapter, ICEBlobjectFacade, Hashable {
private let communicator: Communicator
let servantManager: ServantManager
init(handle: ICEObjectAdapter, communicator: Communicator) {
self.communicator = communicator
servantManager = ServantManager(adapterName: handle.getName(), communicator: communicator)
super.init(handle: handle)
handle.registerDefaultServant(self)
}
func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self).hashValue)
}
static func == (lhs: ObjectAdapterI, rhs: ObjectAdapterI) -> Bool {
return lhs === rhs
}
func getName() -> String {
return handle.getName()
}
func getCommunicator() -> Communicator {
return communicator
}
func activate() throws {
try autoreleasepool {
try handle.activate()
}
}
func hold() {
handle.hold()
}
func waitForHold() {
handle.waitForHold()
}
func deactivate() {
handle.deactivate()
}
func waitForDeactivate() {
handle.waitForDeactivate()
}
func isDeactivated() -> Bool {
return handle.isDeactivated()
}
func destroy() {
return handle.destroy()
}
func add(servant: Disp, id: Identity) throws -> ObjectPrx {
return try addFacet(servant: servant, id: id, facet: "")
}
func addFacet(servant: Disp, id: Identity, facet: String) throws -> ObjectPrx {
precondition(!id.name.isEmpty, "Identity cannot have an empty name")
try servantManager.addServant(servant: servant, id: id, facet: facet)
return try createProxy(id).ice_facet(facet)
}
func addWithUUID(_ servant: Disp) throws -> ObjectPrx {
return try addFacetWithUUID(servant: servant, facet: "")
}
func addFacetWithUUID(servant: Disp, facet: String) throws -> ObjectPrx {
return try addFacet(servant: servant, id: Identity(name: UUID().uuidString, category: ""), facet: facet)
}
func addDefaultServant(servant: Disp, category: String) throws {
try servantManager.addDefaultServant(servant: servant, category: category)
}
func remove(_ id: Identity) throws -> Disp {
return try removeFacet(id: id, facet: "")
}
func removeFacet(id: Identity, facet: String) throws -> Disp {
precondition(!id.name.isEmpty, "Identity cannot have an empty name")
return try servantManager.removeServant(id: id, facet: facet)
}
func removeAllFacets(_ id: Identity) throws -> FacetMap {
precondition(!id.name.isEmpty, "Identity cannot have an empty name")
return try servantManager.removeAllFacets(id: id)
}
func removeDefaultServant(_ category: String) throws -> Disp {
return try servantManager.removeDefaultServant(category: category)
}
func find(_ id: Identity) -> Disp? {
return findFacet(id: id, facet: "")
}
func findFacet(id: Identity, facet: String) -> Disp? {
return servantManager.findServant(id: id, facet: facet)
}
func findAllFacets(_ id: Identity) -> FacetMap {
return servantManager.findAllFacets(id: id)
}
func findByProxy(_ proxy: ObjectPrx) -> Disp? {
return findFacet(id: proxy.ice_getIdentity(), facet: proxy.ice_getFacet())
}
func addServantLocator(locator: ServantLocator, category: String) throws {
try servantManager.addServantLocator(locator: locator, category: category)
}
func removeServantLocator(_ category: String) throws -> ServantLocator {
return try servantManager.removeServantLocator(category: category)
}
func findServantLocator(_ category: String) -> ServantLocator? {
return servantManager.findServantLocator(category: category)
}
func findDefaultServant(_ category: String) -> Disp? {
return servantManager.findDefaultServant(category: category)
}
func createProxy(_ id: Identity) throws -> ObjectPrx {
precondition(!id.name.isEmpty, "Identity cannot have an empty name")
return try autoreleasepool {
return try ObjectPrxI(handle: handle.createProxy(name: id.name, category: id.category),
communicator: communicator)
}
}
func createDirectProxy(_ id: Identity) throws -> ObjectPrx {
precondition(!id.name.isEmpty, "Identity cannot have an empty name")
return try autoreleasepool {
return try ObjectPrxI(handle: handle.createDirectProxy(name: id.name, category: id.category),
communicator: communicator)
}
}
func createIndirectProxy(_ id: Identity) throws -> ObjectPrx {
precondition(!id.name.isEmpty, "Identity cannot have an empty name")
return try autoreleasepool {
return try ObjectPrxI(handle: handle.createIndirectProxy(name: id.name, category: id.category),
communicator: communicator)
}
}
func setLocator(_ locator: LocatorPrx?) {
let l = locator as? LocatorPrxI
handle.setLocator(l?.handle ?? nil)
}
func getLocator() -> LocatorPrx? {
guard let locatorHandle = handle.getLocator() else {
return nil
}
return LocatorPrxI.fromICEObjectPrx(handle: locatorHandle)
}
func getEndpoints() -> EndpointSeq {
return handle.getEndpoints().fromObjc()
}
func refreshPublishedEndpoints() throws {
try autoreleasepool {
try handle.refreshPublishedEndpoints()
}
}
func getPublishedEndpoints() -> EndpointSeq {
return handle.getPublishedEndpoints().fromObjc()
}
func setPublishedEndpoints(_ newEndpoints: EndpointSeq) throws {
try autoreleasepool {
try handle.setPublishedEndpoints(newEndpoints.toObjc())
}
}
func getDispatchQueue() throws -> DispatchQueue {
return try autoreleasepool {
try handle.getDispatchQueue()
}
}
func facadeInvoke(_ adapter: ICEObjectAdapter,
inEncaps: Data,
con: ICEConnection?,
name: String,
category: String,
facet: String,
operation: String,
mode: UInt8,
context: [String: String],
requestId: Int32,
encodingMajor: UInt8,
encodingMinor: UInt8,
response: @escaping (Bool, Data) -> Void,
exception: @escaping (ICERuntimeException) -> Void) {
precondition(handle == adapter)
let connection = con?.getSwiftObject(ConnectionI.self) { ConnectionI(handle: con!) } ?? nil
let current = Current(adapter: self,
con: connection,
id: Identity(name: name, category: category),
facet: facet,
operation: operation,
mode: OperationMode(rawValue: mode)!,
ctx: context,
requestId: requestId,
encoding: EncodingVersion(major: encodingMajor, minor: encodingMinor))
let incoming = Incoming(istr: InputStream(communicator: communicator,
encoding: EncodingVersion(major: encodingMajor,
minor: encodingMinor),
bytes: inEncaps),
response: response,
exception: exception,
current: current)
incoming.invoke(servantManager)
}
func facadeRemoved() {
servantManager.destroy()
}
}
|