Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / MT_NoUpcall_Connect / client.cpp
blob7da39d94eb6680144a5a497bd2bb1622d3685813
1 #include "SharedIntfC.h"
2 #include "SharedIntfS.h"
4 #include "ace/SString.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/Task.h"
7 #include "ace/OS_NS_unistd.h"
8 #include "ace/OS_NS_time.h"
10 Test_Idl::SharedIntf_var intf;
12 ACE_Time_Value upcall_start (0,0);
13 ACE_Time_Value upcall_end (0,0);
14 ACE_Time_Value ping_start (0,0);
15 ACE_Time_Value ping_end (0,0);
17 class SharedIntfCB : public POA_Test_Idl::AMI_SharedIntfHandler
19 public:
20 void ping ()
22 ACE_DEBUG ((LM_DEBUG, "ping returned\n"));
23 ping_end = ping_end.now ();
26 void ping_excep (::Messaging::ExceptionHolder * )
28 ACE_DEBUG ((LM_DEBUG, "exception caught on ping req\n"));
29 ping_end = ping_end.now ();
32 void do_upcall ()
34 ACE_DEBUG ((LM_DEBUG, "upcall returned\n"));
35 upcall_end = upcall_end.now ();
38 void do_upcall_excep (::Messaging::ExceptionHolder * excep )
40 try
42 excep->raise_exception ();
44 catch (const CORBA::Exception &)
47 ACE_DEBUG ((LM_DEBUG, "exception caught on upcall req\n"));
48 upcall_end = upcall_end.now ();
53 int
54 parse_args (int argc, ACE_TCHAR *argv[])
56 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:"));
57 int c;
59 while ((c = get_opts ()) != -1)
60 switch (c)
62 case '?':
63 default:
64 ACE_ERROR_RETURN ((LM_ERROR,
65 "usage: %s "
66 "-t threads "
67 "\n",
68 argv [0]),
69 -1);
71 // Indicates successful parsing of the command line
72 return 0;
75 int
76 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
78 CORBA::ORB_var orb_;
79 int result = 0;
81 try
83 ACE_DEBUG((LM_INFO,"(%P|%t) START OF CLIENT TEST\n"));
85 orb_ = CORBA::ORB_init (argc, argv);
87 if (parse_args (argc, argv) != 0)
88 return 1;
90 CORBA::Object_var obj = orb_->resolve_initial_references ("RootPOA");
91 PortableServer::POA_var root_poa =
92 PortableServer::POA::_narrow (obj.in());
94 PortableServer::POAManager_var poa_manager =
95 root_poa->the_POAManager ();
96 PortableServer::POA_var poa = root_poa;
98 poa_manager->activate ();
100 PortableServer::ServantBase_var cb_serv = new SharedIntfCB;
101 PortableServer::ObjectId_var oid = root_poa->activate_object (cb_serv.in());
102 obj = root_poa->id_to_reference (oid.in());
104 Test_Idl::AMI_SharedIntfHandler_var cb =
105 Test_Idl::AMI_SharedIntfHandler::_narrow (obj.in());
107 obj = orb_->string_to_object ("file://server.ior");
108 intf = Test_Idl::SharedIntf::_narrow(obj.in());
110 ACE_DEBUG((LM_INFO,"(%P|%t) invoking async upcall.\n"));
112 upcall_start = upcall_start.now ();
113 intf->sendc_do_upcall (cb.in());
114 ACE_DEBUG((LM_INFO,"(%P|%t) invoking ping\n"));
116 ping_start = ping_start.now ();
117 intf->ping ();
118 ACE_DEBUG((LM_INFO,"(%P|%t) sync ping returned\n"));
119 ping_end = ping_end.now ();
121 result = (upcall_end > ACE_Time_Value::zero && upcall_end <= ping_end) ? 0 : 1;
123 intf->farewell ();
124 intf = Test_Idl::SharedIntf::_nil ();
125 orb_->destroy ();
127 ACE_DEBUG ((LM_INFO,"(%P|%t) Client Test %C\n",
128 (result == 0 ? "succeeded":"failed")));
130 catch (const CORBA::Exception& ex)
132 ex._tao_print_exception ("Error: Exception caught:");
135 return result;