summaryrefslogtreecommitdiff
path: root/TAO/tao/Typecode_Constants.cpp
blob: d842c1532216991b5e27aafb3179d7c9c0000e25 (plain)
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO
//
// = FILENAME
//    Typecode_Constants.cpp
//
// = DESCRIPTION
//   All the CORBA-specified typecode constants.
//
//   NOTE:  IFR TypeCode constants aren't here; they're left for an IDL
//   compiler to generate from the appropriate IDL source.
//
//   NOTE:  it'd be nice to have these not use init sections.  Most can easily
//   be in readonly data (e.g. text segment, ROM) rather than writable data;
//   that speeds program startup and page sharing in shared libraries.
//
//   THREADING NOTE:  no issues, these are immutable constants
//
// = AUTHOR
//     Copyright 1994-1995 by Sun Microsystems Inc.
//     and Aniruddha Gokhale
//
// ============================================================================

#include "tao/Typecode_Constants.h"
#include "tao/Typecode.h"
#include "tao/NVList.h"
#include "tao/ORB.h"
#include "tao/Object.h"
#include "tao/SystemException.h"

#if defined (TAO_HAS_AMI_POLLER) && (TAO_HAS_AMI_POLLER == 1)
#include "tao/PollableC.h"
#endif /* TAO_HAS_AMI_POLLER == 1 */

ACE_RCSID (tao,
           Typecode_Constants,
           "$Id$")

// Declare all the standard typecodes owned by the ORB

// Null and void
namespace CORBA
{
  TypeCode_ptr  _tc_null = 0;
  TypeCode_ptr  _tc_void = 0;

  // Basic numeric types:  short, long, longlong, and unsigned
  // variants

  TypeCode_ptr  _tc_short = 0;
  TypeCode_ptr  _tc_long = 0;
  TypeCode_ptr  _tc_longlong = 0;
  TypeCode_ptr  _tc_ushort = 0;
  TypeCode_ptr  _tc_ulong = 0;
  TypeCode_ptr  _tc_ulonglong = 0;

  // Floating point types: single, double, quad precision
  TypeCode_ptr  _tc_float = 0;
  TypeCode_ptr  _tc_double = 0;
  TypeCode_ptr  _tc_longdouble = 0;

  // Various simple quantities.
  TypeCode_ptr  _tc_boolean = 0;
  TypeCode_ptr  _tc_octet = 0;

  // Internationalization-related data types: ISO Latin/1 and "wide"
  // characters, and strings of each.  "wchar" is probably Unicode 1.1,
  // "wstring" being null-terminated sets thereof.
  TypeCode_ptr  _tc_char = 0;
  TypeCode_ptr  _tc_wchar = 0;

  // a string/wstring have a simple parameter list that indicates the
  // length
  TypeCode_ptr  _tc_string = 0;
  TypeCode_ptr  _tc_wstring = 0;

  //
  // Various things that can be passed as "general" parameters:
  // Any, TypeCode_ptr  Principal_ptr, Object_ptr
  //
  TypeCode_ptr  _tc_any = 0;
  TypeCode_ptr  _tc_TypeCode = 0;
  TypeCode_ptr  _tc_Principal = 0;
  TypeCode_ptr  _tc_Object = 0;

  // Two typecodes for exceptions
  TypeCode_ptr CORBA::TypeCode::_tc_Bounds = 0;
  TypeCode_ptr CORBA::TypeCode::_tc_BadKind = 0;
  TypeCode_ptr  _tc_exception_type = 0;

  // Some more typecodes in the CORBA namespace. We keep adding
  // to this list as we find more and more things being introduced
  // to the CORBA namespace.
  TypeCode_ptr  _tc_ORBid = 0;

#if (TAO_HAS_MINIMUM_CORBA == 0)
     TypeCode_ptr  _tc_NamedValue = 0;
#endif /* TAO_HAS_MINIMUM_CORBA */
} // End namespace CORBA

namespace TAO
{
  // Internal to TAO ORB
  CORBA::TypeCode_ptr TC_opaque = 0;
  CORBA::TypeCode_ptr TC_completion_status = 0;

  // Flag that denotes that the TAO TypeCode constants have been
  // initialized.
  int TypeCode_Constants::initialized_ = 0;

