File: Name_Request_Reply.cpp

package info (click to toggle)
ace 6.4.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 48,640 kB
  • ctags: 41,204
  • sloc: cpp: 336,448; perl: 33,068; ansic: 20,676; sh: 3,735; exp: 787; python: 635; yacc: 511; xml: 330; lex: 158; lisp: 116; makefile: 80; csh: 20; tcl: 5
file content (574 lines) | stat: -rw-r--r-- 14,918 bytes parent folder | download | duplicates (3)
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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
#include "ace/Name_Request_Reply.h"
#include "ace/Basic_Types.h"
#include "ace/CDR_Base.h"
#include "ace/Log_Category.h"
#include "ace/Time_Value.h"
#include "ace/Truncate.h"
#include "ace/OS_NS_string.h"
#include "ace/os_include/arpa/os_inet.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

// Default "do nothing" constructor.

ACE_Name_Request::ACE_Name_Request (void)
{
  ACE_TRACE ("ACE_Name_Request::ACE_Name_Request");
}

// Create a ACE_Name_Request message.

ACE_Name_Request::ACE_Name_Request (
  ACE_INT32 t, // Type of request.
  const ACE_WCHAR_T name[], // Name
  const ACE_UINT32 name_length, // size in bytes
  const ACE_WCHAR_T value[], //
  const ACE_UINT32 value_length, // size in bytes
  const char type[], //
  const ACE_UINT32 type_length, // size in bytes
  ACE_Time_Value *timeout) // Max time waiting for request.
{
  ACE_TRACE ("ACE_Name_Request::ACE_Name_Request");
  this->msg_type (t);
  this->name_len (name_length);
  this->value_len (value_length);
  this->type_len (type_length);

  // If timeout is a NULL pointer, then block forever...
  if (timeout == 0)
    {
      this->transfer_.block_forever_ = 1;
      this->transfer_.sec_timeout_   = 0;
      this->transfer_.usec_timeout_  = 0;
    }
  else // Do a "timed wait."
    {
      this->block_forever (0);
      // Keep track of how long client is willing to wait.
      this->transfer_.sec_timeout_ = timeout->sec ();
      this->transfer_.usec_timeout_ =
        static_cast<ACE_UINT32> (timeout->usec ());
    }

  // Set up pointers and copy name value and type into request.
  this->name_ = this->transfer_.data_;
  this->value_  = &this->name_[name_length / sizeof (ACE_WCHAR_T) ];
  this->type_  = (char *)(&this->value_[value_length / sizeof (ACE_WCHAR_T)]); //

  (void) ACE_OS::memcpy (this->name_,
                         name,
                         name_length);
  (void) ACE_OS::memcpy (this->value_,
                         value,
                         value_length);
  (void) ACE_OS::memcpy (this->type_,
                         type,
                         type_length);

  // Compute size of the fixed portion of the message...
  size_t len = sizeof this->transfer_ - sizeof this->transfer_.data_;

  // ... then add in the amount of the variable-sized portion.
  len += name_length + value_length + type_length ;

  this->length (static_cast<ACE_UINT32> (len));
}

// Initialize length_ in order to avoid problems with byte-ordering.

void
ACE_Name_Request::init (void)
{
  ACE_TRACE ("ACE_Name_Request::init");
  this->length (sizeof this->transfer_);
}

// = Set/get the length of the encoded/decoded message.

ACE_UINT32
ACE_Name_Request::length (void) const
{
  ACE_TRACE ("ACE_Name_Request::length");
  return this->transfer_.length_;
}

void
ACE_Name_Request::length (ACE_UINT32 l)
{
  ACE_TRACE ("ACE_Name_Request::length");
  this->transfer_.length_ = l;
}

// = Set/get the type of the message.

ACE_INT32
ACE_Name_Request::msg_type (void) const
{
  ACE_TRACE ("ACE_Name_Request::msg_type");
  return this->transfer_.msg_type_;
}

void
ACE_Name_Request::msg_type (ACE_INT32 t)
{
  ACE_TRACE ("ACE_Name_Request::msg_type");
  this->transfer_.msg_type_ = t;
}

// = Set/get the len of the name

ACE_UINT32
ACE_Name_Request::name_len (void) const
{
  ACE_TRACE ("ACE_Name_Request::name_len");
  return this->transfer_.name_len_;
}

