summaryrefslogtreecommitdiff
path: root/TAO/tao/CDR.cpp
blob: 407d04cbbcc57a12e651d7fc155ea3328e7a70d2 (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
// $Id$

// Portions of this file are:
// Copyright 1994-1995 by Sun Microsystems Inc.
// All Rights Reserved

// CDR:         Encode/Decode basic machine data types
//
// Implementation of OMG "Common Data Representation" (CDR) ... there
// are one routine each for byte/halfword/word/doubleword put/get,
// which adjust to establish "natural" alignment (the bulk of the
// code) and then put or get with byteswapping as needed.
//
// The implementation knows that native data formats are conformant
// with OMG-IDL's (and hence CDR's) size requirements, and relies on
// the fact that (for example) CORBA_Long is always four bytes long
// even if the environment's "int" is a different size.
//
//      char, octet                       8 bits (1 byte)
//      short, unsigned short            16 bits (2 bytes)
//      long, unsigned long, float       32 bits (4 bytes)
//      double, (unsigned) long long     64 bits (8 bytes)
//      long double                     128 bits (16 bytes)
//
// Moreover, this "knows" that the native 'char' represents ISO
// Latin/1 characters (an ASCII superset addressing Western European
// characters) and that "double" and "float" comply with the IEEE
// standards. (The "long double" may not be a native data type,
// though.)
//
// THREADING NOTE: "CDR" is a data structure which must be protected
// by external critical sections.

#include "ace/Timeprobe.h"
#include "tao/CDR.h"
#include "tao/ORB_Core.h"
#include "tao/singletons.h"
#include "tao/Environment.h"

#if !defined (__ACE_INLINE__)
# include "tao/CDR.i"
#endif /* ! __ACE_INLINE__ */

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

#if defined (ACE_ENABLE_TIMEPROBES)

static const char *TAO_CDR_Timeprobe_Description[] =
{
  "OutputCDR::ctor[1] - enter",
  "OutputCDR::ctor[1] - leave",
  "OutputCDR::ctor[2] - enter",
  "OutputCDR::ctor[2] - leave",
  "OutputCDR::ctor[3] - enter",
  "OutputCDR::ctor[3] - leave"
};

enum
{
  TAO_OUTPUT_CDR_CTOR1_ENTER = 2000,
  TAO_OUTPUT_CDR_CTOR1_LEAVE,
  TAO_OUTPUT_CDR_CTOR2_ENTER,
  TAO_OUTPUT_CDR_CTOR2_LEAVE,
  TAO_OUTPUT_CDR_CTOR3_ENTER,
  TAO_OUTPUT_CDR_CTOR3_LEAVE
};


// Setup Timeprobes
ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_CDR_Timeprobe_Description,
                                  TAO_OUTPUT_CDR_CTOR1_ENTER);

#endif /* ACE_ENABLE_TIMEPROBES */

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

TAO_OutputCDR::TAO_OutputCDR (size_t size,
                              int byte_order,
			                        ACE_Allocator *buffer_allocator,
			                        ACE_Allocator *data_block_allocator,
                              size_t memcpy_tradeoff)
  :  ACE_OutputCDR (size,
        byte_order,
        buffer_allocator 
          ? buffer_allocator 
          : TAO_ORB_Core_instance ()->output_cdr_buffer_allocator (),
        data_block_allocator
          ? data_block_allocator
          : TAO_ORB_Core_instance ()->output_cdr_dblock_allocator (),
        memcpy_tradeoff
          ? memcpy_tradeoff
          : TAO_ORB_Core_instance ()->orb_params ()->cdr_memcpy_tradeoff ())
{
  ACE_FUNCTION_TIMEPROBE (TAO_OUTPUT_CDR_CTOR1_ENTER);
}

TAO_OutputCDR::TAO_OutputCDR (char *data, 
                              size_t size,
                              int byte_order,
			                        ACE_Allocator *buffer_allocator,
			                        ACE_Allocator *data_block_allocator,
                              size_t memcpy_tradeoff)
  :  ACE_OutputCDR (data,
        size,
        byte_order,
        buffer_allocator 
          ? buffer_allocator 
          : TAO_ORB_Core_instance ()->output_cdr_buffer_allocator (),
        data_block_allocator
          ? data_block_allocator
          : TAO_ORB_Core_instance ()->output_cdr_dblock_allocator (),
        memcpy_tradeoff
          ? memcpy_tradeoff
          : TAO_ORB_Core_instance ()->orb_params ()->cdr_memcpy_tradeoff ())
{
  ACE_FUNCTION_TIMEPROBE (TAO_OUTPUT_CDR_CTOR2_ENTER);
}