  // Initialize all the ORB owned TypeCode constants. This routine will
  // be invoked by the ORB_init method.
  void
  TypeCode_Constants::init (void)
  {
    // Initialize all the standard typecodes owned by the ORB

    // Not thread safe.  Caller must provide synchronization.

    // Do not execute code after this point more than once.
    if (initialized_ != 0)
      {
        return;
      }

    initialized_ = 1;

    // Null and void.
    ACE_NEW (CORBA::_tc_null,
             CORBA::TypeCode (CORBA::tk_null));

    ACE_NEW (CORBA::_tc_void,
             CORBA::TypeCode (CORBA::tk_void));

    // Basic numeric types:  short, long, longlong, and unsigned variants.
    ACE_NEW (CORBA::_tc_short,
             CORBA::TypeCode (CORBA::tk_short));

    ACE_NEW (CORBA::_tc_long,
             CORBA::TypeCode (CORBA::tk_long));

    ACE_NEW (CORBA::_tc_longlong,
             CORBA::TypeCode (CORBA::tk_longlong));

    ACE_NEW (CORBA::_tc_ushort,
             CORBA::TypeCode (CORBA::tk_ushort));

    ACE_NEW (CORBA::_tc_ulong,
             CORBA::TypeCode (CORBA::tk_ulong));

    ACE_NEW (CORBA::_tc_ulonglong,
             CORBA::TypeCode (CORBA::tk_ulonglong));

    // Floating point types: single, double, quad precision.
    ACE_NEW (CORBA::_tc_float,
             CORBA::TypeCode (CORBA::tk_float));

    ACE_NEW (CORBA::_tc_double,
             CORBA::TypeCode (CORBA::tk_double));

    ACE_NEW (CORBA::_tc_longdouble,
             CORBA::TypeCode (CORBA::tk_longdouble));

    // Various simple quantities.
    ACE_NEW (CORBA::_tc_boolean,
             CORBA::TypeCode (CORBA::tk_boolean));

    ACE_NEW (CORBA::_tc_octet,
             CORBA::TypeCode (CORBA::tk_octet));

    // Internationalization-related data types: ISO Latin/1 and "wide"
    // characters, and strings of each.  "wchar" is probably Unicode 1.1,
    // "wstring" being null-terminated sets thereof.
    ACE_NEW (CORBA::_tc_char,
             CORBA::TypeCode (CORBA::tk_char));

    ACE_NEW (CORBA::_tc_wchar,
             CORBA::TypeCode (CORBA::tk_wchar));

    // A string/wstring have a simple parameter list that
    // indicates the length.
    static const CORBA::Long _oc_string [] =
    {
      // CDR typecode octets
      TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky"
      0                     // ... unbounded string
    };

    ACE_NEW (CORBA::_tc_string,
             CORBA::TypeCode (CORBA::tk_string,
                              sizeof _oc_string,
                              (char*)&_oc_string,
                              1,
                              sizeof (CORBA::String_var)));

    static const CORBA::Long _oc_wstring [] =
    {
      // CDR typecode octets
      TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky"
      0                     // ... unbounded string
    };

    ACE_NEW (CORBA::_tc_wstring,
             CORBA::TypeCode (CORBA::tk_wstring,
                              sizeof _oc_wstring,
                              (char *) &_oc_wstring,
                              1,
                              sizeof (CORBA::WChar*)));

    //
    // Various things that can be passed as "general" parameters:
    // Any, TypeCode_ptr, Principal_ptr, Object_ptr
    //
    ACE_NEW (CORBA::_tc_any,
             CORBA::TypeCode (CORBA::tk_any));

    ACE_NEW (CORBA::_tc_TypeCode,
             CORBA::TypeCode (CORBA::tk_TypeCode));

    ACE_NEW (CORBA::_tc_Principal,
             CORBA::TypeCode (CORBA::tk_Principal));

    // typecode for objref is complex, has two string parameters
    //
    // NOTE:  Must be four-byte aligned

    static const CORBA::Long _oc_CORBA_Object[] =
    {
      TAO_ENCAP_BYTE_ORDER, // byte order
      29,
      ACE_NTOHL (0x49444c3a),
      ACE_NTOHL (0x6f6d672e),
      ACE_NTOHL (0x6f72672f),
      ACE_NTOHL (0x434f5242),
      ACE_NTOHL (0x412f4f62),
      ACE_NTOHL (0x6a656374),
      ACE_NTOHL (0x3a312e30),
      ACE_NTOHL (0x0),  // repository ID = IDL:omg.org/CORBA/Object:1.0
      7,
      ACE_NTOHL (0x4f626a65),
      ACE_NTOHL (0x63740000),  // name = Object
    };

    ACE_NEW (CORBA::_tc_Object,
             CORBA::TypeCode (CORBA::tk_objref,
                              sizeof (_oc_CORBA_Object),
                              (char *) &_oc_CORBA_Object,
                              1,
                              sizeof (CORBA::Object)));

    // Static initialization of the two user-defined exceptions that
    // are part of the ORB.

    static const CORBA::Long _oc_CORBA_TypeCode_Bounds[] =
    {
      TAO_ENCAP_BYTE_ORDER, // byte order
      38,
      ACE_NTOHL (0x49444c3a),
      ACE_NTOHL (0x6f6d672e),
      ACE_NTOHL (0x6f72672f),
      ACE_NTOHL (0x434f5242),
      ACE_NTOHL (0x412f5479),
      ACE_NTOHL (0x7065436f),
      ACE_NTOHL (0x64652f42),
      ACE_NTOHL (0x6f756e64),
      ACE_NTOHL (0x733a312e),
      ACE_NTOHL (0x30000000),  // repository ID = IDL:omg.org/CORBA/TypeCode/Bounds:1.0
      7,
      ACE_NTOHL (0x426f756e),
      ACE_NTOHL (0x64730000),  // name = Bounds
      0, // member count
    };

    ACE_NEW (CORBA::TypeCode::_tc_Bounds,
             CORBA::TypeCode (CORBA::tk_except,
                              sizeof (_oc_CORBA_TypeCode_Bounds),
                              (char*) &_oc_CORBA_TypeCode_Bounds,
                              1,
                              sizeof (CORBA::TypeCode::Bounds)));


    static const CORBA::Long _oc_CORBA_TypeCode_BadKind[] =
    {
      TAO_ENCAP_BYTE_ORDER, // byte order
      39,
      ACE_NTOHL (0x49444c3a),
      ACE_NTOHL (0x6f6d672e),
      ACE_NTOHL (0x6f72672f),
      ACE_NTOHL (0x434f5242),
      ACE_NTOHL (0x412f5479),
      ACE_NTOHL (0x7065436f),
      ACE_NTOHL (0x64652f42),
      ACE_NTOHL (0x61644b69),
      ACE_NTOHL (0x6e643a31),
      ACE_NTOHL (0x2e300000),  // repository ID = IDL:omg.org/CORBA/TypeCode/BadKind:1.0
      8,
      ACE_NTOHL (0x4261644b),
      ACE_NTOHL (0x696e6400),  // name = BadKind
      0, // member count
    };

    ACE_NEW (CORBA::TypeCode::_tc_BadKind,
             CORBA::TypeCode (CORBA::tk_except,
                              sizeof (_oc_CORBA_TypeCode_BadKind),
                              (char*) &_oc_CORBA_TypeCode_BadKind,
                              1,
                              sizeof (CORBA::TypeCode::BadKind)));

    static const CORBA::Long _oc_CORBA_ORBid[] =
    {
      TAO_ENCAP_BYTE_ORDER, // byte order
      28, ACE_NTOHL (0x49444c3a),
      ACE_NTOHL (0x6f6d672e),
      ACE_NTOHL (0x6f72672f),
      ACE_NTOHL (0x434f5242),
      ACE_NTOHL (0x412f4f52),
      ACE_NTOHL (0x4269643a),
      ACE_NTOHL (0x312e3000),  // repository ID = IDL:omg.org/CORBA/ORBid:1.0
      6,
      ACE_NTOHL (0x4f524269),
      ACE_NTOHL (0x64000000),  // name = ORBid
      CORBA::tk_string,
      0, // string length
    };

    ACE_NEW (CORBA::_tc_ORBid,
             CORBA::TypeCode (CORBA::tk_alias,
                              sizeof (_oc_CORBA_ORBid),
                              (char *) &_oc_CORBA_ORBid,
                              0,
                              sizeof (CORBA::ORBid)));

  #if (TAO_HAS_MINIMUM_CORBA == 0)

    static const CORBA::Long _oc_corba_NamedValue[] =
    {
      TAO_ENCAP_BYTE_ORDER,     // byte order
      33,
      ACE_NTOHL (0x49444c3a),
      ACE_NTOHL (0x6f6d672e),
      ACE_NTOHL (0x6f72672f),
      ACE_NTOHL (0x636f7262),
      ACE_NTOHL (0x612f4e61),
      ACE_NTOHL (0x6d656456),
      ACE_NTOHL (0x616c7565),
      ACE_NTOHL (0x3a312e30),
      ACE_NTOHL (0x0),          // repository ID =
                                //   IDL:omg.org/corba/NamedValue:1.0
      11,
      ACE_NTOHL (0x4e616d65),
      ACE_NTOHL (0x6456616c),
      ACE_NTOHL (0x75650000),  // name = NamedValue,
    };

    ACE_NEW (CORBA::_tc_NamedValue,
             CORBA::TypeCode (CORBA::tk_objref,
                              sizeof (_oc_corba_NamedValue),
                              (char *) &_oc_corba_NamedValue,
                              0,
                              sizeof (CORBA::NamedValue)));

  #endif /* TAO_HAS_MINIMUM_CORBA */

   // ****************************************************************

   // The following are internal to the TAO ORB

    // Octet codes for the parameters of the "Opaque" (sequence of octet)
    // data type used various places internally ... a CDR encapsulation
    // holding two parameters (like all sequence TypeCodes).
    //
    // NOTE: this **MUST** be longword aligned, which is why it's coded as
    // a longword array not an octet array.  Just sticking a long in for
    // padding won't work with compilers that optimize unused data out of
    // existence.

    // CDR typecode octets.

    typedef TAO_Unbounded_Sequence<CORBA::Octet> TAO_opaque;

    static const CORBA::Long _oc_opaque [] =
    {

      TAO_ENCAP_BYTE_ORDER,    // native endian + padding; "tricky"
      10,                      // ... (sequence of) octets
      0                        // ... unbounded
    };

    ACE_NEW (TC_opaque,
             CORBA::TypeCode (CORBA::tk_sequence,
                              sizeof _oc_opaque,
                              (char *) &_oc_opaque,
                              1,
                              sizeof (TAO_opaque)));

    // Octet codes for the parameters of the ServiceContextList TypeCode
    // ...  this is a CDR encapsulation holding two parameters (like all
    // sequences): a TypeCode, and the bounds of the sequence (zero in
    // this case).
    //
    // This is complicated since the Typecode for the data type for the
    // sequence members is complex, a structure that nests two further
    // typecodes (one is a sequence).
    //
    // NOTE:  this must be longword aligned!

    static const CORBA::ULong oc_completion_status [] =
    {
      TAO_ENCAP_BYTE_ORDER, // byte order flag, tricky
      0, 0,                 // type ID omitted
      3,                    // three members
      0, 0,                 // ... whose names are all omitted
      0, 0,
      0, 0
    };

    ACE_NEW (TC_completion_status,
             CORBA::TypeCode (CORBA::tk_enum,
                              sizeof oc_completion_status,
                              (char *) &oc_completion_status,
                              1,
                              sizeof (CORBA::CompletionStatus)));
  }

