Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_3896_Regression / client.cpp
blob5916bee8932ca74d508f6ae4d44337bdd8dcfa5a
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Task_T.h"
4 #include "ace/OS_NS_unistd.h"
5 #include "tao/TimeBaseC.h"
6 #include "tao/Messaging/Messaging.h"
8 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
9 bool shutdown_server = false;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:x"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
23 case 'x':
24 shutdown_server = true;
25 break;
27 case '?':
28 default:
29 ACE_ERROR_RETURN ((LM_ERROR,
30 "usage: %s "
31 "-k <ior> "
32 "\n",
33 argv [0]),
34 -1);
36 // Indicates successful parsing of the command line
37 return 0;
40 class Client : public ACE_Task_Base
42 public:
43 Client (CORBA::ORB_ptr server);
45 virtual int svc ();
47 private:
48 CORBA::ORB_var orb_;
51 int
52 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
54 try
56 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
58 if (parse_args (argc, argv) != 0)
59 return 1;
61 // Set round-trip timeout
62 const int timeout_secs = 5;
64 CORBA::Object_var obj = orb->resolve_initial_references ("ORBPolicyManager");
65 CORBA::PolicyManager_var policy_manager =
66 CORBA::PolicyManager::_narrow (obj.in());
68 CORBA::PolicyList policy_list;
69 policy_list.length(0);
70 policy_manager->set_policy_overrides(policy_list, CORBA::SET_OVERRIDE);
72 TimeBase::TimeT timeout = timeout_secs * 10000000;
73 CORBA::Any orb_timeout;
74 orb_timeout <<= timeout;
75 policy_list.length(1);
76 policy_list[0] = orb->create_policy(
77 Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE, orb_timeout);
79 policy_manager->set_policy_overrides(policy_list, CORBA::SET_OVERRIDE);
81 CORBA::Object_var tmp = orb->string_to_object(ior);
83 Test::Hello_var hello = Test::Hello::_narrow(tmp.in ());
85 if (CORBA::is_nil (hello.in ()))
87 ACE_ERROR_RETURN ((LM_DEBUG,
88 "Nil Test::Hello reference <%s>\n",
89 ior),
90 1);
93 if (shutdown_server)
95 ACE_DEBUG ((LM_DEBUG,
96 "(%P|%t) Calling shutdown on server\n"));
97 hello->shutdown ();
99 else
101 Client client (orb.in ());
102 if (client.activate (THR_NEW_LWP | THR_JOINABLE, 1) != 0)
103 ACE_ERROR_RETURN ((LM_ERROR,
104 "Cannot activate client threads\n"),
107 CORBA::String_var the_string;
110 the_string = hello->get_string ();
112 catch (const CORBA::TIMEOUT&)
114 ACE_DEBUG ((LM_DEBUG,
115 "(%P|%t) Error: got timeout\n"));
117 catch (const CORBA::COMM_FAILURE&)
119 ACE_DEBUG ((LM_DEBUG,
120 "(%P|%t) Ok: got comm exception\n"));
123 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
124 the_string.in ()));
126 client.thr_mgr ()->wait ();
129 orb->destroy ();
131 catch (const CORBA::Exception& ex)
133 ex._tao_print_exception ("Exception caught:");
134 return 1;
137 return 0;
140 Client::Client (CORBA::ORB_ptr orb)
141 : orb_ (CORBA::ORB::_duplicate (orb))
146 Client::svc ()
150 ACE_OS::sleep (2);
151 ACE_DEBUG ((LM_DEBUG,
152 "(%P|%t) Shutting down ORB\n"));
153 orb_->shutdown (true);
155 catch (const CORBA::Exception&)
158 return 0;