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
|
%{
**********************************************************************
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.
**********************************************************************
%}
classdef (Abstract) Application < handle
methods(Sealed)
%
% main() initializes the Communicator, calls run(), and destroys
% the Communicator upon return from run(). It thereby handles
% all exceptions properly, i.e., error messages are printed
% if exceptions propagate to main(), and the Communicator is
% always destroyed, regardless of exceptions.
%
function r = main(obj, appName, varargin)
if ~isempty(obj.communicator_)
printf('%s: only one instance of the Application class can be used', appName);
r = 1;
return;
end
obj.testName_ = appName;
args = {};
initializationData = [];
if length(varargin) >= 1
args = varargin{1};
end
if length(varargin) >= 2
initializationData = varargin{2};
end
%
% We parse the properties here to extract Ice.ProgramName.
%
if isempty(initializationData)
[initializationData, args] = obj.getInitData(args);
end
if ~isempty(initializationData)
initData = initializationData.clone();
else
initData = Ice.InitializationData();
end
[initData.properties_, args] = Ice.createProperties(args, initData.properties_);
status = 0;
try
[communicator, args] = Ice.initialize(args, initData);
obj.communicator_ = communicator;
status = obj.run(args);
catch ex
fprintf('%s: caught %s', obj.testName_, ex.identifier);
disp(getReport(ex, 'extended'));
status = 1;
end
obj.communicator_.destroy();
obj.communicator_ = [];
r = status;
end
function r = initialize(obj, varargin)
assert(length(varargin) <= 1);
if length(varargin) == 0
r = Ice.initialize();
else
r = Ice.initialize(varargin{1});
end
end
function r = appName(obj)
r = obj.testName_;
end
function r = communicator(obj)
r = obj.communicator_;
end
function r = createInitializationData(obj)
initData = Ice.InitializationData();
r = initData;
end
function r = getTestEndpoint(obj, num, prot)
r = Application.getTestEndpointWithProperties(obj.communicator_.getProperties(), num, prot);
end
function r = getTestHost(obj)
r = Application.getTestHostWithProperties(obj.communicator_.getProperties());
end
function r = getTestProtocol(obj)
r = Application.getTestProtocolWithProperties(obj.communicator_.getProperties());
end
function r = getTestPort(obj, num)
r = Application.getTestPortWithProperties(obj.communicator_.getProperties(), num);
end
end
methods(Static)
function r = getTestEndpointWithProperties(props, num, prot)
protocol = prot;
if length(protocol) == 0
protocol = props.getPropertyWithDefault('Ice.Default.Protocol', 'default');
end
basePort = props.getPropertyAsIntWithDefault('Test.BasePort', 12010);
r = sprintf('%s -p %d', protocol, basePort + num);
end
function r = getTestHostWithProperties(props)
r = props.getPropertyWithDefault('Ice.Default.Host', '127.0.0.1');
end
function r = getTestProtocolWithProperties(props)
r = props.getPropertyWithDefault('Ice.Default.Protocol', 'tcp');
end
function r = getTestPortWithProperties(props, num)
r = props.getPropertyAsIntWithDefault('Test.BasePort', 12010) + num;
end
end
methods(Abstract)
r = run(obj, args)
end
methods(Access=protected)
%
% Hook to override the initialization data. This hook is
% necessary because some properties must be set prior to
% communicator initialization.
%
function [initData, remArgs] = getInitData(obj, args)
initData = obj.createInitializationData();
[initData.properties_, remArgs] = Ice.createProperties(args);
remArgs = initData.properties_.parseCommandLineOptions('Test', remArgs);
end
end
properties(Access=private)
testName_
communicator_
end
end
|