1 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "orbsvcs/Shutdown_Utilities.h"
6 const ACE_TCHAR
*ior_output_file
= 0;
8 class Service_Shutdown_Functor
: public Shutdown_Functor
11 Service_Shutdown_Functor (CORBA::ORB_ptr orb
)
12 : orb_(CORBA::ORB::_duplicate (orb
))
16 void operator() (int which_signal
)
19 "shutting down on signal %d\n", which_signal
));
20 (void) this->orb_
->shutdown ();
28 parse_args (int argc
, ACE_TCHAR
*argv
[])
30 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
33 while ((c
= get_opts ()) != -1)
37 ior_output_file
= get_opts
.opt_arg ();
41 ACE_ERROR_RETURN ((LM_ERROR
,
42 "SERVER (%P): usage: %s "
48 // Indicates successful parsing of the command line
53 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
58 CORBA::ORB_init (argc
, argv
);
60 Service_Shutdown_Functor
killer (orb
.in ());
61 Service_Shutdown
kill_contractor (killer
);
63 CORBA::Object_var poa_object
=
64 orb
->resolve_initial_references ("RootPOA");
66 if (CORBA::is_nil (poa_object
.in ()))
67 ACE_ERROR_RETURN ((LM_ERROR
,
68 "SERVER (%P): Unable to initialize the POA.\n"),
71 PortableServer::POA_var root_poa
=
72 PortableServer::POA::_narrow (poa_object
.in ());
74 PortableServer::POAManager_var poa_manager
=
75 root_poa
->the_POAManager ();
77 if (parse_args (argc
, argv
) != 0)
80 Test_i
server_impl (orb
.in ());
82 PortableServer::ObjectId_var tmp
=
83 root_poa
->activate_object (&server_impl
);
86 CORBA::Object_var server
= server_impl
._this();
88 CORBA::String_var ior
=
89 orb
->object_to_string (server
.in ());
91 // If the ior_output_file exists, output the ior to it
92 if (ior_output_file
!= 0)
94 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
96 ACE_ERROR_RETURN ((LM_ERROR
,
97 "SERVER (%P): Cannot open output file "
98 "for writing IOR: %s",
101 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
102 ACE_OS::fclose (output_file
);
104 ACE_DEBUG ((LM_DEBUG
,
105 "SERVER (%P): Activated as file://%s\n",
110 ACE_DEBUG ((LM_DEBUG
,
111 "SERVER (%P): Activated as <%s>\n",
115 poa_manager
->activate();
119 root_poa
->destroy (true, true);
121 catch (const CORBA::Exception
& ex
)
123 ex
._tao_print_exception ("SERVER (%P): Caught exception:");