Skip to content

Commit

Permalink
Rework EndpointInfo and ConnectionInfo in MATLAB (#3209)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Nov 27, 2024
1 parent 52a0912 commit ade64da
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 342 deletions.
19 changes: 6 additions & 13 deletions matlab/lib/+Ice/+SSL/ConnectionInfo.m
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
classdef ConnectionInfo < Ice.ConnectionInfo
classdef (Sealed) ConnectionInfo < Ice.ConnectionInfo
% ConnectionInfo Summary of ConnectionInfo
%
% Provides access to the connection detaisl of an SSL connection.
% Provides access to the connection details of an SSL connection.
%
% ConnectionInfo Properties:
% peerCertificate - The peer certificate.

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

methods
function obj = ConnectionInfo(underlying, incoming, adapterName, connectionId, ...
peerCertificate)
if nargin == 0
underlying = [];
incoming = false;
adapterName = '';
connectionId = '';
peerCertificate = '';
end
[email protected](underlying, incoming, adapterName, connectionId);
function obj = ConnectionInfo(underlying, peerCertificate)
assert(nargin == 2, 'Invalid number of arguments');
[email protected](underlying);
obj.peerCertificate = peerCertificate;
end
end
properties(SetAccess=private)
properties(SetAccess=immutable)
% peerCertificate - The peer certificate.
peerCertificate
end
Expand Down
12 changes: 4 additions & 8 deletions matlab/lib/+Ice/+SSL/EndpointInfo.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
classdef EndpointInfo < Ice.EndpointInfo
classdef (Sealed) EndpointInfo < Ice.EndpointInfo
% TCPEndpointInfo Summary of TCPEndpointInfo
%
% Provides access to a TCP endpoint information.

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

methods
function obj = EndpointInfo(type, secure, underlying, timeout, compress)
if nargin == 0
underlying = [];
timeout = 0;
compress = false;
end
[email protected](type, false, secure, underlying, timeout, compress);
function obj = EndpointInfo(underlying)
assert(nargin == 1, 'Invalid number of arguments');
[email protected](underlying);
end
end
end
23 changes: 8 additions & 15 deletions matlab/lib/+Ice/Connection.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,23 @@ function throwException(obj)

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);
r = Ice.TCPConnectionInfo(info.connectionId, info.localAddress, info.localPort, ...
info.remoteAddress, info.remotePort, info.rcvSize, info.sndSize);

case 'ssl'
r = Ice.SSL.ConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId, ...
info.peerCertificate);
r = Ice.SSL.ConnectionInfo(underlying, info.peerCertificate);

case 'udp'
r = Ice.UDPConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId, ...
info.localAddress, info.localPort, info.remoteAddress, ...
info.remotePort, info.mcastAddress, info.mcastPort, ...
r = Ice.UDPConnectionInfo(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);
r = Ice.WSConnectionInfo(underlying, info.headers);

otherwise
r = Ice.ConnectionInfo(underlying, info.incoming, info.adapterName, info.connectionId);
assert(false, 'unknown connection type');
end
end
end
Expand Down
47 changes: 17 additions & 30 deletions matlab/lib/+Ice/ConnectionInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,30 @@
% ConnectionInfo Base class providing access to the connection details.
%
% ConnectionInfo Properties:
% underlying (Ice.ConnectionInfo) - The information of the underyling
% transport or an empty array if there's no underlying transport.
% incoming (logical) - Whether or not the connection is an incoming or
% outgoing connection.
% adapterName (char) - The name of the adapter associated with the
% connection.
% underlying (Ice.ConnectionInfo) - The information of the underlying transport or an empty array if there's no
% underlying transport.
% connectionId (char) - The connection id.

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

methods
function obj = ConnectionInfo(underlying, incoming, adapterName, connectionId)
if nargin == 0
underlying = [];
incoming = false;
adapterName = '';
connectionId = '';
end
obj.underlying = underlying;
obj.incoming = incoming;
obj.adapterName = adapterName;
obj.connectionId = connectionId;
end
end
properties(SetAccess=private)
% underlying The information of the underyling transport or null
% if there's no underlying transport.
properties(SetAccess=immutable)
% underlying The information of the underlying transport or an empty array if there's no underlying transport.
underlying