void
ACE_Name_Request::name_len (ACE_UINT32 t)
{
  ACE_TRACE ("ACE_Name_Request::name_len");
  this->transfer_.name_len_ = t;
}

// = Set/get the len of the value

ACE_UINT32
ACE_Name_Request::value_len (void) const
{
  ACE_TRACE ("ACE_Name_Request::value_len");
  return this->transfer_.value_len_;
}

void
ACE_Name_Request::value_len (ACE_UINT32 t)
{
  ACE_TRACE ("ACE_Name_Request::value_len");
  this->transfer_.value_len_ = t;
}

// = Set/get the len of the type

ACE_UINT32
ACE_Name_Request::type_len (void) const
{
  ACE_TRACE ("ACE_Name_Request::type_len");
  return this->transfer_.type_len_;
}

void
ACE_Name_Request::type_len (ACE_UINT32 t)
{
  ACE_TRACE ("ACE_Name_Request::type_len");
  this->transfer_.type_len_ = t;
}

// = Set/get the blocking semantics.

ACE_UINT32
ACE_Name_Request::block_forever (void) const
{
  ACE_TRACE ("ACE_Name_Request::block_forever");
  return this->transfer_.block_forever_;
}

void
ACE_Name_Request::block_forever (ACE_UINT32 bs)
{
  ACE_TRACE ("ACE_Name_Request::block_forever");
  this->transfer_.block_forever_ = bs;
}

// = Set/get the timeout.

ACE_Time_Value
ACE_Name_Request::timeout (void) const
{
  ACE_TRACE ("ACE_Name_Request::timeout");
  time_t sec = ACE_Utils::truncate_cast<time_t> (this->transfer_.sec_timeout_);
  return ACE_Time_Value (sec, this->transfer_.usec_timeout_);
}

void
ACE_Name_Request::timeout (const ACE_Time_Value timeout)
{
  ACE_TRACE ("ACE_Name_Request::timeout");
  this->transfer_.sec_timeout_ = timeout.sec ();
  this->transfer_.usec_timeout_ = static_cast<ACE_UINT32> (timeout.usec ());
}

// = Set/get the name

const ACE_WCHAR_T *
ACE_Name_Request::name (void) const
{
  ACE_TRACE ("ACE_Name_Request::name");
  return this->name_;
}

void
ACE_Name_Request::name (const ACE_WCHAR_T *t)
{
  ACE_TRACE ("ACE_Name_Request::name");
  (void) ACE_OS::memcpy (this->name_,
                         t,
                         this->name_len ());
}

// = Set/get the value

const ACE_WCHAR_T *
ACE_Name_Request::value (void) const
{
  ACE_TRACE ("ACE_Name_Request::value");
  return this->value_;
}

void
ACE_Name_Request::value (const ACE_WCHAR_T *c)
{
  ACE_TRACE ("ACE_Name_Request::value");

  (void) ACE_OS::memcpy (this->value_,
                         c,
                         this->value_len());
}

// = Set/get the type

const char *
ACE_Name_Request::type (void) const
{
  ACE_TRACE ("ACE_Name_Request::type");
  return this->type_;
}

void
ACE_Name_Request::type (const char *c)
{
  ACE_TRACE ("ACE_Name_Request::type");
  ACE_OS::strsncpy (this->type_,
                    c,
                    sizeof this->type_);
}

// Encode the transfer buffer into network byte order so that it can
// be sent to the server.

int
ACE_Name_Request::encode (void *&buf)
{
  ACE_TRACE ("ACE_Name_Request::encode");
  // Compute the length *before* doing the marshaling.

  ACE_UINT32 len = this->length ();

  size_t nv_data_len =
    (this->transfer_.name_len_ + this->transfer_.value_len_)
    / sizeof (ACE_WCHAR_T);

  for (size_t i = 0; i < nv_data_len; i++)
    this->transfer_.data_[i] =
      static_cast<ACE_WCHAR_T> (ACE_HTONS (this->transfer_.data_[i]));

  buf = (void *) &this->transfer_;
  this->transfer_.block_forever_ = ACE_HTONL (this->transfer_.block_forever_);
  this->transfer_.usec_timeout_  = ACE_HTONL (this->transfer_.usec_timeout_);
#if defined (ACE_LITTLE_ENDIAN)
  ACE_UINT64 secs = this->transfer_.sec_timeout_;
  ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.sec_timeout_);
