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

import IceObjc

class EndpointInfoFactory: ICEEndpointInfoFactory {
    static func createTCPEndpointInfo(_ handle: ICEEndpointInfo,
                                      underlying: Any,
                                      timeout: Int32,
                                      compress: Bool,
                                      host: String,
                                      port: Int32,
                                      sourceAddress: String) -> Any {
        return TCPEndpointInfoI(handle: handle,
                                underlying: getUnderlying(underlying),
                                timeout: timeout,
                                compress: compress,
                                host: host,
                                port: port,
                                sourceAddress: sourceAddress)
    }

    static func createUDPEndpointInfo(_ handle: ICEEndpointInfo,
                                      underlying: Any,
                                      timeout: Int32,
                                      compress: Bool,
                                      host: String,
                                      port: Int32,
                                      sourceAddress: String,
                                      mcastInterface: String,
                                      mcastTtl: Int32) -> Any {
        return UDPEndpointInfoI(handle: handle,
                                underlying: getUnderlying(underlying),
                                timeout: timeout,
                                compress: compress,
                                host: host,
                                port: port,
                                sourceAddress: sourceAddress,
                                mcastInterface: mcastInterface,
                                mcastTtl: mcastTtl)
    }

    static func createWSEndpointInfo(_ handle: ICEEndpointInfo,
                                     underlying: Any,
                                     timeout: Int32,
                                     compress: Bool,
                                     resource: String) -> Any {
        return WSEndpointInfoI(handle: handle,
                               underlying: getUnderlying(underlying),
                               timeout: timeout,
                               compress: compress,
                               resource: resource)
    }

    static func createOpaqueEndpointInfo(_ handle: ICEEndpointInfo,
                                         underlying: Any,
                                         timeout: Int32,
                                         compress: Bool,
                                         encodingMajor: UInt8,
                                         encodingMinor: UInt8,
                                         rawBytes: Data) -> Any {
        return OpaqueEndpointInfoI(handle: handle,
                                   underlying: getUnderlying(underlying),
                                   timeout: timeout,
                                   compress: compress,
                                   rawEncoding: EncodingVersion(major: encodingMajor, minor: encodingMinor),
                                   rawBytes: rawBytes)
    }

    static func createSSLEndpointInfo(_ handle: ICEEndpointInfo,
                                      underlying: Any,
                                      timeout: Int32,
                                      compress: Bool) -> Any {
        return SSLEndpointInfoI(handle: handle,
                                underlying: getUnderlying(underlying),
                                timeout: timeout,
                                compress: compress)
    }

    #if os(iOS) || os(watchOS) || os(tvOS)

        static func createIAPEndpointInfo(_ handle: ICEEndpointInfo,
                                          underlying: Any,
                                          timeout: Int32,
                                          compress: Bool,
                                          manufacturer: String,
                                          modelNumber: String,
                                          name: String,
                                          protocol: String) -> Any {
            return IAPEndpointInfoI(handle: handle,
                                    underlying: getUnderlying(underlying),
                                    timeout: timeout,
                                    compress: compress,
                                    manufacturer: manufacturer,
                                    modelNumber: modelNumber,
                                    name: name,
                                    protocol: `protocol`)
        }

    #endif

    static func getUnderlying(_ info: Any) -> EndpointInfo? {
        return info as? EndpointInfo
    }
}