% incoming Whether or not the connection is an incoming or outgoing
% connection.
incoming logical

% adapter The name of the adapter associated with the connection.
adapterName char

% connectionId The connection id.
connectionId char
end
methods(Access=protected)
function obj = ConnectionInfo(underlying, connectionId)
if nargin == 1
assert(~isempty(underlying), 'underlying cannot be empty');
connectionId = underlying.connectionId;
else
assert(nargin == 2, 'Invalid number of arguments');
assert(isempty(underlying), 'underlying must be empty');
end
obj.underlying = underlying;
obj.connectionId = connectionId;
end
end
end
20 changes: 9 additions & 11 deletions matlab/lib/+Ice/Endpoint.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,26 @@
end

if ~isempty(info.rawEncoding)
r = Ice.OpaqueEndpointInfo(info.type, underlying, info.timeout, info.compress, info.rawEncoding, ...
info.rawBytes);
r = Ice.OpaqueEndpointInfo(info.type, info.rawEncoding, info.rawBytes);
else
% info.infoType points to the XxxEndpointInfo type we need to create
switch info.infoType
case Ice.TCPEndpointType.value
r = Ice.TCPEndpointInfo(info.type, info.secure, underlying, info.timeout, info.compress, ...
info.host, info.port, info.sourceAddress);
r = Ice.TCPEndpointInfo(info.timeout, info.compress, info.host, info.port, ...
info.sourceAddress, info.type, info.secure);

case Ice.SSLEndpointType.value
r = Ice.SSL.EndpointInfo(info.type, info.secure, underlying, info.timeout, info.compress);
r = Ice.SSL.EndpointInfo(underlying);

case Ice.UDPEndpointType.value
r = Ice.UDPEndpointInfo(info.type, underlying, info.timeout, info.compress, info.host, ...
info.port, info.sourceAddress, info.mcastInterface, info.mcastTtl);
r = Ice.UDPEndpointInfo(info.compress, info.host, info.port, info.sourceAddress, ...
info.mcastInterface, info.mcastTtl);

case {Ice.WSEndpointType.value, Ice.WSSEndpointType.value}
r = Ice.WSEndpointInfo(info.type, info.secure, underlying, info.timeout, info.compress, ...
info.resource);
r = Ice.WSEndpointInfo(underlying, info.resource);

otherwise
r = Ice.EndpointInfo(info.type, info.datagram, info.secure, underlying, info.timeout, ...
info.compress);
assert(false, 'unknown endpoint type');
end
end
end
Expand Down
55 changes: 24 additions & 31 deletions matlab/lib/+Ice/EndpointInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,14 @@
% secure - Returns true if this endpoint is a secure endpoint.
%
% EndpointInfo Properties:
% underlying (Ice.EndpointInfo) - The information of the underyling
% endpoint or an empty array if there's no underlying endpoint.
% underlying (Ice.EndpointInfo) - The information of the underlying endpoint or an empty array if there's no
% underlying endpoint.
% timeout (int32) - The timeout for the endpoint in milliseconds.
% compress (logical) - Specifies whether or not compression should be
% used if available when using this endpoint.
% compress (logical) - Specifies whether or not compression should be used if available when using this endpoint.

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