#endif
  this->transfer_.length_ = ACE_HTONL (this->transfer_.length_);
  this->transfer_.msg_type_ = ACE_HTONL (this->transfer_.msg_type_);
  this->transfer_.name_len_ = ACE_HTONL (this->transfer_.name_len_);
  this->transfer_.value_len_ = ACE_HTONL (this->transfer_.value_len_);
  this->transfer_.type_len_ = ACE_HTONL (this->transfer_.type_len_);

  return len;
}

// Decode the transfer buffer into host byte byte order so that it can
// be used by the server.

int
ACE_Name_Request::decode (void)
{
  ACE_TRACE ("ACE_Name_Request::decode");
  // Decode the fixed-sized portion first.
  this->transfer_.block_forever_ = ACE_NTOHL (this->transfer_.block_forever_);
  this->transfer_.usec_timeout_  = ACE_NTOHL (this->transfer_.usec_timeout_);
#if defined (ACE_LITTLE_ENDIAN)
  ACE_UINT64 secs = this->transfer_.sec_timeout_;
  ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.sec_timeout_);
#endif
  this->transfer_.length_ = ACE_NTOHL (this->transfer_.length_);
  this->transfer_.msg_type_ = ACE_NTOHL (this->transfer_.msg_type_);
  this->transfer_.name_len_ = ACE_NTOHL (this->transfer_.name_len_);
  this->transfer_.value_len_ = ACE_NTOHL (this->transfer_.value_len_);
  this->transfer_.type_len_ = ACE_NTOHL (this->transfer_.type_len_);

  size_t nv_data_len =
    (this->transfer_.name_len_ + this->transfer_.value_len_)
    / sizeof (ACE_WCHAR_T);

  for (size_t i = 0; i < nv_data_len; i++)
    this->transfer_.data_[i] =
      static_cast<ACE_WCHAR_T> (ACE_NTOHS (this->transfer_.data_[i]));

  this->name_ = this->transfer_.data_;
  this->value_ = &this->name_[this->transfer_.name_len_ / sizeof (ACE_WCHAR_T)];
  this->type_ = (char *)(&this->value_[this->transfer_.value_len_ / sizeof (ACE_WCHAR_T)]);
  this->type_[this->transfer_.type_len_] = '\0';

  // Decode the variable-sized portion.
  return 0;
}

// Print out the current values of the ACE_Name_Request.

void
ACE_Name_Request::dump (void) const
{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_Name_Request::dump");
  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("*******\nlength = %d\n"),
              this->length ()));
  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("message-type = ")));

  switch (this->msg_type ())
    {
    case ACE_Name_Request::BIND:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("BIND\n")));
      break;
    case ACE_Name_Request::REBIND:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("REBIND\n")));
      break;
    case ACE_Name_Request::RESOLVE:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("RESOLVE\n")));
      break;
    case ACE_Name_Request::UNBIND:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("UNBIND\n")));
      break;
    case ACE_Name_Request::LIST_NAMES:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("LIST_NAMES\n")));
      break;
    case ACE_Name_Request::LIST_VALUES:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("LIST_VALUES\n")));
      break;
    case ACE_Name_Request::LIST_TYPES:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("LIST_TYPES\n")));
      break;
    case ACE_Name_Request::LIST_NAME_ENTRIES:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("LIST_NAME_ENTRIES\n")));
      break;
    case ACE_Name_Request::LIST_VALUE_ENTRIES:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("LIST_VALUE_ENTRIES\n")));
      break;
    case ACE_Name_Request::LIST_TYPE_ENTRIES:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("LIST_TYPE_ENTRIES\n")));
      break;
    default:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("<unknown type> = %d\n"),
                  this->msg_type ()));
      break;
    }

  if (this->block_forever ())
    ACELIB_DEBUG ((LM_DEBUG,
                ACE_TEXT ("blocking forever\n")));
  else
    {
#if !defined (ACE_NLOGGING)
      ACE_Time_Value tv = this->timeout ();
#endif /* ! ACE_NLOGGING */
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("waiting for %d secs and %d usecs\n"),
                  tv.sec (),
                  tv.usec ()));
    }
  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("*******\nname_len = %d\n"),
              this->name_len ()));
  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("*******\nvalue_len = %d\n"),
              this->value_len ()));

  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("+++++++\n")));
#endif /* ACE_HAS_DUMP */
}

