Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2285_Regression / ServerRequest_Interceptor2.cpp
blob50f3f99a44f6186f5e67fd4cdaf895a2239cd59d
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"
16 TAO249_ServerRequest_Interceptor2::TAO249_ServerRequest_Interceptor2 ()
17 : orb_ (0),
18 client_id_ (0)
22 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 (), "drop_down_dead"))
52 // bail if not the op we are interested in -
53 // avoid excess spurious error clutter when client calls ::shutdown
54 return;
57 try
59 IOP::ServiceContext_var sc =
60 ri->get_request_service_context (IOP::FT_REQUEST);
62 TAO_InputCDR cdr (reinterpret_cast <const char*>
63 (sc->context_data.get_buffer ()
65 sc->context_data.length ());
67 CORBA::Boolean byte_order;
69 if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
71 throw CORBA::BAD_PARAM (CORBA::OMGVMCID | 28, CORBA::COMPLETED_NO);
74 cdr.reset_byte_order (static_cast <int>(byte_order));
76 FT::FTRequestServiceContext ftrsc;
78 if ((cdr >> ftrsc) == 0)
79 throw CORBA::BAD_PARAM (CORBA::OMGVMCID | 28, CORBA::COMPLETED_NO);
81 FILE* last_exp_time_file = ACE_OS::fopen ("last_expiration_time", "r+");
82 TimeBase::TimeT last_exp_time = 0;
84 if (!last_exp_time_file)
86 // file does not exist ... we're the first server
87 // create new file for the expiration time
88 last_exp_time_file = ACE_OS::fopen ("last_expiration_time", "w+");
89 last_exp_time = ftrsc.expiration_time;
91 else
93 // We're a subsequent server... read in the previous server's expiration time
94 ACE_OS::fread (&last_exp_time,
96 sizeof (TimeBase::TimeT),
97 last_exp_time_file);
98 ACE_OS::sleep (1);
101 if (last_exp_time != ftrsc.expiration_time)
103 ACE_DEBUG ((LM_DEBUG, "Test Failed - REGRESSION !!! Different expiration times used on consecutive retries of the same op!!\n"));
104 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Previous expiration: %Q\n"), last_exp_time));
105 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Current expiration : %Q\n"), ftrsc.expiration_time));
106 return;
110 // This is the offset from UTC to posix - a value less than than this will
111 // indicate posix is (mistakenly) being used
112 TimeBase::TimeT the_seventies = ACE_UINT64_LITERAL (0x1B21DD213814000);
114 // @warning - this test is fragile. It will break in 2358 A.D. :-)
115 if (last_exp_time <= the_seventies)
117 ACE_DEBUG ((LM_ERROR, "Test Failed - REGRESSION !!! Expiration time is in wrong format - it is before 1970 A.D. !!\n"));
118 ACE_DEBUG ((LM_DEBUG, "Expiration time: %Q\n", last_exp_time));
119 ACE_DEBUG ((LM_DEBUG, "1970 A.D. : %Q\n", the_seventies));
120 return;
122 else if ( last_exp_time > (the_seventies * 2))
124 ACE_DEBUG ((LM_ERROR, "Test Failed - REGRESSION !!! Expiration time is garbage - it is after 2358 A.D. !!\n"));
125 ACE_DEBUG ((LM_DEBUG, "Expiration time: %Q\n", last_exp_time));
126 ACE_DEBUG ((LM_DEBUG, "2358 A.D. : %Q\n", (the_seventies * 2)));
127 return;
130 TimeBase::TimeT now = get_now ();
132 if (now > last_exp_time)
134 // We have passed the exp time... there should be no more retries received after this point...
135 FILE* no_more_retries = ACE_OS::fopen ("no_more_retries", "r+");
136 if (no_more_retries)
138 TimeBase::TimeT last_expired_attempt = 0;
139 ACE_OS::fread (&last_expired_attempt, 1, sizeof (TimeBase::TimeT), no_more_retries);
140 ACE_OS::fclose (no_more_retries);
142 // There has already been an attempt after the last server passed the expiration time
143 ACE_DEBUG ((LM_ERROR, "Test Failed - REGRESSION !!! Client ORB is still retrying after the expiration time!!\n"));
144 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Expiration time : %Q\n"), last_exp_time));
145 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Previous attempt : %Q\n"), last_expired_attempt));
146 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Time now : %Q\n"), now));
147 return;
149 else
151 // Tell the next server we've passed the point of no return
152 no_more_retries = ACE_OS::fopen ("no_more_retries", "w+");
153 ACE_OS::fwrite (&now, 1, sizeof (TimeBase::TimeT), no_more_retries);
154 ACE_OS::fflush (no_more_retries);
155 ACE_OS::fclose (no_more_retries);
159 // Everthing is fine so far. Write out the expiration time for the next server to check
160 ACE_OS::fwrite (&ftrsc.expiration_time, 1, sizeof (TimeBase::TimeT), last_exp_time_file);
161 ACE_OS::fflush (last_exp_time_file);
162 ACE_OS::fclose (last_exp_time_file);
164 // Goodbye cruel world !!
165 ACE_OS::abort ();
167 catch (const CORBA::Exception& ex)
169 ACE_DEBUG ((LM_ERROR, "Unexpected (non regression problem) error - test failed\n"));
170 ex._tao_print_exception (
171 "Exception in TAO249_ServerRequest_Interceptor2::receive_request\n");
172 throw;
177 TimeBase::TimeT
178 TAO249_ServerRequest_Interceptor2::get_now ()
180 // 1582...
181 const TimeBase::TimeT timeOffset = ACE_UINT64_LITERAL (0x1B21DD213814000);
183 // Now in posix
184 ACE_Time_Value time_value = ACE_OS::gettimeofday ();
186 TimeBase::TimeT sec_part = time_value.sec ();
187 sec_part = sec_part * 10000000;
188 TimeBase::TimeT usec_part = time_value.usec ();
189 usec_part = usec_part * 10;
190 return (sec_part + usec_part + timeOffset);
193 void
194 TAO249_ServerRequest_Interceptor2::send_reply (
195 PortableInterceptor::ServerRequestInfo_ptr)
199 void
200 TAO249_ServerRequest_Interceptor2::send_exception (
201 PortableInterceptor::ServerRequestInfo_ptr)
205 void
206 TAO249_ServerRequest_Interceptor2::send_other (
207 PortableInterceptor::ServerRequestInfo_ptr)