2 #include "ace/OS_NS_stdio.h"
3 #include "ace/OS_NS_time.h"
4 #include "ace/Get_Opt.h"
6 #include "tao/ORB_Core.h"
8 /***************************/
9 /*** Servant Declaration ***/
12 : public virtual POA_Test::AMH_Roundtrip
15 ST_AMH_Servant (CORBA::ORB_ptr orb
);
17 void test_method (Test::AMH_RoundtripResponseHandler_ptr _tao_rh
,
18 Test::Timestamp send_time
);
20 //FUZZ: disable check_for_lack_ACE_OS
21 void shutdown (Test::AMH_RoundtripResponseHandler_ptr _tao_rh
);
22 //FUZZ: disable check_for_lack_ACE_OS
29 /***************************/
30 /*** Servant Definition ***/
32 ST_AMH_Servant::ST_AMH_Servant (CORBA::ORB_ptr orb
)
33 : orb_ (CORBA::ORB::_duplicate (orb
))
38 ST_AMH_Servant::test_method (Test::AMH_RoundtripResponseHandler_ptr _tao_rh
,
41 // Throw an overload exception
42 Test::ServerOverload
*ts
= new Test::ServerOverload
;
44 // Caller owns the memory now. Need not delete 'ts'
45 Test::AMH_RoundtripExceptionHolder
holder (ts
);
49 _tao_rh
->test_method_excep (&holder
);
57 ST_AMH_Servant::shutdown (Test::AMH_RoundtripResponseHandler_ptr
/*_tao_rh*/)
59 this->orb_
->shutdown (0);
62 /*** Server Declaration ***/
65 Class that performs all 'dirty' initialisation work that is common to
66 all the AMH servers and 'hides' all the common ORB functions.
71 ST_AMH_Server (int argc
, ACE_TCHAR
**argv
);
72 virtual ~ST_AMH_Server ();
74 /// ORB initialisation stuff
75 int start_orb_and_poa (void);
77 /// register the servant with the poa
78 virtual void register_servant (ST_AMH_Servant
*servant
);
80 /// orb-perform_work () abstraction
81 virtual void run_event_loop ();
84 /// Accesor method (for servants) to the initialized ORB
85 CORBA::ORB_ptr
orb () { return this->orb_
.in (); }
90 const ACE_TCHAR
*ior_output_file_
;
92 PortableServer::POA_var root_poa_
;
95 /// Write servant IOR to file specified with the '-o' option
96 int write_ior_to_file (CORBA::String_var ior
);
99 /*** Server Declaration ***/
101 ST_AMH_Server::ST_AMH_Server (int argc
, ACE_TCHAR
**argv
)
105 this->ior_output_file_
= ACE_TEXT ("test.ior");
106 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
109 while ((c
= get_opts ()) != -1)
113 this->ior_output_file_
= get_opts
.opt_arg ();
118 ST_AMH_Server::~ST_AMH_Server ()
122 this->root_poa_
->destroy (1, 1);
124 this->orb_
->destroy ();
126 catch (const CORBA::Exception
& ex
)
128 ex
._tao_print_exception ("Exception caught:");
134 ST_AMH_Server::start_orb_and_poa (void)
138 this->orb_
= CORBA::ORB_init (this->argc_
, this->argv_
);
140 CORBA::Object_var poa_object
=
141 this->orb_
->resolve_initial_references("RootPOA");
143 if (CORBA::is_nil (poa_object
.in ()))
144 ACE_ERROR_RETURN ((LM_ERROR
,
145 " (%P|%t) Unable to initialize the POA.\n"),
148 this->root_poa_
= PortableServer::POA::_narrow (poa_object
.in ());
150 PortableServer::POAManager_var poa_manager
=
151 this->root_poa_
->the_POAManager ();
153 poa_manager
->activate ();
155 catch (const CORBA::Exception
& ex
)
157 ex
._tao_print_exception ("Exception caught:");
165 ST_AMH_Server::register_servant (ST_AMH_Servant
*servant
)
169 CORBA::Object_var poa_object
=
170 this->orb_
->resolve_initial_references("RootPOA");
172 PortableServer::POA_var root_poa
=
173 PortableServer::POA::_narrow (poa_object
.in ());
175 PortableServer::ObjectId_var id
=
176 root_poa
->activate_object (servant
);
178 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
180 Test::Roundtrip_var roundtrip
=
181 Test::Roundtrip::_narrow (object
.in ());
183 CORBA::String_var ior
=
184 this->orb_
->object_to_string (roundtrip
.in ());
186 (void) this->write_ior_to_file (ior
);
188 catch (const CORBA::Exception
& ex
)
190 ex
._tao_print_exception ("Exception caught:");
195 ST_AMH_Server::run_event_loop ()
199 ACE_Time_Value
period (0, 11000);
200 while (!this->orb_
->orb_core ()->has_shutdown ())
202 this->orb_
->perform_work (&period
);
205 catch (const CORBA::Exception
&)
210 ST_AMH_Server::write_ior_to_file (CORBA::String_var ior
)
212 // If the ior_output_file exists, output the ior to it
213 FILE *output_file
= ACE_OS::fopen (ST_AMH_Server::ior_output_file_
,
215 if (output_file
== 0)
217 ACE_ERROR ((LM_ERROR
,
218 "Cannot open output file for writing IOR: %s",
219 ST_AMH_Server::ior_output_file_
));
223 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
224 ACE_OS::fclose (output_file
);
230 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
232 ST_AMH_Server
amh_server (argc
, argv
);
234 amh_server
.start_orb_and_poa ();
236 ST_AMH_Servant
servant (amh_server
.orb ());
238 amh_server
.register_servant (&servant
);
240 amh_server
.run_event_loop ();