// Default constructor.

ACE_Name_Reply::ACE_Name_Reply (void)
{
  ACE_TRACE ("ACE_Name_Reply::ACE_Name_Reply");

  // Initialize to a known quantity.
  this->msg_type (0);
  this->errnum (0);
  this->length (sizeof this->transfer_);
}

// Create a ACE_Name_Reply message.

ACE_Name_Reply::ACE_Name_Reply (ACE_UINT32 t, ACE_UINT32 err) // Type of reply.
{
  ACE_TRACE ("ACE_Name_Reply::ACE_Name_Reply");
  this->msg_type (t);
  this->errnum (err);
  this->length (sizeof this->transfer_);
}

// Initialize length_ to avoid problems with byte-ordering.

void
ACE_Name_Reply::init (void)
{
  ACE_TRACE ("ACE_Name_Reply::init");
  this->length (sizeof this->transfer_);
}

// = Set/get the length of the encoded/decoded message.

ACE_UINT32
ACE_Name_Reply::length (void) const
{
  ACE_TRACE ("ACE_Name_Reply::length");
  return this->transfer_.length_;
}

void
ACE_Name_Reply::length (ACE_UINT32 l)
{
  ACE_TRACE ("ACE_Name_Reply::length");
  this->transfer_.length_ = l;
}

// = Set/get the type of the message.

ACE_INT32
ACE_Name_Reply::msg_type (void) const
{
  ACE_TRACE ("ACE_Name_Reply::msg_type");
  return this->transfer_.type_;
}

void
ACE_Name_Reply::msg_type (ACE_INT32 t)
{
  ACE_TRACE ("ACE_Name_Reply::msg_type");
  this->transfer_.type_ = t;
}

// Get the status of the reply (0 == success, -1 == failure).

ACE_INT32
ACE_Name_Reply::status (void) const
{
  ACE_TRACE ("ACE_Name_Reply::status");
  return this->transfer_.type_;
}

// Set the status of the reply (0 == success, -1 == failure).

void
ACE_Name_Reply::status (ACE_INT32 s)
{
  ACE_TRACE ("ACE_Name_Reply::status");
  if (s == -1)
    this->transfer_.type_ = -1;
  else
    this->transfer_.type_ = 0;
}

// = Set/get the errno of a failed reply.
ACE_UINT32
ACE_Name_Reply::errnum (void) const
{
  ACE_TRACE ("ACE_Name_Reply::errnum");
  return this->transfer_.errno_;
}

void
ACE_Name_Reply::errnum (ACE_UINT32 e)
{
  ACE_TRACE ("ACE_Name_Reply::errnum");
  this->transfer_.errno_ = e;
}

// Encode the transfer buffer into network byte order
// so that it can be sent to the client.

int
ACE_Name_Reply::encode (void *&buf)
{
  ACE_TRACE ("ACE_Name_Reply::encode");
  int len = this->length (); // Get length *before* marshaling.

  this->transfer_.length_ = ACE_HTONL (this->transfer_.length_);
  this->transfer_.type_ = ACE_HTONL (this->transfer_.type_);
  this->transfer_.errno_ = ACE_HTONL (this->transfer_.errno_);
  buf = (void *) &this->transfer_;
  return len;
}

// Decode the transfer buffer into host byte order so that it can be
// used by the client.

int
ACE_Name_Reply::decode (void)
{
  ACE_TRACE ("ACE_Name_Reply::decode");
  this->transfer_.length_ = ACE_NTOHL (this->transfer_.length_);
  this->transfer_.type_ = ACE_NTOHL (this->transfer_.type_);
  this->transfer_.errno_ = ACE_NTOHL (this->transfer_.errno_);
  return 0;
}

// Print out current values of the ACE_Name_Reply object.

void
ACE_Name_Reply::dump (void) const
{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_Name_Reply::dump");
  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("*******\nlength = %d\nerrnum = %d"),
              this->length (),
              this->errnum ()));
  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("type = ")));
  switch (this->msg_type ())
    {
    case 0:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("SUCCESS\n")));
      break;
    case -1:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("FAILURE\n")));
      break;
    default:
      ACELIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("<unknown type> = %d\n"),
                  this->msg_type ()));
      break;
    }
#endif /* ACE_HAS_DUMP */
}

ACE_END_VERSIONED_NAMESPACE_DECL