File: Connection.m

package info (click to toggle)
zeroc-ice 3.7.10-3.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 75,696 kB
  • sloc: cpp: 356,894; java: 226,081; cs: 98,312; javascript: 35,027; python: 28,716; objc: 27,050; php: 7,526; ruby: 7,190; yacc: 2,949; ansic: 2,469; xml: 1,589; lex: 1,241; makefile: 472; sh: 52
file content (282 lines) | stat: -rw-r--r-- 11,768 bytes parent folder | download | duplicates (4)
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
classdef Connection < IceInternal.WrapperObject
    % Connection   Summary of Connection
    %
    % The user-level interface to a connection.
    %
    % Connection Methods:
    %   close - Manually close the connection using the specified closure mode.
    %   closeAsync - Manually close the connection using the specified closure
    %     mode.
    %   createProxy - Create a special proxy that always uses this connection.
    %   getEndpoint - Get the endpoint from which the connection was created.
    %   flushBatchRequests - Flush any pending batch requests for this
    %     connection.
    %   flushBatchRequestsAsync - Flush any pending batch requests for this
    %     connection.
    %   heartbeat - Send a heartbeat message.
    %   heartbeatAsync - Send a heartbeat message.
    %   setACM - Set the active connection management parameters.
    %   getACM - Get the ACM parameters.
    %   type - Return the connection type.
    %   timeout - Get the timeout for the connection.
    %   toString - Return a description of the connection as human readable
    %     text, suitable for logging or error messages.
    %   getInfo - Returns the connection information.
    %   setBufferSize - Set the connection buffer receive/send size.
    %   throwException - Throw an exception indicating the reason for
    %     connection closure.

    % Copyright (c) ZeroC, Inc. All rights reserved.

    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.iceCallWithResult('equals', other.impl_);
            end
        end
        function close(obj, mode)
            % close   Manually close the connection using the specified
            %   closure mode.
            %
            % Parameters:
            %   mode (Ice.ConnectionClose) - Determines how the connection
            %     will be closed.

            obj.iceCall('close', mode);
        end
        function f = closeAsync(obj)
            % closeAsync   Manually close the connection using the specified
            %   closure mode.
            %
            % Parameters:
            %   mode (Ice.ConnectionClose) - Determines how the connection
            %     will be closed.
            %
            % Returns (Ice.Future) - A future that will be completed when the
            %   invocation completes.

            future = libpointer('voidPtr');
            obj.iceCall('closeAsync', future);
            assert(~isNull(future));
            f = Ice.Future(future, 'close', 0, 'Ice_SimpleFuture', @(fut) fut.iceCall('check'));
        end
        function r = createProxy(obj, id)
            % createProxy   Create a special proxy that always uses this
            %   connection. This can be used for callbacks from a server to a
            %   client if the server cannot directly establish a connection to
            %   the client, for example because of firewalls. In this case,
            %   the server would create a proxy using an already established
            %   connection from the client.
            %
            % Parameters:
            %   id (Ice.Identity) - The identity for which a proxy is to be
            %     created.
            %
            % Returns (Ice.ObjectPrx) - A proxy that matches the given identity
            %   and uses this connection.

            proxy = libpointer('voidPtr');
            obj.iceCall('createProxy', id, proxy);
            r = Ice.ObjectPrx(obj.communicator, obj.communicator.getEncoding(), proxy);
        end
        function r = getEndpoint(obj)
            % getEndpoint   Get the endpoint from which the connection was
            %   created.
            %
            % Returns (Ice.Endpoint) - The endpoint from which the connection
            %   was created.

            endpoint = libpointer('voidPtr');
            obj.iceCall('getEndpoint', endpoint);
            r = Ice.Endpoint(endpoint);
        end
        function flushBatchRequests(obj, compress)
            % flushBatchRequests   Flush any pending batch requests for this
            %   connection. This means all batch requests invoked on fixed
            %   proxies associated with the connection.
            %
            % Parameters:
            %   compress (Ice.CompressBatch) - Specifies whether or not the
            %     queued batch requests should be compressed before being sent
            %     over the wire.

            obj.iceCall('flushBatchRequests', compress);
        end
        function r = flushBatchRequestsAsync(obj)
            % flushBatchRequestsAsync   Flush any pending batch requests for
            %   this connection. This means all batch requests invoked on fixed
            %   proxies associated with the connection.
            %
            % Parameters:
            %   compress (Ice.CompressBatch) - Specifies whether or not the
            %     queued batch requests should be compressed before being sent
            %     over the wire.
            %
            % Returns (Ice.Future) - A future that will be completed when the
            %   invocation completes.

            future = libpointer('voidPtr');
            obj.iceCall('flushBatchRequestsAsync', future);
            assert(~isNull(future));
            r = Ice.Future(future, 'flushBatchRequests', 0, 'Ice_SimpleFuture', @(fut) fut.iceCall('check'));
        end
        function heartbeat(obj)
            % heartbeat   Send a heartbeat message.

            obj.iceCall('heartbeat');
        end
        function r = heartbeatAsync(obj)
            % heartbeatAsync   Send a heartbeat message.
            %
            % Returns (Ice.Future) - A future that will be completed when the
            %   invocation completes.

            future = libpointer('voidPtr');
            obj.iceCall('heartbeatAsync', future);
            assert(~isNull(future));
            r = Ice.Future(future, 'heartbeat', 0, 'Ice_SimpleFuture', @(fut) fut.iceCall('check'));
        end
        function setACM(obj, timeout, close, heartbeat)
            % setACM   Set the active connection management parameters.
            %
            % Parameters:
            %   timeout (int32) - The timeout value in milliseconds.
            %   close (Ice.ACMClose) - The close condition.
            %   heartbeat (Ice.ACMHeartbeat) - The hertbeat condition.

            if timeout == Ice.Unset
                timeout = [];
            end
            if close == Ice.Unset
                close = [];
            end
            if heartbeat == Ice.Unset
                heartbeat = [];
            end
            obj.iceCall('setACM', timeout, close, heartbeat);
        end
        function r = getACM(obj)
            % getACM   Get the ACM parameters.
            %
            % Returns (Ice.ACM) - The ACM parameters.

            r = obj.iceCallWithResult('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)
            % type   Return the connection type. This corresponds to the
            %   endpoint type, i.e., "tcp", "udp", etc.
            %
            % Returns (char) - The type of the connection.

            r = obj.iceCallWithResult('type');
        end
        function r = timeout(obj)
            % timeout   Get the timeout for the connection.
            %
            % Returns (int32) - The connection's timeout.

            r = obj.iceCallWithResult('timeout');
        end
        function r = toString(obj)
            % toString   Return a description of the connection as human
            %   readable text, suitable for logging or error messages.
            %
            % Returns (char) - The description of the connection as human
            %   readable text.

            r = obj.iceCallWithResult('toString');
        end
        function r = getInfo(obj)
            % getInfo   Returns the connection information.
            %
            % Returns (Ice.ConnectionInfo) - The connection information.

            info = obj.iceCallWithResult('getInfo');
            r = obj.createConnectionInfo(info);
        end
        function setBufferSize(obj, rcvSize, sndSize)
            % setBufferSize   Set the connection buffer receive/send size.
            %
            % Parameters:
            %   rcvSize (int32) - The connection receive buffer size.
            %   sndSize (int32) - The connection send buffer size.

            obj.iceCall('setBufferSize', rcvSize, sndSize);
        end
        function throwException(obj)
            % throwException   Throw an exception indicating the reason for
            %   connection closure. For example, CloseConnectionException is
            %   raised if the connection was closed gracefully, whereas
            %   ConnectionManuallyClosedException is raised if the connection
            %   was manually closed by the application. This operation does
            %   nothing if the connection is not yet closed.

            obj.iceCall('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 = IceSSL.ConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId, ...
                                             info.cipher, info.certs, info.verified);

                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