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
[])
59 CORBA::ORB_init (argc
, argv
);
61 Service_Shutdown_Functor
killer (orb
.in ());
62 Service_Shutdown
kill_contractor (killer
);
64 CORBA::Object_var poa_object
=
65 orb
->resolve_initial_references ("RootPOA");
67 if (CORBA::is_nil (poa_object
.in ()))
68 ACE_ERROR_RETURN ((LM_ERROR
,
69 "SERVER (%P): Unable to initialize the POA.\n"),
72 PortableServer::POA_var root_poa
=
73 PortableServer::POA::_narrow (poa_object
.in ());
75 PortableServer::POAManager_var poa_manager
=
76 root_poa
->the_POAManager ();
78 if (parse_args (argc
, argv
) != 0)
81 Test_i
server_impl (orb
.in ());
83 PortableServer::ObjectId_var tmp
=
84 root_poa
->activate_object (&server_impl
);
87 CORBA::Object_var server
= server_impl
._this();
89 CORBA::String_var ior
=
90 orb
->object_to_string (server
.in ());
92 // If the ior_output_file exists, output the ior to it
93 if (ior_output_file
!= 0)
95 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
97 ACE_ERROR_RETURN ((LM_ERROR
,
98 "SERVER (%P): Cannot open output file "
99 "for writing IOR: %s",
102 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
103 ACE_OS::fclose (output_file
);
105 ACE_DEBUG ((LM_DEBUG
,
106 "SERVER (%P): Activated as file://%s\n",
111 ACE_DEBUG ((LM_DEBUG
,
112 "SERVER (%P): Activated as <%s>\n",
116 poa_manager
->activate();
120 root_poa
->destroy (1, 1);
122 catch (const CORBA::Exception
& ex
)
124 ex
._tao_print_exception ("SERVER (%P): Caught exception:");