Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / utils / logWalker / Invocation.cpp
blob7ab85a713a29742f11901867dae2689481d732cb
1 #include "Invocation.h"
2 #include "GIOP_Buffer.h"
3 #include "PeerProcess.h"
4 #include "PeerObject.h"
5 #include "Session.h"
6 #include "HostProcess.h"
7 #include "Thread.h"
9 #include "ace/OS_NS_string.h"
10 #include "ace/OS_NS_stdio.h"
11 #include "ace/Log_Msg.h"
13 Invocation::Invocation (PeerProcess *peer, Thread *thr, size_t rid)
14 :req_octets_(0),
15 repl_octets_(0),
16 waiter_ (thr),
17 notify_incidents_ (),
18 peer_(peer),
19 req_id_(rid),
20 target_(0),
21 handle_(thr->active_handle()),
22 finish_reported_(false),
23 req_level_ (0),
24 repl_level_ (0)
28 Invocation::~Invocation ()
30 delete this->req_octets_;
31 delete this->repl_octets_;
34 bool
35 Invocation::init (const char * text, size_t offset, Thread *thread)
37 if (GIOP_Buffer::size_leadin == 0)
38 GIOP_Buffer::init_leadin (Session::tao_version());
39 const char *size_str = ACE_OS::strstr(text, GIOP_Buffer::size_leadin);
40 const char *id = size_str == 0 ? 0 : ACE_OS::strchr(size_str, '[');
41 if (size_str == 0 || id == 0)
43 ACE_ERROR ((LM_ERROR,
44 "Not a request preamble line %d:\n '%s'\n",offset,
45 text));
46 return false;
49 if( ACE_OS::strstr(text,"Request") == 0)
50 this->repl_octets_ = new GIOP_Buffer(text, offset, thread, this);
51 else
52 this->req_octets_ = new GIOP_Buffer(text, offset, thread, this);
53 return true;
56 void
57 Invocation::add_notify_incident (const ACE_CString &text, size_t /* offset */)
59 this->notify_incidents_.enqueue_tail (text);
62 bool
63 Invocation::is_oneway() const
65 return this->req_octets_ == 0 ? false : this->req_octets_->is_oneway();
68 void
69 Invocation::set_target (const char *oid, size_t oid_len)
71 PeerObject *tgt = this->peer_->object_for (oid, oid_len);
72 if (tgt == 0)
73 return;
75 if (this->target_ == 0)
77 this->target_ = tgt;
78 this->target_->add_invocation (this);
82 bool
83 Invocation::message_complete ()
85 if (this->is_oneway())
87 if (this->req_octets_ == 0 || !this->req_octets_->is_full())
88 return false;
90 else
91 if (this->repl_octets_ == 0 || !this->repl_octets_->is_full())
92 return false;
94 return true;
97 GIOP_Buffer *
98 Invocation::octets (bool request)
100 return request ? this->req_octets_ : this->repl_octets_ ;
103 GIOP_Buffer *
104 Invocation::give_octets (bool request)
106 GIOP_Buffer *result = request ? this->req_octets_ : this->repl_octets_ ;
108 if (request)
109 this->req_octets_ = 0;
110 else
111 this->repl_octets_ = 0;
112 return result;
115 void
116 Invocation::set_octets (bool request, GIOP_Buffer *octets)
118 if (request)
120 if (this->req_octets_ != 0)
122 return;
124 this->req_octets_ = octets;
126 else
128 if (this->repl_octets_ != 0)
130 return;
132 this->repl_octets_ = octets;
134 octets->owner(this);
137 bool
138 Invocation::sent_request () const
140 if (this->req_octets_)
141 return this->req_octets_->sending();
142 if (this->repl_octets_)
143 return !this->repl_octets_->sending();
144 return false;
147 size_t
148 Invocation::request_id () const
150 return this->req_octets_ == 0 ? this->req_id_ : this->req_octets_->expected_req_id();
153 size_t
154 Invocation::expected_size () const
156 if (repl_octets_ != 0)
157 return repl_octets_->expected_size();
158 return req_octets_->expected_size();
161 size_t
162 Invocation::request_bytes () const
164 return req_octets_ != 0 ? req_octets_->expected_size() : 0;
167 Thread *
168 Invocation::waiter () const
170 return this->waiter_;
173 long
174 Invocation::handle () const
176 return this->handle_;
179 bool
180 Invocation::contains (size_t line)
182 if (this->req_octets_ == 0 || this->is_oneway())
183 return false;
184 return
185 line > this->req_octets_->log_posn() &&
186 (this->repl_octets_ == 0 || line < this->repl_octets_->log_posn());
189 size_t
190 Invocation::req_line ()
192 return this->req_octets_ == 0 ? 0 : this->req_octets_->log_posn();
195 size_t
196 Invocation::repl_line ()
198 return this->repl_octets_ == 0 ? 0 : this->repl_octets_->log_posn();
201 void
202 Invocation::new_line (ostream &strm, size_t indent, int offset, bool add_nl, bool show_indent)
204 if (add_nl)
206 strm << "\n";
209 size_t steps = indent / 20;
210 size_t extra = indent % 20;
212 if (steps > 1)
214 if (show_indent)
216 strm << "[indent " << steps * 20 << "] --->";
217 extra += (indent > 99) ? 5 : 4;
219 else
221 extra += 20;
224 else
226 extra += (steps * 20);
229 extra += offset;
230 while (extra-- > 0)
231 strm << " ";
234 void
235 Invocation::dump_rel_time (ostream &strm, const ACE_Time_Value &tv, const ACE_Time_Value& start)
237 ACE_Time_Value reltime = tv - start;
238 int hours = (int)(reltime.sec()) / 3600;
239 int min = (int)(reltime.sec() %3600) / 60;
240 int sec = (int)(reltime.sec()) % 60;
241 int subsec = (int)(reltime.usec()/1000);
243 char buffer[20];
244 ACE_OS::snprintf (buffer, 20, "%d:%02d:%02d.%03d",
245 hours, min, sec, subsec);
247 strm << buffer << ' ';
250 void
251 Invocation::dump_start_line (ostream &strm, size_t indent, const ACE_Time_Value& start)
253 if (this->req_octets_ == 0)
254 return;
255 this->req_level_ = indent;
256 strm << setw(7) << this->req_octets_->log_posn() << " " << setw(0);
258 const ACE_Time_Value &tv = this->req_octets_->time();
259 if (tv != ACE_Time_Value::zero)
261 dump_rel_time (strm, tv, start);
264 const char *opname = "";
265 const char *dir_1 = "sent to ";
266 const char *dir_2 = " in ";
268 if (this->req_octets_ != 0)
270 opname = this->req_octets_->operation();
271 if (this->req_octets_->sending())
273 dir_1 = "recv for ";
274 dir_2 = " from ";
278 this->new_line (strm, indent, 0, false, true);
280 strm << "start request ";
282 if (opname == 0 || opname[0] == 0)
283 opname = "<no operation>";
285 strm << dir_1;
286 if (this->target_ == 0)
287 strm << "<unknown object>" ;
288 else
289 strm << this->target_->name();
290 strm << dir_2 << this->peer_->id() << ", req " << this->req_id_;
291 strm << " [" << opname << "]";
292 if (this->is_oneway())
293 strm << " oneway";
294 else if (this->repl_octets_ == 0)
295 strm << " <no reply found>";
296 strm << endl;
299 void
300 Invocation::dump_finish_line (ostream &strm, size_t indent, const ACE_Time_Value& start)
302 bool is_popped = this->repl_level_ > 0 && indent == this->req_level_;
304 if (!is_popped && (this->finish_reported_ || this->is_oneway() || this->repl_octets_ == 0))
305 return;
307 if (!this->finish_reported_)
309 this->repl_level_ = indent;
312 this->finish_reported_ = true;
313 strm << setw(7) << this->repl_octets_->log_posn() << " " << setw(0);
315 const char *opname = "";
316 const ACE_Time_Value &tv = this->repl_octets_->time();
317 if (tv != ACE_Time_Value::zero)
319 dump_rel_time (strm, tv, start);
322 const char *dir = "reply from ";
324 if (this->req_octets_ != 0)
326 opname = this->req_octets_->operation();
327 if (this->req_octets_->sending())
329 dir = "reply to ";
333 if (opname == 0 || opname[0] == 0)
335 opname = "<no operation>";
338 this->new_line (strm, indent, 0, false, true);
340 strm << dir << this->peer_->id() << ", req " << this->req_id_;
341 strm << " [" << opname << "]";
342 if (is_popped)
344 strm << " (reply received at " << this->repl_level_ << " evaluated)";
346 else
348 if (indent != this->req_level_)
350 strm << " (req at level " << this->req_level_ << " reply at " << indent << ")";
354 strm << endl;
357 void
358 Invocation::dump_detail (ostream &strm,
359 size_t indent,
360 Dump_Mode mode,
361 bool show_handle)
363 const char *opname = "";
364 const char *dir_1 = "sent to ";
365 const char *dir_2 = " in ";
367 if (this->req_octets_ != 0)
369 opname = this->req_octets_->operation();
370 if (this->req_octets_->sending())
372 dir_1 = "recv for ";
373 dir_2 = " from ";
377 this->new_line (strm, indent, 0, false, true);
379 if (opname == 0 || opname[0] == 0)
380 opname = "<no operation>";
382 strm << dir_1;
383 if (this->target_ == 0)
384 strm << "<unknown object>" ;
385 else
386 strm << this->target_->name();
387 if (mode == Dump_Proc || mode == Dump_Both)
388 strm << dir_2 << this->peer_->id() << ",";
390 strm << " req " << this->req_id_;
391 if (show_handle)
392 strm << "(h=" << this->handle_ << ")";
393 strm << " [" << opname << "]\t";
394 ACE_Time_Value req_time;
395 ACE_Time_Value rep_time;
396 size_t delta = 0;
397 if (!this->is_oneway() && this->req_octets_ != 0)
399 req_time = this->req_octets_->time();
400 if (this->repl_octets_ != 0)
402 rep_time = this->repl_octets_->time();
403 delta = this->repl_octets_->log_posn() -
404 this->req_octets_->log_posn();
407 if (req_time.msec() != 0 && rep_time.msec() != 0)
408 strm << " took " << (rep_time.msec() - req_time.msec()) << " ms";
410 if (this->req_octets_ != 0)
412 strm << " Request, ";
413 if (this->req_octets_->num_contexts() > 0)
414 strm << "with " << this->req_octets_->num_contexts() << " contexts, ";
415 strm << "size " << this->req_octets_->expected_size() << " ";
416 strm << "line " << this->req_octets_->log_posn();
417 if (mode == Dump_Thread || mode == Dump_Both)
418 strm << " " << this->req_octets_->thread()->alias();
420 else
421 strm << " <no request found>";
422 if (this->is_oneway())
423 strm << " oneway";
424 else
426 if (this->repl_octets_ != 0)
428 strm << " Reply, ";
429 if (this->repl_octets_->num_contexts() > 0)
430 strm << "with " << this->repl_octets_->num_contexts()
431 << " contexts, ";
432 strm << "size " << this->repl_octets_->expected_size() << " ";
433 strm << "line " << this->repl_octets_->log_posn();
434 #if defined (SHOW_THREAD_ID)
435 strm << " " << this->repl_octets_->thread()->alias();
436 #endif
437 size_t rstat = this->repl_octets_->reply_status();
438 if (rstat == 1 || rstat == 2)
440 strm << (rstat == 1 ? " User" : " System") << " Exception";
442 else if (rstat == 3)
444 strm << " Location Forward";
447 else
448 strm << " <no reply found>";
450 if (delta > 0)
451 strm << " log span = " << delta;
452 if (this->req_octets_ != 0 && this->req_octets_->has_octets())
453 this->dump_special_details (strm, indent, opname);
454 strm << endl;
455 if (this->notify_incidents_.size() > 0)
457 for (NotifyIncidents::ITERATOR i = this->notify_incidents_.begin();
458 !(i.done()); i.advance())
460 ACE_CString *note = 0;
461 i.next(note);
462 strm << " " << *note << endl;
467 void
468 Invocation::dump_special_details (ostream &strm, size_t indent, const char *opname)
470 size_t rstat = 0;
471 if (this->repl_octets_ != 0 && this->repl_octets_->has_octets())
472 rstat = this->repl_octets_->reply_status();
473 int opid = 0;
474 if (ACE_OS::strcmp (opname, "_is_a") == 0)
476 opid = 1;
477 ACE_InputCDR &giop_cdr = this->req_octets_->payload();
478 ACE_InputCDR cdr (giop_cdr.rd_ptr(),
479 giop_cdr.length(),
480 giop_cdr.byte_order());
481 this->new_line (strm, indent, 8, true, false);
482 ACE_CDR::ULong len;
483 if (cdr >> len)
485 strm << "expected type ( len = " << len << ") " << cdr.rd_ptr();
487 else
489 strm << "expected type parse failed";
492 else if (ACE_OS::strcmp (opname, "_get_MyID") == 0)
494 opid = 2;
496 else if (ACE_OS::strcmp (opname, "resolve_str") == 0 ||
497 ACE_OS::strcmp (opname, "get_object_group_ref_from_name") == 0)
499 opid = 3;
500 ACE_InputCDR &giop_cdr = this->req_octets_->payload();
501 ACE_InputCDR cdr (giop_cdr.rd_ptr(),
502 giop_cdr.length(),
503 giop_cdr.byte_order());
504 ACE_CDR::ULong len;
505 if (cdr >> len)
507 this->new_line (strm, indent, 8, true, false);
508 strm << "name (len = " << len << ") " << cdr.rd_ptr();
511 else if (ACE_OS::strcmp (opname, "resolve") == 0 ||
512 ACE_OS::strcmp (opname, "bind") == 0 ||
513 ACE_OS::strcmp (opname, "rebind") == 0 ||
514 ACE_OS::strcmp (opname, "bind_new_context") == 0
517 opid = 3;
518 ACE_InputCDR &giop_cdr = this->req_octets_->payload();
519 ACE_InputCDR cdr (giop_cdr.rd_ptr(),
520 giop_cdr.length(),
521 giop_cdr.byte_order());
522 ACE_CDR::ULong count;
523 if (cdr >> count)
525 this->new_line (strm, indent, 3, true, false);
526 strm << "name_seq.lengh = " << count << " ";
527 while (count-- > 0)
529 ACE_CDR::ULong len;
530 if (!(cdr >> len))
531 break;
532 strm << cdr.rd_ptr();
533 if (!cdr.skip_bytes (len))
534 break;
535 if (!(cdr >> len))
536 break;
537 if (len > 1)
539 strm << "." << cdr.rd_ptr();
541 if (!cdr.skip_bytes (len))
542 break;
543 if (count > 0)
545 strm << "/";
548 if (static_cast<ACE_CDR::Long>(count) > 0)
550 strm << " [name truncated]";
554 else if (ACE_OS::strcmp (opname, "register_activator") == 0 ||
555 ACE_OS::strcmp (opname, "unregister_activator") == 0 ||
556 ACE_OS::strcmp (opname, "notify_child_death") == 0 ||
557 ACE_OS::strcmp (opname, "start_server") == 0 ||
558 ACE_OS::strcmp (opname, "wait_for_startup") == 0 ||
559 ACE_OS::strcmp (opname, "activate_server") == 0 ||
560 ACE_OS::strcmp (opname, "add_or_update_server") == 0 ||
561 ACE_OS::strcmp (opname, "shutdown_server") == 0 ||
562 ACE_OS::strcmp (opname, "server_is_running") == 0 ||
563 ACE_OS::strcmp (opname, "server_is_shutting_down") == 0 ||
564 ACE_OS::strcmp (opname, "find") == 0)
566 ACE_InputCDR &giop_cdr = this->req_octets_->payload();
567 ACE_InputCDR cdr (giop_cdr.rd_ptr(),
568 giop_cdr.length(),
569 giop_cdr.byte_order());
570 ACE_CDR::ULong len;
571 if (cdr >> len)
573 this->new_line (strm, indent, 8, true, false);
574 if (this->repl_octets_ == 0)
575 strm << "<nrf> ";
576 else if (ACE_OS::strcmp (opname, "server_is_running") == 0)
577 strm << "<sir> ";
578 else if (ACE_OS::strcmp (opname, "server_is_shutting_down") == 0)
579 strm << "<ssd> ";
580 strm << "name ( len = " << len << ") " << cdr.rd_ptr();
584 if (this->repl_octets_ == 0 || !this->repl_octets_->has_octets())
585 return;
587 ACE_InputCDR &giop_cdr = this->repl_octets_->payload();
588 ACE_InputCDR cdr (giop_cdr.rd_ptr(),
589 giop_cdr.length(),
590 giop_cdr.byte_order());
592 if (rstat == 0)
594 switch (opid)
596 case 1:
598 ACE_CDR::Boolean x;
599 if (cdr >> ACE_InputCDR::to_boolean (x))
600 strm << " reply: " << (x ? "yes" : "no");
601 break;
603 case 2:
605 this->new_line (strm, indent, 8, true, false);
606 ACE_CDR::Long x;
607 if (cdr >> x)
608 strm << "MyID reply: " << x;
609 break;
611 default:;
614 else
616 this->new_line (strm, indent, 8, true, false);
617 ACE_CDR::ULong len;
618 if (rstat == 1 || rstat == 2)
620 strm << "Exception ";
622 else
624 strm << "Redirect to ";
626 if (cdr >> len)
628 strm << "(len = " << len << ") " << cdr.rd_ptr();
630 else
632 strm << "unparsable";