TAO_OutputCDR::TAO_OutputCDR (ACE_Message_Block *data,
                              int byte_order,
                              size_t memcpy_tradeoff)
  :  ACE_OutputCDR (data,
        byte_order,
        memcpy_tradeoff
          ? memcpy_tradeoff
          : TAO_ORB_Core_instance ()->orb_params ()->cdr_memcpy_tradeoff ())
{ 
  ACE_FUNCTION_TIMEPROBE (TAO_OUTPUT_CDR_CTOR3_ENTER);
}

TAO_OutputCDR::~TAO_OutputCDR (void)
{
}

CORBA::TypeCode::traverse_status
TAO_OutputCDR::encode (CORBA::TypeCode_ptr tc,
                       const void *data,
                       const void *data2,
                       CORBA::Environment &TAO_IN_ENV)
{
  TAO_Marshal_Object *mobj =
    TAO_MARSHAL_FACTORY::instance ()->make_marshal_object (tc, 
                                                           TAO_IN_ENV);
  TAO_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP);

  if (!mobj)
    return CORBA::TypeCode::TRAVERSE_STOP;

  return mobj->encode (tc, data, data2, this, TAO_IN_ENV);
}

CORBA::Boolean
operator<< (TAO_OutputCDR& cdr, const CORBA::Any &x)
{
  // @@ This function should *not* use the interpreter, there must be
  // a way to do this with just CDR operations!!!!
  TAO_TRY
    {
      CORBA::TypeCode::traverse_status status =
        TAO_MARSHAL_ANY::instance ()->encode (0, 
                                              &x, 
                                              0, 
                                              &cdr, 
                                              TAO_TRY_ENV);
      TAO_CHECK_ENV;

      if (status== CORBA::TypeCode::TRAVERSE_CONTINUE)
        return 1;
      // else return 0 at the end of the function
    }
  TAO_CATCH (CORBA_Exception, ex)
    {
      return 0;
    }
  TAO_ENDTRY;
  return 0;
}

CORBA::Boolean
operator<< (TAO_OutputCDR& cdr, const CORBA::Object *x)
{
  TAO_TRY
    {
      // @@ This function should *not* use the interpreter, there must
      // be a way to do this with just CDR operations!!!!
      CORBA::TypeCode::traverse_status status =
        TAO_MARSHAL_OBJREF::instance ()->encode (0, 
                                                 &x, 
                                                 0, 
                                                 &cdr, 
                                                 TAO_TRY_ENV);
      TAO_CHECK_ENV;

      if (status == CORBA::TypeCode::TRAVERSE_CONTINUE)
        return 1;
      // else return 0 at the end of the function
    }
  TAO_CATCH (CORBA_Exception, ex)
    {
      return 0;
    }
  TAO_ENDTRY;
  return 0;
}

CORBA::Boolean
operator<< (TAO_OutputCDR& cdr, const CORBA::TypeCode *x)
{
  TAO_TRY
    {
      // @@ This function should *not* use the interpreter, there must
      // be a way to do this with just CDR operations!!!!
      CORBA::TypeCode::traverse_status status =
        TAO_MARSHAL_TYPECODE::instance ()->encode (0, 
                                                   &x, 
                                                   0, 
                                                   &cdr, 
                                                   TAO_TRY_ENV);
      TAO_CHECK_ENV;

      if (status == CORBA::TypeCode::TRAVERSE_CONTINUE)
        return 1;
      // else return 0 at the end of the function
    }
  TAO_CATCH (CORBA_Exception, ex)
    {
      return 0;
    }
  TAO_ENDTRY;
  return 0;
}

CORBA::TypeCode::traverse_status
TAO_OutputCDR::append (CORBA::TypeCode_ptr tc,
                       TAO_InputCDR *src,
                       CORBA::Environment &TAO_IN_ENV)
{
  TAO_Marshal_Object *mobj =
    TAO_MARSHAL_FACTORY::instance ()->make_marshal_object (tc, 
                                                           TAO_IN_ENV);
  TAO_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP);

  if (mobj == 0)
    return CORBA::TypeCode::TRAVERSE_STOP;

  return mobj->append (tc, src, this, TAO_IN_ENV);
}

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

TAO_InputCDR::TAO_InputCDR (const char *buf, 
                            size_t bufsiz,
                            int byte_order)
  : ACE_InputCDR (buf,
                  bufsiz,
                  byte_order)
{
}

TAO_InputCDR::TAO_InputCDR (size_t bufsiz,
                            int byte_order)
  : ACE_InputCDR (bufsiz,
                  byte_order)
{
}

