Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Nested_Upcall_Crash / server.cpp
blob47b5e700d19c6b9726e91ab7496fcf8bc2dbdfe1
1 #include "Server_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"
8 #include "ace/OS_NS_time.h"
10 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
11 unsigned int seed;
12 int payload_size = 4;
14 int
15 parse_args (int argc, ACE_TCHAR *argv[]);
17 class Sleeper : public ACE_Event_Handler
19 public:
20 Sleeper(CORBA::ORB_ptr orb);
22 virtual int handle_timeout (ACE_Time_Value const & current_time,
23 void const * arg);
25 private:
26 CORBA::ORB_var orb_;
29 int
30 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
32 try
34 CORBA::ORB_var orb =
35 CORBA::ORB_init (argc, argv);
37 CORBA::Object_var poa_object =
38 orb->resolve_initial_references("RootPOA");
40 PortableServer::POA_var root_poa =
41 PortableServer::POA::_narrow (poa_object.in ());
43 if (CORBA::is_nil (root_poa.in ()))
44 ACE_ERROR_RETURN ((LM_ERROR,
45 " (%P|%t) Panic: nil RootPOA\n"),
46 1);
48 PortableServer::POAManager_var poa_manager =
49 root_poa->the_POAManager ();
51 CORBA::Object_var object =
52 orb->resolve_initial_references ("PolicyCurrent");
54 CORBA::PolicyCurrent_var policy_current =
55 CORBA::PolicyCurrent::_narrow (object.in ());
57 if (CORBA::is_nil (policy_current.in ()))
59 ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n"));
60 return 1;
62 CORBA::Any scope_as_any;
63 scope_as_any <<= Messaging::SYNC_WITH_SERVER;
65 CORBA::PolicyList policies(1); policies.length (1);
66 policies[0] =
67 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
68 scope_as_any);
70 policy_current->set_policy_overrides (policies,
71 CORBA::ADD_OVERRIDE);
73 policies[0]->destroy ();
75 seed = (unsigned int) ACE_OS::gethrtime ();
77 if (parse_args (argc, argv) != 0)
78 return 1;
80 ACE_DEBUG ((LM_DEBUG, "SEED = %u\n", seed));
82 Server_Peer *impl;
83 ACE_NEW_RETURN (impl,
84 Server_Peer (seed, orb.in (), payload_size),
85 1);
86 PortableServer::ServantBase_var owner_transfer(impl);
88 PortableServer::ObjectId_var id =
89 root_poa->activate_object (impl);
91 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
93 Test::Peer_var peer =
94 Test::Peer::_narrow (object_act.in ());
96 CORBA::String_var ior =
97 orb->object_to_string (peer.in ());
99 // If the ior_output_file exists, output the ior to it
100 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
101 if (output_file == 0)
102 ACE_ERROR_RETURN ((LM_ERROR,
103 "Cannot open output file for writing IOR: %s",
104 ior_output_file),
106 ACE_OS::fprintf (output_file, "%s", ior.in ());
107 ACE_OS::fclose (output_file);
109 poa_manager->activate ();
111 Sleeper sleeper (orb.in ());
113 ACE_Time_Value interval(0, 500000);
114 ACE_Reactor * reactor = orb->orb_core()->reactor();
115 reactor->schedule_timer(&sleeper, 0, interval, interval);
117 // ACE_Time_Value run_time(600, 0);
118 // orb->run (run_time);
119 orb->run ();
121 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
123 root_poa->destroy (1, 1);
125 orb->destroy ();
127 catch (const CORBA::Exception& ex)
129 ex._tao_print_exception ("Exception caught:");
130 return 1;
133 return 0;
137 parse_args (int argc, ACE_TCHAR *argv[])
139 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:s:b:"));
140 int c;
142 while ((c = get_opts ()) != -1)
143 switch (c)
145 case 'o':
146 ior_output_file = get_opts.opt_arg ();
147 break;
149 case 's':
150 seed = ACE_OS::atoi(get_opts.opt_arg ());
151 break;
153 case 'b':
154 payload_size = ACE_OS::atoi(get_opts.opt_arg ());
155 break;
157 case '?':
158 default:
159 ACE_ERROR_RETURN ((LM_ERROR,
160 "usage: %s "
161 "-o <iorfile> "
162 "-s <seed> "
163 "-b <payload_size> "
164 "\n",
165 argv [0]),
166 -1);
168 // Indicates successful parsing of the command line
169 return 0;
172 Sleeper::Sleeper(CORBA::ORB_ptr orb)
173 : orb_ (CORBA::ORB::_duplicate (orb))
178 Sleeper::handle_timeout (ACE_Time_Value const & ,
179 void const *)
181 // ACE_DEBUG((LM_DEBUG, "(%P|%t) - Sleeper::handle_timeout()\n"));
182 ACE_Time_Value clk_tck (0, Clock_Ticks::get_usecs_per_tick ());
183 this->orb_->perform_work(clk_tck);
185 return 0;