Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_4059_Regression / client.cpp
blob774de214a0d8521c5734c61e15bd76324fa4348c
1 #include "TestC.h"
2 #include "tao/RTCORBA/RTCORBA.h"
3 #include "tao/Policy_ManagerC.h"
4 #include "ace/Synch.h"
5 #include "ace/Condition_T.h"
6 #include "ace/OS_NS_time.h"
7 #include "ace/OS_NS_sys_time.h"
8 #include "ace/Thread.h"
9 #include "ace/Get_Opt.h"
11 TAO_SYNCH_MUTEX test_lock;
12 ACE_Condition<TAO_SYNCH_MUTEX> cond (test_lock);
13 bool is_ok = false;
14 CORBA::ORB_var orb;
16 const ACE_TCHAR *ior = ACE_TEXT ("corbaloc::localhost:5678/Test");
18 int
19 parse_args (int argc, ACE_TCHAR *argv[])
21 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
22 int c;
24 while ((c = get_opts ()) != -1)
25 switch (c)
27 case 'k':
28 ior = get_opts.opt_arg ();
29 break;
31 case '?':
32 default:
33 ACE_ERROR_RETURN ((LM_ERROR,
34 "usage: %s "
35 "-k <ior> "
36 "\n",
37 argv [0]),
38 -1);
40 // Indicates successful parsing of the command line
41 return 0;
44 ACE_THR_FUNC_RETURN failsafe (void *)
46 test_lock.acquire();
47 ACE_Time_Value timeout = ACE_OS::gettimeofday() + ACE_Time_Value (10,0);
48 cond.wait(&timeout);
49 test_lock.release();
50 if (!is_ok)
52 ACE_DEBUG ((LM_DEBUG, "FAILURE: failsafe timed out\n"));
53 orb->shutdown(0);
54 ACE_OS::exit(1);
56 return 0;
59 int
60 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
62 try
64 orb = CORBA::ORB_init (argc, argv);
65 CORBA::Object_var object =
66 orb->resolve_initial_references ("RTORB");
68 RTCORBA::RTORB_var rt_orb =
69 RTCORBA::RTORB::_narrow (object.in ());
71 // Set the tcp protocol properties
72 RTCORBA::TCPProtocolProperties_var tcp_properties =
73 rt_orb->create_tcp_protocol_properties (ACE_DEFAULT_MAX_SOCKET_BUFSIZ,
74 ACE_DEFAULT_MAX_SOCKET_BUFSIZ,
75 1, 0, 1, 0);
76 RTCORBA::ProtocolList protocols;
77 protocols.length (1);
78 protocols[0].protocol_type = 0;
79 protocols[0].transport_protocol_properties =
80 RTCORBA::ProtocolProperties::_duplicate (tcp_properties.in ());
81 protocols[0].orb_protocol_properties =
82 RTCORBA::ProtocolProperties::_nil ();
84 CORBA::PolicyList policy_list;
86 policy_list.length (1);
87 policy_list[0] =
88 rt_orb->create_client_protocol_policy (protocols);
89 object = orb->resolve_initial_references ("ORBPolicyManager");
91 CORBA::PolicyManager_var policy_manager =
92 CORBA::PolicyManager::_narrow (object.in ());
94 policy_manager->set_policy_overrides (policy_list,
95 CORBA::SET_OVERRIDE);
97 // start the failsafe thread. It will expire in 10 seconds and
98 // terminate with a failure if the following does not complete.
100 ACE_Thread::spawn (failsafe);
102 object = orb->string_to_object ("corbaloc::localhost:5678/Test");
103 Test::Hello_var hello = Test::Hello::_narrow(object.in());
105 is_ok = true;
106 test_lock.acquire ();
107 cond.signal();
108 test_lock.release ();
109 ACE_DEBUG ((LM_DEBUG, "SUCCESS: test did not spin.\n"));
111 CORBA::String_var the_string = hello->get_string ();
113 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
114 the_string.in ()));
116 hello->shutdown ();
117 orb->destroy ();
119 catch (const CORBA::Exception& ex)
121 ex._tao_print_exception ("Exception caught:");
122 return 1;
125 return 0;