TAO_InputCDR::TAO_InputCDR (ACE_Message_Block *data,
                            int byte_order)
  : ACE_InputCDR (data,
                  byte_order)
{
}

TAO_InputCDR::TAO_InputCDR (ACE_Data_Block *data,
                            int byte_order)
  : ACE_InputCDR (data,
                  byte_order)
{
}

TAO_InputCDR::TAO_InputCDR (const TAO_InputCDR& rhs,
                            size_t size,
                            CDR::Long offset)
  : ACE_InputCDR (rhs,
                  size,
                  offset)
{
}

TAO_InputCDR::TAO_InputCDR (const TAO_InputCDR& rhs,
                            size_t size)
  : ACE_InputCDR (rhs,
                  size)
{
}

TAO_InputCDR::TAO_InputCDR (const TAO_InputCDR& rhs)
  : ACE_InputCDR (rhs)
{
}

TAO_InputCDR::TAO_InputCDR (const TAO_OutputCDR& rhs,
                            ACE_Allocator* buffer_allocator,
                            ACE_Allocator* data_block_allocator)
  : ACE_InputCDR (rhs,
        buffer_allocator
          ? buffer_allocator 
          : TAO_ORB_Core_instance ()->output_cdr_buffer_allocator (),
        data_block_allocator
          ? data_block_allocator
          : TAO_ORB_Core_instance ()->output_cdr_dblock_allocator ())
{
}

TAO_InputCDR::~TAO_InputCDR (void)
{
}

CORBA::TypeCode::traverse_status
TAO_InputCDR::decode (CORBA::TypeCode_ptr tc,
                      const void *data,
                      const void *data2,
                      CORBA::Environment &TAO_IN_ENV)
{
  TAO_Marshal_Object *mobj =
    TAO_MARSHAL_FACTORY::instance ()->make_marshal_object (tc, 
                                                           TAO_IN_ENV);
  TAO_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP);

  if (!mobj)
    return CORBA::TypeCode::TRAVERSE_STOP;

  return mobj->decode (tc, data, data2, this, TAO_IN_ENV);
}

CORBA::TypeCode::traverse_status
TAO_InputCDR::skip (CORBA::TypeCode_ptr tc,
                    CORBA::Environment &TAO_IN_ENV)
{
  TAO_Marshal_Object *mobj =
    TAO_MARSHAL_FACTORY::instance ()->make_marshal_object (tc, 
                                                           TAO_IN_ENV);
  TAO_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP);

  if (mobj == 0)
    return CORBA::TypeCode::TRAVERSE_STOP;

  return mobj->skip (tc, this, TAO_IN_ENV);
}

CORBA::Boolean
operator>> (TAO_InputCDR& cdr, CORBA::Any &x)
{
  TAO_TRY
    {
      CORBA::TypeCode::traverse_status status =
        TAO_MARSHAL_ANY::instance ()->decode (0, 
                                              &x, 
                                              0, 
                                              &cdr, 
                                              TAO_TRY_ENV);
      TAO_CHECK_ENV;

      if (status != CORBA::TypeCode::TRAVERSE_CONTINUE)
        return 0;
    }
  TAO_CATCH (CORBA_Exception, ex)
    {
      return 0;
    }
  TAO_ENDTRY;

  return 1;
}

CORBA::Boolean
operator>> (TAO_InputCDR& cdr, CORBA::Object *&x)
{
  TAO_TRY
    {
      CORBA::TypeCode::traverse_status status =
        TAO_MARSHAL_OBJREF::instance ()->decode (0, 
                                                 &x, 
                                                 0, 
                                                 &cdr, 
                                                 TAO_TRY_ENV);
      TAO_CHECK_ENV;

      if (status != CORBA::TypeCode::TRAVERSE_CONTINUE)
        return 0;
    }
  TAO_CATCH (CORBA_Exception, ex)
    {
      return 0;
    }
  TAO_ENDTRY;

  return 1;
}

CORBA::Boolean
operator>> (TAO_InputCDR& cdr, CORBA::TypeCode *&x)
{
  TAO_TRY
    {
      CORBA::TypeCode::traverse_status status =
        TAO_MARSHAL_TYPECODE::instance ()->decode (0, 
                                                   &x, 
                                                   0, 
                                                   &cdr, 
                                                   TAO_TRY_ENV);
      TAO_CHECK_ENV;

      if (status != CORBA::TypeCode::TRAVERSE_CONTINUE)
        return 0;
    }
  TAO_CATCH (CORBA_Exception, ex)
    {
      return 0;
    }
  TAO_ENDTRY;

  return 1;
}