Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Nested_Upcall_Crash / client.cpp
blobf2127345363b803907ae5d0c7e46f722079b08e5
1 #include "Client_Peer.h"
2 #include "Clock_Ticks.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "tao/ORB_Core.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Reactor.h"
9 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[]);
14 class Timer : public ACE_Event_Handler
16 public:
17 Timer(Test::Peer_ptr local_peer,
18 Test::Peer_ptr remote_peer);
20 virtual int handle_timeout (ACE_Time_Value const & current_time,
21 void const * arg);
23 private:
24 Test::Peer_var local_peer_;
25 Test::Peer_var remote_peer_;
28 int
29 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
31 try
33 CORBA::ORB_var orb =
34 CORBA::ORB_init (argc, argv);
36 CORBA::Object_var poa_object =
37 orb->resolve_initial_references("RootPOA");
39 PortableServer::POA_var root_poa =
40 PortableServer::POA::_narrow (poa_object.in ());
42 if (CORBA::is_nil (root_poa.in ()))
43 ACE_ERROR_RETURN ((LM_ERROR,
44 " (%P|%t) Panic: nil RootPOA\n"),
45 1);
47 PortableServer::POAManager_var poa_manager =
48 root_poa->the_POAManager ();
50 CORBA::Object_var object =
51 orb->resolve_initial_references ("PolicyCurrent");
53 CORBA::PolicyCurrent_var policy_current =
54 CORBA::PolicyCurrent::_narrow (object.in ());
56 if (CORBA::is_nil (policy_current.in ()))
58 ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n"));
59 return 1;
61 CORBA::Any scope_as_any;
62 scope_as_any <<= Messaging::SYNC_WITH_SERVER;
64 CORBA::PolicyList policies(1); policies.length (1);
65 policies[0] =
66 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
67 scope_as_any);
69 policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
71 policies[0]->destroy ();
73 if (parse_args (argc, argv) != 0)
74 return 1;
76 Client_Peer *impl;
77 ACE_NEW_RETURN (impl,
78 Client_Peer (orb.in ()),
79 1);
80 PortableServer::ServantBase_var owner_transfer(impl);
82 PortableServer::ObjectId_var id =
83 root_poa->activate_object (impl);
85 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
87 Test::Peer_var local_peer =
88 Test::Peer::_narrow (object_act.in ());
90 CORBA::Object_var tmp =
91 orb->string_to_object(ior);
93 Test::Peer_var peer =
94 Test::Peer::_narrow(tmp.in ());
96 if (CORBA::is_nil (peer.in ()))
98 ACE_ERROR_RETURN ((LM_DEBUG,
99 "Nil Test::Peer reference <%s>\n",
100 ior),
104 poa_manager->activate ();
106 Timer timer(local_peer.in (), peer.in ());
108 ACE_Time_Value interval(0, 50 * Clock_Ticks::get_usecs_per_tick ());
109 ACE_Reactor * reactor = orb->orb_core()->reactor();
110 reactor->schedule_timer(&timer, 0, interval, interval);
112 ACE_Time_Value run_time(120, 0);
113 orb->run (run_time);
115 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - event loop finished\n"));
117 root_poa->destroy (1, 1);
119 orb->destroy ();
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("Exception caught:");
124 return 1;
127 return 0;
131 parse_args (int argc, ACE_TCHAR *argv[])
133 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
134 int c;
136 while ((c = get_opts ()) != -1)
137 switch (c)
139 case 'k':
140 ior = get_opts.opt_arg ();
141 break;
143 case '?':
144 default:
145 ACE_ERROR_RETURN ((LM_ERROR,
146 "usage: %s "
147 "-k <ior> "
148 "\n",
149 argv [0]),
150 -1);
152 // Indicates successful parsing of the command line
153 return 0;
156 Timer::Timer(Test::Peer_ptr local_peer,
157 Test::Peer_ptr remote_peer)
158 : local_peer_ (Test::Peer::_duplicate (local_peer))
159 , remote_peer_ (Test::Peer::_duplicate (remote_peer))
164 Timer::handle_timeout (ACE_Time_Value const & ,
165 void const *)
167 Test::Payload data;
168 this->remote_peer_->callme (this->local_peer_.in(), 32, data);
169 return 0;