Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2287_Regression / ServerRequest_Interceptor2.cpp
blob720ac6d87dcb1edeeb4456ffeafdcf49c23f6390
1 // -*- C++ -*-
2 #include "ServerRequest_Interceptor2.h"
3 #include "orbsvcs/FT_CORBA_ORBC.h"
4 #include "tao/IOPC.h"
5 #include "tao/ORB_Constants.h"
6 #include "tao/AnyTypeCode/DynamicC.h"
7 #include "tao/AnyTypeCode/TypeCode.h"
8 #include "tao/CDR.h"
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_string.h"
11 #include "ace/OS_NS_stdio.h"
12 #include "ace/OS_NS_unistd.h"
13 #include "Hello.h"
14 #include "ace/OS_NS_sys_time.h"
15 #include "tao/PI/PIForwardRequestC.h"
17 TAO249_ServerRequest_Interceptor2::TAO249_ServerRequest_Interceptor2 ()
18 : orb_ (0),
19 expired_ (0)
23 TAO249_ServerRequest_Interceptor2::~TAO249_ServerRequest_Interceptor2 ()
27 char *
28 TAO249_ServerRequest_Interceptor2::name ()
30 return CORBA::string_dup ("TAO_TAO249_ServerRequest_Interceptor2");
33 void
34 TAO249_ServerRequest_Interceptor2::destroy ()
38 void
39 TAO249_ServerRequest_Interceptor2::receive_request_service_contexts (
40 PortableInterceptor::ServerRequestInfo_ptr)
44 void
45 TAO249_ServerRequest_Interceptor2::receive_request (
46 PortableInterceptor::ServerRequestInfo_ptr ri)
48 CORBA::String_var op = ri->operation ();
50 if (ACE_OS::strcmp (op.in (), "throw_location_forward"))
52 // bail if not the op we are interested in -
53 // avoid excess spurious error clutter when client calls ::shutdown
54 return;
58 IOP::ServiceContext_var sc =
59 ri->get_request_service_context (IOP::FT_REQUEST);
61 TAO_InputCDR cdr (reinterpret_cast <const char*>
62 (sc->context_data.get_buffer ()
64 sc->context_data.length ());
66 CORBA::Boolean byte_order;
68 if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
70 throw CORBA::BAD_PARAM (CORBA::OMGVMCID | 28, CORBA::COMPLETED_NO);
73 cdr.reset_byte_order (static_cast <int>(byte_order));
75 FT::FTRequestServiceContext ftrsc;
77 if ((cdr >> ftrsc) == 0)
78 throw CORBA::BAD_PARAM (CORBA::OMGVMCID | 28, CORBA::COMPLETED_NO);
80 TimeBase::TimeT now = get_now ();
82 if (now > ftrsc.expiration_time)
84 // We have passed the exp time... there should be no more retries received after this point...
85 if (expired_)
87 // The client has retried after the expiration time. This is a regression
88 ACE_DEBUG ((LM_ERROR, "Test Failed - REGRESSION !!! Client ORB is still retrying LOCATION_FORWARDs after the expiration time!!\n"));
89 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Expiration time : %Q\n"), ftrsc.expiration_time));
90 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Time now : %Q\n"), now));
92 // Let the request 'succeed' rather than throwing a forward exception.
93 return;
95 else
97 // A request has been recioved after the expiration time.
98 // This could legitimately happen - it is only definitely a problem if
99 // the client keeps on retrying after now. We set a flag so we can check for this.
100 expired_ = 1;
101 ACE_DEBUG ((LM_DEBUG, "The expiration time has now passed !!\n"));
102 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Expiration time : %Q\n"), ftrsc.expiration_time));
103 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Time now : %Q\n"), now));
107 // Let's forward the client back to us again. I would like to be able to make this a PERM
108 // but there's no such animal in the PortableInterceptor module. Plus as we (currently) transform
109 // and marshal *all* forward requests as vanilla LOCATION_FORWARD it doesn't really matter.
110 throw PortableInterceptor::ForwardRequest (server_iogr_.in ());
113 TimeBase::TimeT
114 TAO249_ServerRequest_Interceptor2::get_now ()
116 // 1582...
117 const TimeBase::TimeT timeOffset = ACE_UINT64_LITERAL (0x1B21DD213814000);
119 // Now in posix
120 ACE_Time_Value time_value = ACE_OS::gettimeofday ();
122 TimeBase::TimeT sec_part = time_value.sec ();
123 sec_part = sec_part * 10000000;
124 TimeBase::TimeT usec_part = time_value.usec ();
125 usec_part = usec_part * 10;
126 return (sec_part + usec_part + timeOffset);
129 void
130 TAO249_ServerRequest_Interceptor2::send_reply (
131 PortableInterceptor::ServerRequestInfo_ptr)
135 void
136 TAO249_ServerRequest_Interceptor2::send_exception (
137 PortableInterceptor::ServerRequestInfo_ptr)
141 void
142 TAO249_ServerRequest_Interceptor2::send_other (
143 PortableInterceptor::ServerRequestInfo_ptr)