  // Destroy all the typecodes owned by the ORB.
  void
  TypeCode_Constants::fini (void)
  {
    // Release all the standard typecodes owned by the ORB.

    // Null and void.
    CORBA::release (CORBA::_tc_null);

    CORBA::release (CORBA::_tc_void);

    // Basic numeric types:  short, long, longlong, and unsigned variants
    CORBA::release (CORBA::_tc_short);

    CORBA::release (CORBA::_tc_long);

    CORBA::release (CORBA::_tc_longlong);

    CORBA::release (CORBA::_tc_ushort);

    CORBA::release (CORBA::_tc_ulong);

    CORBA::release (CORBA::_tc_ulonglong);

    // Floating point types: single, double, quad precision
    CORBA::release (CORBA::_tc_float);

    CORBA::release (CORBA::_tc_double);

    CORBA::release (CORBA::_tc_longdouble);

    // Various simple quantities.
    CORBA::release (CORBA::_tc_boolean);

    CORBA::release (CORBA::_tc_octet);

    // Internationalization-related data types: ISO Latin/1 and "wide"
    // characters, and strings of each.  "wchar" is probably Unicode 1.1,
    // "wstring" being null-terminated sets thereof.
    CORBA::release (CORBA::_tc_char);

    CORBA::release (CORBA::_tc_wchar);

    // A string/wstring have a simple parameter list that
    // indicates the length.
    CORBA::release (CORBA::_tc_string);

    CORBA::release (CORBA::_tc_wstring);

    //
    // Various things that can be passed as "general" parameters:
    // Any, TypeCode_ptr, Principal_ptr, Object_ptr
    //
    CORBA::release (CORBA::_tc_any);

    CORBA::release (CORBA::_tc_TypeCode);

    CORBA::release (CORBA::_tc_Principal);

    // typecode for objref is complex, has two string parameters
    //
    CORBA::release (CORBA::_tc_Object);

    // other ORB owned typecodes
    CORBA::release (CORBA::TypeCode::_tc_Bounds);

    CORBA::release (CORBA::TypeCode::_tc_BadKind);

    CORBA::release (CORBA::_tc_ORBid);

  #if (TAO_HAS_MINIMUM_CORBA == 0)

    CORBA::release (CORBA::_tc_NamedValue);

  #endif /* TAO_HAS_MINIMUM_CORBA */

    // TAO specific
    CORBA::release (TC_opaque);

    CORBA::release (TC_completion_status);
  }
} // end namespace TAO