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
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import IceObjc
/// Request is an opaque type that represents an incoming request.
public typealias Request = Incoming
/// A request dispatcher (Disp) is a helper struct used by object adapters to dispatch
/// requests to servants.
public protocol Disp {
/// Dispatch request to servant.
///
/// - parameter request: `Ice.Request` - The incoming request.
///
/// - parameter current: `Ice.Current` - The Current object for the dispatch.
func dispatch(request: Request, current: Current) throws
}
/// A SliceTraits struct describes a Slice interface, class or exception.
public protocol SliceTraits {
/// List of all type-ids.
static var staticIds: [String] { get }
/// Most derived type-id.
static var staticId: String { get }
}
/// The base class for servants.
public protocol Object {
/// Returns the Slice type ID of the most-derived interface supported by this object.
///
/// - parameter current: `Ice.Current` - The Current object for the dispatch.
///
/// - returns: `String` - The Slice type ID of the most-derived interface.
func ice_id(current: Current) throws -> String
/// Returns the Slice type IDs of the interfaces supported by this object.
///
/// - parameter current: `Ice.Current` - The Current object for the dispatch.
///
/// - returns: `[String]` The Slice type IDs of the interfaces supported by this object, in base-to-derived
/// order. The first element of the returned array is always `::Ice::Object`.
func ice_ids(current: Current) throws -> [String]
/// Tests whether this object supports a specific Slice interface.
///
/// - parameter s: `String` - The type ID of the Slice interface to test against.
///
/// - parameter current: `Ice.Current` - The Current object for the dispatch.
///
/// - returns: `Bool` - True if this object has the interface specified by s or
/// derives from the interface specified by s.
func ice_isA(id: String, current: Current) throws -> Bool
/// Tests whether this object can be reached.
///
/// - parameter current: The Current object for the dispatch.
func ice_ping(current: Current) throws
}
public extension Object {
func _iceD_ice_id(incoming inS: Incoming, current: Current) throws {
try inS.readEmptyParams()
let returnValue = try ice_id(current: current)
inS.write { ostr in
ostr.write(returnValue)
}
}
func _iceD_ice_ids(incoming inS: Incoming, current: Current) throws {
try inS.readEmptyParams()
let returnValue = try ice_ids(current: current)
inS.write { ostr in
ostr.write(returnValue)
}
}
func _iceD_ice_isA(incoming inS: Incoming, current: Current) throws {
let ident: String = try inS.read { istr in
try istr.read()
}
let returnValue = try ice_isA(id: ident, current: current)
inS.write { ostr in
ostr.write(returnValue)
}
}
func _iceD_ice_ping(incoming inS: Incoming, current: Current) throws {
try inS.readEmptyParams()
try ice_ping(current: current)
inS.writeEmptyParams()
}
}
/// Traits for Object.
public struct ObjectTraits: SliceTraits {
public static let staticIds = ["::Ice::Object"]
public static let staticId = "::Ice::Object"
}
/// class ObjectI provides the default implementation of Object operations (ice_id,
/// ice_ping etc.) for a given Slice interface.
open class ObjectI<T: SliceTraits>: Object {
public init() {}
open func ice_id(current _: Current) throws -> String {
return T.staticId
}
open func ice_ids(current _: Current) throws -> [String] {
return T.staticIds
}
open func ice_isA(id: String, current _: Current) throws -> Bool {
return T.staticIds.contains(id)
}
open func ice_ping(current _: Current) throws {
// Do nothing
}
}
/// Request dispatcher for plain Object servants.
public struct ObjectDisp: Disp {
public let servant: Object
public init(_ servant: Object) {
self.servant = servant
}
public func dispatch(request: Request, current: Current) throws {
switch current.operation {
case "ice_id":
try servant._iceD_ice_id(incoming: request, current: current)
case "ice_ids":
try servant._iceD_ice_ids(incoming: request, current: current)
case "ice_isA":
try servant._iceD_ice_isA(incoming: request, current: current)
case "ice_ping":
try servant._iceD_ice_ping(incoming: request, current: current)
default:
throw OperationNotExistException(id: current.id, facet: current.facet, operation: current.operation)
}
}
}
|