methods
function obj = EndpointInfo(type, datagram, secure, underlying, timeout, compress)
if nargin == 3
underlying = [];
timeout = 0;
compress = false;
end
obj.type_ = type;
obj.datagram_ = datagram;
obj.secure_ = secure;
obj.underlying = underlying;
obj.timeout = timeout;
obj.compress = compress;
end
function r = type(obj)
% type Returns the type of the endpoint.
%
Expand All @@ -39,7 +25,7 @@
if ~isempty(obj.underlying)
r = obj.underlying.type();
else
r = obj.type_;
r = -1;
end
end
function r = datagram(obj)
Expand All @@ -50,7 +36,7 @@
if ~isempty(obj.underlying)
r = obj.underlying.datagram();
else
r = obj.datagram_;
r = false;
end
end
function r = secure(obj)
Expand All @@ -61,26 +47,33 @@
if ~isempty(obj.underlying)
r = obj.underlying.secure();
else
r = obj.secure_;
r = false;
end
end
end
properties(SetAccess=private)
% underlying The information of the underyling endpoint or an empty
% array if there's no underlying endpoint.
properties(SetAccess=immutable)
% underlying The information of the underlying endpoint or an empty array if there's no underlying endpoint.
underlying

% timeout The timeout for the endpoint in milliseconds. 0 means
% non-blocking, -1 means no timeout.
% timeout The timeout for the endpoint in milliseconds. 0 means non-blocking, -1 means no timeout.
timeout int32

% compress Specifies whether or not compression should be used if
% available when using this endpoint.
% compress Specifies whether or not compression should be used if available when using this endpoint.
compress logical
end
properties(Access=protected)
type_
datagram_
secure_
methods(Access=protected)
function obj = EndpointInfo(underlying, timeout, compress)
if nargin == 1
assert(~isempty(underlying), 'underlying cannot be empty');
timeout = underlying.timeout;
compress = underlying.compress;
else
assert(isempty(underlying), 'underlying must be empty');
assert(nargin == 3, 'Invalid number of arguments');
end
obj.underlying = underlying;
obj.timeout = timeout;
obj.compress = compress;
end
end
end
32 changes: 11 additions & 21 deletions matlab/lib/+Ice/IPConnectionInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,7 @@

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

methods
function obj = IPConnectionInfo(underlying, incoming, adapterName, connectionId, localAddress, localPort, ...
remoteAddress, remotePort)
if nargin == 0
underlying = [];
incoming = false;
adapterName = '';
connectionId = '';
localAddress = '';
localPort = 0;
remoteAddress = '';
remotePort = 0;
end
[email protected](underlying, incoming, adapterName, connectionId);
obj.localAddress = localAddress;
obj.localPort = localPort;
obj.remoteAddress = remoteAddress;
obj.remotePort = remotePort;
end
end
properties(SetAccess=private)
properties(SetAccess=immutable)
% localAddress - The local address.
localAddress char

Expand All @@ -44,4 +24,14 @@
% remotePort - The remote port.
remotePort int32
end
methods(Access=protected)
function obj = IPConnectionInfo(connectionId, localAddress, localPort, remoteAddress, remotePort)
assert(nargin == 5, 'Invalid number of arguments');
[email protected]([], connectionId);
obj.localAddress = localAddress;
obj.localPort = localPort;
obj.remoteAddress = remoteAddress;
obj.remotePort = remotePort;
end
end
end
27 changes: 10 additions & 17 deletions matlab/lib/+Ice/IPEndpointInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,7 @@

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

methods
function obj = IPEndpointInfo(type, datagram, secure, underlying, timeout, compress, host, port, sourceAddress)
if nargin == 3
underlying = [];
timeout = 0;
compress = false;
host = '';
port = 0;
sourceAddress = '';
end
[email protected](type, datagram, secure, underlying, timeout, compress);
obj.host = host;
obj.port = port;
obj.sourceAddress = sourceAddress;
end
end
properties(SetAccess=private)
properties(SetAccess=immutable)
% host - The host or address configured with the endpoint.
host char

Expand All @@ -36,4 +20,13 @@
% sourceAddress - The source IP address.
sourceAddress char
end
methods(Access=protected)
function obj = IPEndpointInfo(timeout, compress, host, port, sourceAddress)
assert(nargin == 5, 'Invalid number of arguments');
[email protected]([], timeout, compress);
obj.host = host;
obj.port = port;
obj.sourceAddress = sourceAddress;
end
end
end
Loading

0 comments on commit ade64da

Please sign in to comment.