summaryrefslogtreecommitdiff
path: root/swift/src/Ice/Blobject.swift
blob: c7134a48ab9f1410c42c85a8db48ba197818540b (plain)
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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import Foundation

/// Base protocol for dynamic dispatch servants.
public protocol Blobject {
    /// Dispatch an incoming request.
    ///
    /// - parameter inEncaps: `Data` - The encoded in-parameters for the operation.
    ///
    /// - parameter current: `Ice.Current` - The Current object to pass to the operation.
    ///
    /// - returns: `(ok: Bool, outParams: Data)` - A tuple with the following fields:
    ///
    ///   - ok: `Bool` - True if the operation completed successfully, false if
    ///     the operation raised a user exception (in this case, outParams
    ///     contains the encoded user exception). If the operation raises an
    ///     Ice run-time exception, it must throw it directly.
    ///
    ///   - outParams: `Data` - The encoded out-paramaters and return value
    ///     for the operation. The return value follows any out-parameters.
    func ice_invoke(inEncaps: Data, current: Current) throws -> (ok: Bool, outParams: Data)
}

/// Request dispatcher for Blobject servants.
public struct BlobjectDisp: Disp {
    public let servant: Blobject

    public init(_ servant: Blobject) {
        self.servant = servant
    }

    public func dispatch(request: Request, current: Current) throws {
        let inEncaps = try request.readParamEncaps()
        let invokeResult = try servant.ice_invoke(inEncaps: inEncaps, current: current)
        request.writeParamEncaps(ok: invokeResult.ok, outParams: invokeResult.outParams)
    }
}