summaryrefslogtreecommitdiff
path: root/matlab/lib/+Ice/Connection.m
blob: 7d747d9a2fad3c4cb113fa9c227bc0efbc68b627 (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
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
%{
**********************************************************************

Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.

This copy of Ice is licensed to you under the terms described in the
ICE_LICENSE file included in this distribution.

**********************************************************************
%}
%
% Ice version 3.7.0
%

classdef Connection < IceInternal.WrapperObject
    methods
        function obj = Connection(impl, communicator)
            if ~isa(impl, 'lib.pointer')
                throw(MException('Ice:ArgumentException', 'invalid argument'));
            end
            obj = obj@IceInternal.WrapperObject(impl);
            obj.communicator = communicator;
        end
        function r = eq(obj, other)
            %
            % Override == operator.
            %
            if isempty(other) || ~isa(other, 'Ice.Connection')
                r = false;
            else
                %
                % Call into C++ to compare the two objects.
                %
                r = obj.callWithResult_('equals', other.impl_);
            end
        end
        function close(obj, mode)
            obj.call_('close', mode);
        end
        function f = closeAsync(obj)
            future = libpointer('voidPtr');
            obj.call_('closeAsync', future);
            assert(~isNull(future));
            f = Ice.Future(future, 'close', 0, 'Ice_SimpleFuture', @(fut) fut.call_('check'));
        end
        function r = createProxy(obj, id)
            proxy = libpointer('voidPtr');
            obj.call_('createProxy', id, proxy);
            r = Ice.ObjectPrx(obj.communicator, obj.communicator.getEncoding(), proxy);
        end
        function r = getEndpoint(obj)
            endpoint = libpointer('voidPtr');
            obj.call_('getEndpoint', endpoint);
            r = Ice.Endpoint(endpoint);
        end
        function flushBatchRequests(obj, compress)
            obj.call_('flushBatchRequests', compress);
        end
        function r = flushBatchRequestsAsync(obj)
            future = libpointer('voidPtr');
            obj.call_('flushBatchRequestsAsync', future);
            assert(~isNull(future));
            r = Ice.Future(future, 'flushBatchRequests', 0, 'Ice_SimpleFuture', @(fut) fut.call_('check'));
        end
        function heartbeat(obj)
            obj.call_('heartbeat');
        end
        function r = heartbeatAsync(obj)
            future = libpointer('voidPtr');
            obj.call_('heartbeatAsync', future);
            assert(~isNull(future));
            r = Ice.Future(future, 'heartbeat', 0, 'Ice_SimpleFuture', @(fut) fut.call_('check'));
        end
        function setACM(obj, timeout, close, heartbeat)
            if timeout == Ice.Unset
                timeout = [];
            end
            if close == Ice.Unset
                close = [];
            end
            if heartbeat == Ice.Unset
                heartbeat = [];
            end
            obj.call_('setACM', timeout, close, heartbeat);
        end
        function r = getACM(obj)
            r = obj.callWithResult_('getACM');
            if isempty(r.timeout)
                r.timeout = Ice.Unset;
            end
            if isempty(r.close)
                r.close = Ice.Unset;
            end
            if isempty(r.heartbeat)
                r.heartbeat = Ice.Unset;
            end
        end
        function r = type(obj)
            r = obj.callWithResult_('type');
        end
        function r = timeout(obj)
            r = obj.callWithResult_('timeout');
        end
        function r = toString(obj)
            r = obj.callWithResult_('toString');
        end
        function r = getInfo(obj)
            info = obj.callWithResult_('getInfo');
            r = obj.createConnectionInfo(info);
        end
        function setBufferSize(obj, rcvSize, sndSize)
            obj.call_('setBufferSize', rcvSize, sndSize);
        end
        function throwException(obj)
            obj.call_('throwException');
        end
    end

    methods(Access=private)
        function r = createConnectionInfo(obj, info)
            underlying = [];
            if ~isempty(info.underlying)
                underlying = obj.createConnectionInfo(info.underlying);
            end

            switch info.type
                case 'tcp'
                    r = Ice.TCPConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId, ...
                                              info.localAddress, info.localPort, info.remoteAddress, ...
                                              info.remotePort, info.rcvSize, info.sndSize);

                case 'ssl'
                    r = Ice.IPConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId, ...
                                             info.localAddress, info.localPort, info.remoteAddress, info.remotePort);

                case 'udp'
                    r = Ice.UDPConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId, ...
                                              info.localAddress, info.localPort, info.remoteAddress, ...
                                              info.remotePort, info.mcastAddress, info.mcastPort, ...
                                              info.rcvSize, info.sndSize);

                case 'ws'
                    r = Ice.WSConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId, ...
                                             info.headers);

                case 'ip'
                    r = Ice.IPConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId, ...
                                             info.localAddress, info.localPort, info.remoteAddress, info.remotePort);

                otherwise
                    r = Ice.ConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId);
            end
        end
    end

    properties(Access=private)
        communicator % The communicator wrapper
    end
end