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
|
%%----------------------------------------------------------------------
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2000-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); yu may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
%%
%%----------------------------------------------------------------------
%% File : CosPropertyService_PropertySetFactory_impl.erl
%% Description :
%%
%%----------------------------------------------------------------------
-module('CosPropertyService_PropertySetFactory_impl').
%%----------------------------------------------------------------------
%% Include files
%%----------------------------------------------------------------------
-include_lib("orber/include/corba.hrl").
-include_lib("orber/src/orber_iiop.hrl").
-include("CosPropertyService.hrl").
-include("cosProperty.hrl").
%%----------------------------------------------------------------------
%% External exports
%%----------------------------------------------------------------------
-export([init/1,
terminate/2,
code_change/3]).
-export([create_propertyset/2,
create_constrained_propertyset/4,
create_initial_propertyset/3]).
%%----------------------------------------------------------------------
%% Internal exports
%%----------------------------------------------------------------------
-export([]).
%%----------------------------------------------------------------------
%% Records
%%----------------------------------------------------------------------
-record(state, {}).
%%----------------------------------------------------------------------
%% Macros
%%----------------------------------------------------------------------
-define(checkTCfun, fun(TC) -> orber_tc:check_tc(TC) end).
%%======================================================================
%% External functions
%%======================================================================
%%----------------------------------------------------------------------
%% Function : init/1
%% Returns : {ok, State} |
%% {ok, State, Timeout} |
%% ignore |
%% {stop, Reason}
%% Description: Initiates the server
%%----------------------------------------------------------------------
init([]) ->
{ok, #state{}}.
%%----------------------------------------------------------------------
%% Function : terminate/2
%% Returns : any (ignored by gen_server)
%% Description: Shutdown the server
%%----------------------------------------------------------------------
terminate(_Reason, _State) ->
ok.
%%----------------------------------------------------------------------
%% Function : code_change/3
%% Returns : {ok, NewState}
%% Description: Convert process state when code is changed
%%----------------------------------------------------------------------
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%%----------------------------------------------------------------------
%% Function : create_propertyset
%% Arguments :
%% Returns : CosPropertyService::PropertySet reference.
%% Description:
%%----------------------------------------------------------------------
create_propertyset(_OE_This, State) ->
{reply,
'CosPropertyService_PropertySetDef':
oe_create({normal, [], [], [], ?PropertySet}, [{pseudo, true}]),
State}.
%%----------------------------------------------------------------------
%% Function : create_constrained_propertyset
%% Arguments : PropTypes - list of property types.
%% Properties - list of properties.
%% Returns : CosPropertyService::PropertySet |
%% {'EXCEPTION', CosPropertyService::ConstraintNotSupported}
%% Description:
%%----------------------------------------------------------------------
create_constrained_propertyset(_OE_This, State, PropTypes, Properties) ->
case lists:all(?checkTCfun, PropTypes) of
true ->
crosscheckTC(Properties, PropTypes),
{reply,
'CosPropertyService_PropertySetDef':
oe_create({normal, PropTypes, Properties, [], ?PropertySet},
[{pseudo, true}]),
State};
false ->
corba:raise(#'CosPropertyService_ConstraintNotSupported'{})
end.
crosscheckTC([], _) ->
ok;
crosscheckTC([#'CosPropertyService_Property'
{property_name = Name,
property_value = Value}|T], TCs) ->
case lists:member(any:get_typecode(Value), TCs) of
true when Name =/= "" ->
crosscheckTC(T, TCs);
_ ->
corba:raise(#'CosPropertyService_ConstraintNotSupported'{})
end.
%%----------------------------------------------------------------------
%% Function : create_initial_propertyset
%% Arguments : Properties - list of properties.
%% Returns : CosPropertyService::PropertySetDef |
%% {'EXCEPTION', CosPropertyService::MultipleExceptions}
%% Description:
%%----------------------------------------------------------------------
create_initial_propertyset(_OE_This, State, Properties) ->
InitProps = evaluate_propertyset(Properties),
{reply,
'CosPropertyService_PropertySetDef':
oe_create({normal, [], [], InitProps, ?PropertySet}, [{pseudo, true}]),
State}.
%%======================================================================
%% Internal functions
%%======================================================================
evaluate_propertyset(Sets) ->
evaluate_propertyset(Sets, [], []).
%% To avoid dialyzer warnings due to the use of exit/throw.
-spec(evaluate_propertyset/3 :: (_, _, _) -> no_return()).
evaluate_propertyset([], NewProperties, []) ->
%% No exceptions found.
NewProperties;
evaluate_propertyset([], _, Exc) ->
corba:raise(#'CosPropertyService_MultipleExceptions'{exceptions = Exc});
evaluate_propertyset([#'CosPropertyService_Property'
{property_name = Name,
property_value = Value}|T], X, Exc) ->
case orber_tc:check_tc(any:get_typecode(Value)) of
true ->
evaluate_propertyset(T, [{Name, Value, normal}|X], Exc);
false ->
evaluate_propertyset(T, X, [#'CosPropertyService_PropertyException'
{reason = unsupported_type_code,
failing_property_name = Name}|Exc])
end.
%%======================================================================
%% END OF MODULE
%%======================================================================
|