1%%--------------------------------------------------------------------
2%%
3%% %CopyrightBegin%
4%%
5%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
6%%
7%% Licensed under the Apache License, Version 2.0 (the "License");
8%% you may not use this file except in compliance with the License.
9%% You may obtain a copy of the License at
10%%
11%%     http://www.apache.org/licenses/LICENSE-2.0
12%%
13%% Unless required by applicable law or agreed to in writing, software
14%% distributed under the License is distributed on an "AS IS" BASIS,
15%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16%% See the License for the specific language governing permissions and
17%% limitations under the License.
18%%
19%% %CopyrightEnd%
20%%
21%%
22%%%----------------------------------------------------------------------
23%%% File    : ir_objects.hrl
24%%% Purpose : Record definitions for the IR DB
25%%%----------------------------------------------------------------------
26
27%%%----------------------------------------------------------------------
28%%% *********************************************************************
29%%% *									*
30%%% *                        PLEASE NOTE				*
31%%% *									*
32%%% * If a record is removed or added in this file, the corresponding   *
33%%% * database initialization code _MUST_ be updated accordingly.	*
34%%% *									*
35%%% * The initialization code is defined in a macro in this file.	*
36%%% *									*
37%%% * Also remember to update select/2 in orber_ifr.erl when adding	*
38%%% * or deleting a record in this file.				*
39%%% *									*
40%%% *********************************************************************
41%%%----------------------------------------------------------------------
42
43%% Interface objects
44
45%% There are eight interface objects in an interface repository:
46%% Repository, ModuleDef, InterfaceDef, AttributeDef, OperationDef,
47%% TypedefDef, ConstantDef and ExceptionDef (CORBA V2.0, page 6-5/6).
48
49% The other objects defined here are used to build the above objects
50% (CORBA V2.0, page 6-7).
51
52% Object references are stored as mnesia object IDs, i.e. a tuple with
53% the table name and the ir_Internal_ID.
54
55% Inheritance strategy. We incorporate the inherited object into the
56% inheriting object. The record element 'inherited_objects' is a list
57% of objects that "this" object inherits from (i.e. full object
58% records and not object references).
59
60% The record element 'ir_Internal_ID' is a tag that uniquely
61% identifies a record. See the function orber_ifr:unique().
62
63						% IRObject, page 6-9
64-record(ir_IRObject,	 {ir_Internal_ID,def_kind}).
65
66						% Contained, page 6-9
67-record(ir_Contained,    {ir_Internal_ID,	%[IRObject]
68			  def_kind,		%from IRObject
69			  id,
70			  name,
71			  version,
72			  defined_in,
73			  absolute_name,
74			  containing_repository}).
75
76						% Container, page 6-10
77-record(ir_Container,    {ir_Internal_ID,	%[IRObject]
78			  def_kind,		%from IRObject
79			  contents}).
80
81						% IDLType, page 6-15
82-record(ir_IDLType,      {ir_Internal_ID,	%[IRObject]
83			  def_kind,		%from IRObject
84			  type}).
85
86						% Repository, page 6-16
87-record(ir_Repository,   {ir_Internal_ID,	%[Container]
88			  def_kind,		%from IRObject
89			  contents,		%from Container
90			  primitivedefs}).
91
92						% ModuleDef, page 6-17
93-record(ir_ModuleDef,    {ir_Internal_ID,	%[Container,Contained]
94			  def_kind,		%from IRObject
95			  contents,		%from Container
96			  id,			%from Contained
97			  name,			%from Contained
98			  version,		%from Contained
99			  defined_in,		%from Contained
100			  absolute_name,	%from Contained
101			  containing_repository %from Contained
102			 }).
103
104						% ConstantDef, page 6-17
105-record(ir_ConstantDef,  {ir_Internal_ID,	%[Contained]
106			  def_kind,		%from IRObject
107			  id,			%from Contained
108			  name,			%from Contained
109			  version,		%from Contained
110			  defined_in,		%from Contained
111			  absolute_name,	%from Contained
112			  containing_repository, %from Contained
113			  type,
114			  type_def,
115			  value}).
116
117						% TypedefDef, page 6-18
118-record(ir_TypedefDef,   {ir_Internal_ID,	%[Contained,IDLType]
119			  def_kind,		%from IRObject
120			  id,			%from Contained
121			  name,			%from Contained
122			  version,		%from Contained
123			  defined_in,		%from Contained
124			  absolute_name,	%from Contained
125			  containing_repository, %from Contained
126			  type			%from IDLType
127			 }).
128
129						% StructDef, page 6-19
130-record(ir_StructDef,    {ir_Internal_ID,	%[TypedefDef]
131			  def_kind,		%from IRObject
132			  id,			%from Contained
133			  name,			%from Contained
134			  version,		%from Contained
135			  defined_in,		%from Contained
136			  absolute_name,	%from Contained
137			  containing_repository, %from Contained
138			  type,			%from IDLType
139			  members}).
140
141						% UnionDef, page 6-19
142-record(ir_UnionDef,     {ir_Internal_ID,	%[TypedefDef]
143			  def_kind,		%from IRObject
144			  id,			%from Contained
145			  name,			%from Contained
146			  version,		%from Contained
147			  defined_in,		%from Contained
148			  absolute_name,	%from Contained
149			  containing_repository, %from Contained
150			  type,			%from IDLType
151			  discriminator_type,
152			  discriminator_type_def,
153			  members}).
154
155						% EnumDef, page 6-20
156-record(ir_EnumDef,      {ir_Internal_ID,	%[TypedefDef]
157			  def_kind,		%from IRObject
158			  id,			%from Contained
159			  name,			%from Contained
160			  version,		%from Contained
161			  defined_in,		%from Contained
162			  absolute_name,	%from Contained
163			  containing_repository, %from Contained
164			  type,			%from IDLType
165			  members}).
166
167						% AliasDef, page 6-21
168-record(ir_AliasDef,     {ir_Internal_ID,	%[TypedefDef]
169			  def_kind,		%from IRObject
170			  id,			%from Contained
171			  name,			%from Contained
172			  version,		%from Contained
173			  defined_in,		%from Contained
174			  absolute_name,	%from Contained
175			  containing_repository, %from Contained
176			  type,			%from IDLType
177			  original_type_def}).
178
179						% PrimitiveDef, page 6-21
180-record(ir_PrimitiveDef, {ir_Internal_ID,	%[IDLType]
181			  def_kind,		%from IRObject
182			  type,			%from IDLType
183			  kind}).
184
185						% StringDef, page 6-22
186-record(ir_StringDef,    {ir_Internal_ID,	%[IDLType]
187			  def_kind,		%from IRObject
188			  type,			%from IDLType
189			  bound}).
190
191-record(ir_WstringDef,   {ir_Internal_ID,	%[IDLType]
192			  def_kind,		%from IRObject
193			  type,			%from IDLType
194			  bound}).
195
196						% SequenceDef, page 6-22
197-record(ir_SequenceDef,  {ir_Internal_ID,	%[IDLType]
198			  def_kind,		%from IRObject
199			  type,			%from IDLType
200			  bound,
201			  element_type,
202			  element_type_def}).
203
204						% ArrayDef, page 6-23
205-record(ir_ArrayDef,     {ir_Internal_ID,	%[IDLType]
206			  def_kind,		%from IRObject
207			  type,			%from IDLType
208			  length,
209			  element_type,
210			  element_type_def}).
211
212						% ExceptionDef, page 6-23
213-record(ir_ExceptionDef, {ir_Internal_ID,	%[Contained]
214			  def_kind,		%from IRObject
215			  id,			%from Contained
216			  name,			%from Contained
217			  version,		%from Contained
218			  defined_in,		%from Contained
219			  absolute_name,	%from Contained
220			  containing_repository, %from Contained
221			  type,
222			  members}).
223
224						% AttributeDef, page 6-24
225-record(ir_AttributeDef, {ir_Internal_ID,	%[Contained]
226			  def_kind,		%from IRObject
227			  id,			%from Contained
228			  name,			%from Contained
229			  version,		%from Contained
230			  defined_in,		%from Contained
231			  absolute_name,	%from Contained
232			  containing_repository, %from Contained
233			  type,
234			  type_def,
235			  mode}).
236
237						% OperationDef, page 6-25
238-record(ir_OperationDef, {ir_Internal_ID,	%[Contained]
239			  def_kind,		%from IRObject
240			  id,			%from Contained
241			  name,			%from Contained
242			  version,		%from Contained
243			  defined_in,		%from Contained
244			  absolute_name,	%from Contained
245			  containing_repository, %from Contained
246			  result,
247			  result_def,
248			  params,
249			  mode,
250			  contexts,
251			  exceptions}).
252
253						% InterfaceDef, page 6-27
254-record(ir_InterfaceDef, {ir_Internal_ID,	%[Container,Contained,IDLType]
255			  def_kind,		%from IRObject
256			  contents,		%from Container
257			  id,			%from Contained
258			  name,			%from Contained
259			  version,		%from Contained
260			  defined_in,		%from Contained
261			  absolute_name,	%from Contained
262			  containing_repository, %from Contained
263			  type,			%from IDLType
264			  base_interfaces}).
265
266						% TypeCode, page 6-33
267
268-record(ir_FixedDef,     {ir_Internal_ID,	%[IDLType]
269			  def_kind,		%from IRObject
270			  type,			%from IDLType
271			  digits,
272			  scale}).
273
274
275% TypeCodes cannot be defined as records, since each type code has a
276% quite unique structure depending on the type. The old TypeCode
277% record definition is left here as a comment in case we want to
278% change back to the old style.
279
280%% ir_TypeCode does not have a field ir_Internal_ID. TypeCodes are
281%% never explicitly written to the database as separate DB-records.
282%% TypeCodes are stored as full records whenever they are used in an
283%% IFR-object.
284%%-record(ir_TypeCode,     {kind,
285%%			  parameter_list}).
286
287						% ORB, page 6-39
288-record(ir_ORB,          {ir_Internal_ID,   % *** Do we need any attributes
289			  dummy}).	    % for this table? ORB is a pseudo-
290					    % object so perhaps the table is
291					    % unnecessary?
292
293-record(orber_light_ifr, {id, %% IFR-id
294			  module,
295			  type,
296			  base_id}).
297
298-define(IFR_ModuleDef,    0).
299-define(IFR_ConstantDef,  1).
300-define(IFR_StructDef,    2).
301-define(IFR_UnionDef,     3).
302-define(IFR_EnumDef,      4).
303-define(IFR_AliasDef,     5).
304-define(IFR_InterfaceDef, 6).
305-define(IFR_ExceptionDef, 7).
306
307
308%%%----------------------------------------------------------------------
309%%% 'ifr_object_list' is used by other modules. Do NOT remove or rename
310%%% this list!
311%%% An addition or deletion of a record above must be duplicated here in
312%%% this list and in the macro 'ifr_record_tuple_list' below.
313-define(ifr_object_list, [ir_ModuleDef,
314			  ir_Contained,
315			  ir_AttributeDef,
316			  ir_Repository,
317			  ir_OperationDef,
318			  ir_InterfaceDef,
319			  ir_TypedefDef,
320			  ir_Container,
321			  ir_EnumDef,
322			  ir_UnionDef,
323			  ir_StringDef,
324			  ir_WstringDef,
325			  ir_ORB,
326			  ir_IDLType,
327			  ir_ExceptionDef,
328			  ir_IRObject,
329			  ir_PrimitiveDef,
330			  ir_ArrayDef,
331			  ir_AliasDef,
332			  ir_ConstantDef,
333			  ir_StructDef,
334			  ir_SequenceDef,
335			  ir_FixedDef]).
336
337-define(ifr_light_object_list, [orber_light_ifr]).
338
339-define(cr_fun_tuple(Table, Options),
340	{Table,
341	 fun() ->
342		 case mnesia:create_table(Table,[{attributes,
343						  record_info(fields,
344							      Table)}]++Options)of
345		     {atomic,ok} ->
346			 ok;
347		     R ->
348			 R
349		 end
350	 end}
351       ).
352
353-define(cr_fun_tuple_local(Table, IFR_storage_type),
354	{Table,
355	 fun() ->
356		 case mnesia:add_table_copy(Table,node(), IFR_storage_type)of
357		     {atomic,ok} ->
358			 ok;
359		     R ->
360			 R
361		 end
362	 end}
363       ).
364
365-define(ifr_record_tuple_list(Options),
366        [?cr_fun_tuple(ir_IRObject, Options),
367         ?cr_fun_tuple(ir_Contained, [{index, [#ir_Contained.id]}|Options]),
368         ?cr_fun_tuple(ir_Container, Options),
369         ?cr_fun_tuple(ir_IDLType, Options),
370         ?cr_fun_tuple(ir_Repository, Options),
371         ?cr_fun_tuple(ir_ModuleDef, [{index, [#ir_ModuleDef.id]}|Options]),
372         ?cr_fun_tuple(ir_ConstantDef, [{index, [#ir_ConstantDef.id]}|Options]),
373         ?cr_fun_tuple(ir_TypedefDef, [{index, [#ir_TypedefDef.id]}|Options]),
374         ?cr_fun_tuple(ir_StructDef, [{index, [#ir_StructDef.id]}|Options]),
375         ?cr_fun_tuple(ir_UnionDef, [{index, [#ir_UnionDef.id]}|Options]),
376         ?cr_fun_tuple(ir_EnumDef, [{index, [#ir_EnumDef.id]}|Options]),
377         ?cr_fun_tuple(ir_AliasDef, [{index, [#ir_AliasDef.id]}|Options]),
378         ?cr_fun_tuple(ir_PrimitiveDef, Options),
379         ?cr_fun_tuple(ir_StringDef, Options),
380         ?cr_fun_tuple(ir_WstringDef, Options),
381         ?cr_fun_tuple(ir_SequenceDef, Options),
382         ?cr_fun_tuple(ir_ArrayDef, Options),
383         ?cr_fun_tuple(ir_ExceptionDef, [{index, [#ir_ExceptionDef.id]}|Options]),
384         ?cr_fun_tuple(ir_AttributeDef, [{index, [#ir_AttributeDef.id]}|Options]),
385         ?cr_fun_tuple(ir_OperationDef, [{index, [#ir_OperationDef.id]}|Options]),
386         ?cr_fun_tuple(ir_InterfaceDef, [{index, [#ir_InterfaceDef.id]}| Options]),
387%        ?cr_fun_tuple(ir_TypeCode, Options),
388         ?cr_fun_tuple(ir_ORB, Options),
389	 ?cr_fun_tuple(ir_FixedDef, Options)]).
390
391-define(ifr_light_record_tuple_list(Options),
392        [?cr_fun_tuple(orber_light_ifr, Options)]).
393
394
395-define(ifr_record_tuple_list_local(IFR_storage_type),
396        [?cr_fun_tuple_local(ir_IRObject, IFR_storage_type),
397         ?cr_fun_tuple_local(ir_Contained, IFR_storage_type),
398         ?cr_fun_tuple_local(ir_Container, IFR_storage_type),
399         ?cr_fun_tuple_local(ir_IDLType, IFR_storage_type),
400         ?cr_fun_tuple_local(ir_Repository, IFR_storage_type),
401         ?cr_fun_tuple_local(ir_ModuleDef, IFR_storage_type),
402         ?cr_fun_tuple_local(ir_ConstantDef, IFR_storage_type),
403         ?cr_fun_tuple_local(ir_TypedefDef, IFR_storage_type),
404         ?cr_fun_tuple_local(ir_StructDef, IFR_storage_type),
405         ?cr_fun_tuple_local(ir_UnionDef, IFR_storage_type),
406         ?cr_fun_tuple_local(ir_EnumDef, IFR_storage_type),
407         ?cr_fun_tuple_local(ir_AliasDef, IFR_storage_type),
408         ?cr_fun_tuple_local(ir_PrimitiveDef, IFR_storage_type),
409         ?cr_fun_tuple_local(ir_StringDef, IFR_storage_type),
410         ?cr_fun_tuple_local(ir_WstringDef, IFR_storage_type),
411         ?cr_fun_tuple_local(ir_SequenceDef, IFR_storage_type),
412         ?cr_fun_tuple_local(ir_ArrayDef, IFR_storage_type),
413         ?cr_fun_tuple_local(ir_ExceptionDef, IFR_storage_type),
414         ?cr_fun_tuple_local(ir_AttributeDef, IFR_storage_type),
415         ?cr_fun_tuple_local(ir_OperationDef, IFR_storage_type),
416         ?cr_fun_tuple_local(ir_InterfaceDef, IFR_storage_type),
417%        ?cr_fun_tuple_local(ir_TypeCode, IFR_storage_type),
418         ?cr_fun_tuple_local(ir_ORB, IFR_storage_type),
419	 ?cr_fun_tuple_local(ir_FixedDef, IFR_storage_type)]).
420
421-define(ifr_light_record_tuple_list_local(IFR_storage_type),
422        [?cr_fun_tuple_local(orber_light_ifr, IFR_storage_type)]).
423