summaryrefslogtreecommitdiff
path: root/TAO/utils/logWalker/Invocation.cpp
blob: a7a67bf03d8168bcc9cbd474710e9b91680a55b5 (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
// $Id$

#include "Invocation.h"
#include "GIOP_Buffer.h"
#include "PeerProcess.h"
#include "PeerObject.h"
#include "Session.h"
#include "HostProcess.h"
#include "Thread.h"

#include "ace/OS_NS_string.h"
#include "ace/OS_NS_stdio.h"
#include "ace/Log_Msg.h"

Invocation::Invocation (PeerProcess *peer, Thread *thr, size_t rid)
  :req_octets_(0),
   repl_octets_(0),
   waiter_ (thr),
   notify_incidents_ (),
   peer_(peer),
   req_id_(rid),
   target_(0),
   handle_(thr->active_handle())
{
}

Invocation::~Invocation (void)
{
  delete this->req_octets_;
  delete this->repl_octets_;
}

bool
Invocation::init (const char * text, size_t offset, Thread *thread)
{
  if (GIOP_Buffer::size_leadin == 0)
    GIOP_Buffer::init_leadin (Session::tao_version());
  const char *size_str = ACE_OS::strstr(text, GIOP_Buffer::size_leadin);
  const char *id = size_str == 0 ? 0 : ACE_OS::strchr(size_str, '[');
  if (size_str == 0 || id == 0)
    {
      ACE_ERROR ((LM_ERROR,
                  "Not a request preamble line %d:\n '%s'\n",offset,
                  text));
      return false;
  }


  if( ACE_OS::strstr(text,"Request") == 0)
    this->repl_octets_ = new GIOP_Buffer(text, offset, thread, this);
  else
    this->req_octets_  = new GIOP_Buffer(text, offset, thread, this);
  return true;
}

void
Invocation::add_notify_incident (const ACE_CString &text, size_t /* offset */)
{
  this->notify_incidents_.enqueue_tail (text);
}

bool
Invocation::is_oneway(void) const
{
  return this->req_octets_ == 0 ? false : this->req_octets_->is_oneway();
}

void
Invocation::set_target (const char *oid, size_t oid_len)
{
  PeerObject *tgt = this->peer_->object_for (oid, oid_len);
  if (tgt == 0)
    return;

  if (this->target_ == 0)
    {
      this->target_ = tgt;
      this->target_->add_invocation (this);
    }
}

bool
Invocation::message_complete (void)
{
  if (this->is_oneway())
    {
      if (this->req_octets_ == 0 || !this->req_octets_->is_full())
        return false;
    }
  else
    if (this->repl_octets_ == 0 || !this->repl_octets_->is_full())
      return false;

  return true;
}

GIOP_Buffer *
Invocation::octets (bool request)
{
  return request ? this->req_octets_ : this->repl_octets_ ;
}

GIOP_Buffer *
Invocation::give_octets (bool request)
{
  GIOP_Buffer *result = request ? this->req_octets_ : this->repl_octets_ ;

  if (request)
    this->req_octets_ = 0;
  else
    this->repl_octets_ = 0;
  return result;
}

void
Invocation::set_octets (bool request, GIOP_Buffer *octets)
{
  if (request)
    {
      if (this->req_octets_ != 0)
        {
          return;
        }
      this->req_octets_ = octets;
    }
  else
    {
      if (this->repl_octets_ != 0)
        {
          return;
        }
      this->repl_octets_ = octets;
    }
  octets->owner(this);
}

bool
Invocation::sent_request (void) const
{
  if (this->req_octets_)
    return this->req_octets_->sending();
  if (this->repl_octets_)
    return !this->repl_octets_->sending();
  return false;
}

size_t
Invocation::request_id (void) const
{
  return this->req_octets_ == 0 ? this->req_id_ : this->req_octets_->expected_req_id();
}

size_t
Invocation::expected_size (void) const
{
  if (repl_octets_ != 0)
    return repl_octets_->expected_size();
  return req_octets_->expected_size();
}

size_t
Invocation::request_bytes (void) const
{
  return req_octets_ != 0 ? req_octets_->expected_size() : 0;
}

Thread *
Invocation::waiter (void) const
{
  return this->waiter_;
}

long
Invocation::handle (void) const
{
  return this->handle_;
}

bool
Invocation::contains (size_t line)
{
  if (this->req_octets_ == 0 || this->repl_octets_ == 0)
    return false;
  return
    line > this->req_octets_->log_posn() &&
    line < this->repl_octets_->log_posn();
}

size_t
Invocation::req_line (void)
{
  return this->req_octets_ == 0 ? 0 : this->req_octets_->log_posn();
}

void
Invocation::new_line (ostream &strm, int indent, int offset, bool add_nl, bool show_indent)
{
  if (add_nl)
    {
      strm << "\n";
    }

  if (indent > 9)
    {
      if (show_indent)
        strm << "[indent " << indent << "] ---> ";
      else
        strm << "                   ";
    }
  else
    {
      indent += offset;
      while (indent-- > 0)
        strm << "  ";
    }
}

void
Invocation::dump_detail (ostream &strm,
                         size_t indent,
                         Dump_Mode mode,
                         bool show_handle)
{
  const char *opname = "";
  const char *dir_1 = "sent to ";
  const char *dir_2 = " in ";

  if (this->req_octets_ != 0)
    {
      opname = this->req_octets_->operation();
      if (this->req_octets_->sending())
        {
          dir_1 = "recv for ";
          dir_2 = " from ";
        }
    }

  this->new_line (strm, indent, 0, false, true);

  if (opname == 0 || opname[0] == 0)
    opname = "<no operation>";

  strm << dir_1;
  if (this->target_ == 0)
    strm << "<unknown object>" ;
  else
    strm << this->target_->name();
  if (mode == Dump_Proc || mode == Dump_Both)
    strm << dir_2 << this->peer_->id() << ",";

  strm << " req " << this->req_id_;
  if (show_handle)
    strm << "(h=" << this->handle_ << ")";
  strm << " [" << opname << "]\t";
  time_t req_time = 0;
  time_t rep_time = 0;
  size_t delta = 0;
  if (!this->is_oneway() && this->req_octets_ != 0)
    {
      req_time = this->req_octets_->time();
      if (this->repl_octets_ != 0)
        {
          rep_time = this->repl_octets_->time();
          delta = this->repl_octets_->log_posn() -
            this->req_octets_->log_posn();
        }
    }
  if (req_time != 0 && rep_time != 0)
    strm << " took " << (rep_time - req_time) << " ms";

  if (this->req_octets_ != 0)
    {
      strm << " Request, ";
      if (this->req_octets_->num_contexts() > 0)
        strm << "with " << this->req_octets_->num_contexts() << " contexts, ";
      strm << "size " << this->req_octets_->expected_size() << " ";
      strm << "line " << this->req_octets_->log_posn();
      if (mode == Dump_Thread || mode == Dump_Both)
        strm << " " << this->req_octets_->thread()->alias();
    }
  else
    strm << " <no request found>";
  if (this->is_oneway())
    strm << " oneway";
  else
    {
      if (this->repl_octets_ != 0)
        {
          strm << " Reply, ";
          if (this->repl_octets_->num_contexts() > 0)
            strm << "with " << this->repl_octets_->num_contexts()
                 << " contexts, ";
          strm << "size " << this->repl_octets_->expected_size() << " ";
          strm << "line " << this->repl_octets_->log_posn();
#if defined (SHOW_THREAD_ID)
          strm << " " << this->repl_octets_->thread()->alias();
#endif
          size_t rstat = this->repl_octets_->reply_status();
          if (rstat == 1 || rstat == 2)
            {
              strm << (rstat == 1 ? " User" : " System") << " Exception";
            }
          else if (rstat == 3)
            {
              strm << " Location Forward";
            }
        }
      else
        strm << " <no reply found>";
    }
  if (delta > 0)
    strm << " log span = " << delta;
  if (this->req_octets_ != 0 && this->req_octets_->has_octets())
    this->dump_special_details (strm, indent, opname);
  strm << endl;
  if (this->notify_incidents_.size() > 0)
    {
      for (NotifyIncidents::ITERATOR i = this->notify_incidents_.begin();
           !(i.done()); i.advance())
        {
          ACE_CString *note;
          i.next(note);
          strm << "            " << *note << endl;
        }
    }
}

void
Invocation::dump_special_details (ostream &strm, size_t indent, const char *opname)
{
  size_t rstat = 0;
  if (this->repl_octets_ != 0 && this->repl_octets_->has_octets())
    rstat = this->repl_octets_->reply_status();
  int opid = 0;
  if (ACE_OS::strcmp (opname, "_is_a") == 0)
    {
      opid = 1;
      ACE_InputCDR &giop_cdr = this->req_octets_->payload();
      ACE_InputCDR cdr (giop_cdr.rd_ptr(),
                        giop_cdr.length(),
                        giop_cdr.byte_order());
      this->new_line (strm, indent, 8, true, false);
      ACE_CDR::ULong len;
      if (cdr >> len)
        {
          strm << "expected type ( len = " << len << ") " << cdr.rd_ptr();
        }
      else
        {
          strm << "expected type parse failed";
        }
    }
  else if (ACE_OS::strcmp (opname, "_get_MyID") == 0)
    {
      opid = 2;
    }
  else if (ACE_OS::strcmp (opname, "resolve_str") == 0)
    {
      opid = 3;
      ACE_InputCDR &giop_cdr = this->req_octets_->payload();
      ACE_InputCDR cdr (giop_cdr.rd_ptr(),
                        giop_cdr.length(),
                        giop_cdr.byte_order());
      ACE_CDR::ULong len;
      if (cdr >> len)
        {
          this->new_line (strm, indent, 8, true, false);
          strm << "name (len = " << len << ") " << cdr.rd_ptr();
        }
    }
  else if (ACE_OS::strcmp (opname, "resolve") == 0 ||
           ACE_OS::strcmp (opname, "bind") == 0 ||
           ACE_OS::strcmp (opname, "rebind") == 0 ||
           ACE_OS::strcmp (opname, "bind_new_context") == 0
           )
    {
      opid = 3;
      ACE_InputCDR &giop_cdr = this->req_octets_->payload();
      ACE_InputCDR cdr (giop_cdr.rd_ptr(),
                        giop_cdr.length(),
                        giop_cdr.byte_order());
      ACE_CDR::ULong count;
      if (cdr >> count)
        {
          this->new_line (strm, indent, 3, true, false);
          strm << "name_seq.lengh = " << count << " ";
          while (count-- > 0)
            {
              ACE_CDR::ULong len;
              if (!(cdr >> len))
                break;
              strm << cdr.rd_ptr();
              if (!cdr.skip_bytes (len))
                break;
              if (!(cdr >> len))
                break;
              if (len > 1)
                {
                  strm << "." << cdr.rd_ptr();
                }
              if (!cdr.skip_bytes (len))
                break;
              if (count > 0)
                {
                  strm << "/";
                }
            }
          if (static_cast<ACE_CDR::Long>(count) > 0)
            {
              strm << " [name truncated]";
            }
        }
    }
  else if (ACE_OS::strcmp (opname, "register_activator") == 0 ||
           ACE_OS::strcmp (opname, "unregister_activator") == 0 ||
           ACE_OS::strcmp (opname, "notify_child_death") == 0 ||
           ACE_OS::strcmp (opname, "start_server") == 0 ||
           ACE_OS::strcmp (opname, "wait_for_startup") == 0 ||
           ACE_OS::strcmp (opname, "activate_server") == 0 ||
           ACE_OS::strcmp (opname, "add_or_update_server") == 0 ||
           ACE_OS::strcmp (opname, "shutdown_server") == 0 ||
           ACE_OS::strcmp (opname, "server_is_running") == 0 ||
           ACE_OS::strcmp (opname, "server_is_shutting_down") == 0 ||
           ACE_OS::strcmp (opname, "find") == 0)
    {
      ACE_InputCDR &giop_cdr = this->req_octets_->payload();
      ACE_InputCDR cdr (giop_cdr.rd_ptr(),
                        giop_cdr.length(),
                        giop_cdr.byte_order());
      ACE_CDR::ULong len;
      if (cdr >> len)
        {
          this->new_line (strm, indent, 8, true, false);
          if (this->repl_octets_ == 0)
            strm << "<nrf> ";
          else if (ACE_OS::strcmp (opname, "server_is_running") == 0)
            strm << "<sir> ";
          else if (ACE_OS::strcmp (opname, "server_is_shutting_down") == 0)
            strm << "<ssd> ";
          strm << "name ( len = " << len << ") " << cdr.rd_ptr();
        }
    }

  if (this->repl_octets_ == 0 || !this->repl_octets_->has_octets())
    return;

  ACE_InputCDR &giop_cdr = this->repl_octets_->payload();
  ACE_InputCDR cdr (giop_cdr.rd_ptr(),
                    giop_cdr.length(),
                    giop_cdr.byte_order());

  if (rstat == 0)
    {
      switch (opid)
        {
        case 1:
          {
            ACE_CDR::Boolean x;
            if (cdr >> ACE_InputCDR::to_boolean (x))
              strm << " reply: " << (x ? "yes" : "no");
            break;
          }
        case 2:
          {
            this->new_line (strm, indent, 8, true, false);
            ACE_CDR::Long x;
            if (cdr >> x)
              strm << "MyID reply: " << x;
            break;
          }
        default:;
        }
    }
  else
    {
      this->new_line (strm, indent, 8, true, false);
      ACE_CDR::ULong len;
      if (rstat == 1 || rstat == 2)
        {
          strm << "Exception ";
        }
      else
        {
          strm << "Redirect to ";
        }
      if (cdr >> len)
        {
          strm << "(len = " << len << ") " << cdr.rd_ptr();
        }
      else
        {
          strm << "unparsable";
        }
    }

}