1 #include "Invocation.h"
2 #include "GIOP_Buffer.h"
3 #include "PeerProcess.h"
4 #include "PeerObject.h"
6 #include "HostProcess.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
)
21 handle_(thr
->active_handle()),
22 finish_reported_(false),
28 Invocation::~Invocation ()
30 delete this->req_octets_
;
31 delete this->repl_octets_
;
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)
44 "Not a request preamble line %d:\n '%s'\n",offset
,
49 if( ACE_OS::strstr(text
,"Request") == 0)
50 this->repl_octets_
= new GIOP_Buffer(text
, offset
, thread
, this);
52 this->req_octets_
= new GIOP_Buffer(text
, offset
, thread
, this);
57 Invocation::add_notify_incident (const ACE_CString
&text
, size_t /* offset */)
59 this->notify_incidents_
.enqueue_tail (text
);
63 Invocation::is_oneway() const
65 return this->req_octets_
== 0 ? false : this->req_octets_
->is_oneway();
69 Invocation::set_target (const char *oid
, size_t oid_len
)
71 PeerObject
*tgt
= this->peer_
->object_for (oid
, oid_len
);
75 if (this->target_
== 0)
78 this->target_
->add_invocation (this);
83 Invocation::message_complete ()
85 if (this->is_oneway())
87 if (this->req_octets_
== 0 || !this->req_octets_
->is_full())
91 if (this->repl_octets_
== 0 || !this->repl_octets_
->is_full())
98 Invocation::octets (bool request
)
100 return request
? this->req_octets_
: this->repl_octets_
;
104 Invocation::give_octets (bool request
)
106 GIOP_Buffer
*result
= request
? this->req_octets_
: this->repl_octets_
;
109 this->req_octets_
= 0;
111 this->repl_octets_
= 0;
116 Invocation::set_octets (bool request
, GIOP_Buffer
*octets
)
120 if (this->req_octets_
!= 0)
124 this->req_octets_
= octets
;
128 if (this->repl_octets_
!= 0)
132 this->repl_octets_
= octets
;
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();
148 Invocation::request_id () const
150 return this->req_octets_
== 0 ? this->req_id_
: this->req_octets_
->expected_req_id();
154 Invocation::expected_size () const
156 if (repl_octets_
!= 0)
157 return repl_octets_
->expected_size();
158 return req_octets_
->expected_size();
162 Invocation::request_bytes () const
164 return req_octets_
!= 0 ? req_octets_
->expected_size() : 0;
168 Invocation::waiter () const
170 return this->waiter_
;
174 Invocation::handle () const
176 return this->handle_
;
180 Invocation::contains (size_t line
)
182 if (this->req_octets_
== 0 || this->is_oneway())
185 line
> this->req_octets_
->log_posn() &&
186 (this->repl_octets_
== 0 || line
< this->repl_octets_
->log_posn());
190 Invocation::req_line ()
192 return this->req_octets_
== 0 ? 0 : this->req_octets_
->log_posn();
196 Invocation::repl_line ()
198 return this->repl_octets_
== 0 ? 0 : this->repl_octets_
->log_posn();
202 Invocation::new_line (ostream
&strm
, size_t indent
, int offset
, bool add_nl
, bool show_indent
)
209 size_t steps
= indent
/ 20;
210 size_t extra
= indent
% 20;
216 strm
<< "[indent " << steps
* 20 << "] --->";
217 extra
+= (indent
> 99) ? 5 : 4;
226 extra
+= (steps
* 20);
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);
244 ACE_OS::snprintf (buffer
, 20, "%d:%02d:%02d.%03d",
245 hours
, min
, sec
, subsec
);
247 strm
<< buffer
<< ' ';
251 Invocation::dump_start_line (ostream
&strm
, size_t indent
, const ACE_Time_Value
& start
)
253 if (this->req_octets_
== 0)
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())
278 this->new_line (strm
, indent
, 0, false, true);
280 strm
<< "start request ";
282 if (opname
== 0 || opname
[0] == 0)
283 opname
= "<no operation>";
286 if (this->target_
== 0)
287 strm
<< "<unknown object>" ;
289 strm
<< this->target_
->name();
290 strm
<< dir_2
<< this->peer_
->id() << ", req " << this->req_id_
;
291 strm
<< " [" << opname
<< "]";
292 if (this->is_oneway())
294 else if (this->repl_octets_
== 0)
295 strm
<< " <no reply found>";
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))
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())
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
<< "]";
344 strm
<< " (reply received at " << this->repl_level_
<< " evaluated)";
348 if (indent
!= this->req_level_
)
350 strm
<< " (req at level " << this->req_level_
<< " reply at " << indent
<< ")";
358 Invocation::dump_detail (ostream
&strm
,
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())
377 this->new_line (strm
, indent
, 0, false, true);
379 if (opname
== 0 || opname
[0] == 0)
380 opname
= "<no operation>";
383 if (this->target_
== 0)
384 strm
<< "<unknown object>" ;
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_
;
392 strm
<< "(h=" << this->handle_
<< ")";
393 strm
<< " [" << opname
<< "]\t";
394 ACE_Time_Value req_time
;
395 ACE_Time_Value rep_time
;
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();
421 strm
<< " <no request found>";
422 if (this->is_oneway())
426 if (this->repl_octets_
!= 0)
429 if (this->repl_octets_
->num_contexts() > 0)
430 strm
<< "with " << this->repl_octets_
->num_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();
437 size_t rstat
= this->repl_octets_
->reply_status();
438 if (rstat
== 1 || rstat
== 2)
440 strm
<< (rstat
== 1 ? " User" : " System") << " Exception";
444 strm
<< " Location Forward";
448 strm
<< " <no reply found>";
451 strm
<< " log span = " << delta
;
452 if (this->req_octets_
!= 0 && this->req_octets_
->has_octets())
453 this->dump_special_details (strm
, indent
, opname
);
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;
462 strm
<< " " << *note
<< endl
;
468 Invocation::dump_special_details (ostream
&strm
, size_t indent
, const char *opname
)
471 if (this->repl_octets_
!= 0 && this->repl_octets_
->has_octets())
472 rstat
= this->repl_octets_
->reply_status();
474 if (ACE_OS::strcmp (opname
, "_is_a") == 0)
477 ACE_InputCDR
&giop_cdr
= this->req_octets_
->payload();
478 ACE_InputCDR
cdr (giop_cdr
.rd_ptr(),
480 giop_cdr
.byte_order());
481 this->new_line (strm
, indent
, 8, true, false);
485 strm
<< "expected type ( len = " << len
<< ") " << cdr
.rd_ptr();
489 strm
<< "expected type parse failed";
492 else if (ACE_OS::strcmp (opname
, "_get_MyID") == 0)
496 else if (ACE_OS::strcmp (opname
, "resolve_str") == 0 ||
497 ACE_OS::strcmp (opname
, "get_object_group_ref_from_name") == 0)
500 ACE_InputCDR
&giop_cdr
= this->req_octets_
->payload();
501 ACE_InputCDR
cdr (giop_cdr
.rd_ptr(),
503 giop_cdr
.byte_order());
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
518 ACE_InputCDR
&giop_cdr
= this->req_octets_
->payload();
519 ACE_InputCDR
cdr (giop_cdr
.rd_ptr(),
521 giop_cdr
.byte_order());
522 ACE_CDR::ULong count
;
525 this->new_line (strm
, indent
, 3, true, false);
526 strm
<< "name_seq.lengh = " << count
<< " ";
532 strm
<< cdr
.rd_ptr();
533 if (!cdr
.skip_bytes (len
))
539 strm
<< "." << cdr
.rd_ptr();
541 if (!cdr
.skip_bytes (len
))
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(),
569 giop_cdr
.byte_order());
573 this->new_line (strm
, indent
, 8, true, false);
574 if (this->repl_octets_
== 0)
576 else if (ACE_OS::strcmp (opname
, "server_is_running") == 0)
578 else if (ACE_OS::strcmp (opname
, "server_is_shutting_down") == 0)
580 strm
<< "name ( len = " << len
<< ") " << cdr
.rd_ptr();
584 if (this->repl_octets_
== 0 || !this->repl_octets_
->has_octets())
587 ACE_InputCDR
&giop_cdr
= this->repl_octets_
->payload();
588 ACE_InputCDR
cdr (giop_cdr
.rd_ptr(),
590 giop_cdr
.byte_order());
599 if (cdr
>> ACE_InputCDR::to_boolean (x
))
600 strm
<< " reply: " << (x
? "yes" : "no");
605 this->new_line (strm
, indent
, 8, true, false);
608 strm
<< "MyID reply: " << x
;
616 this->new_line (strm
, indent
, 8, true, false);
618 if (rstat
== 1 || rstat
== 2)
620 strm
<< "Exception ";
624 strm
<< "Redirect to ";
628 strm
<< "(len = " << len
<< ") " << cdr
.rd_ptr();
632 strm
<< "unparsable";