3 #include "ace/OS_NS_stdio.h"
4 #include "orbsvcs/Shutdown_Utilities.h"
5 #include "ace/Get_Opt.h"
8 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT("iorfile");
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
16 while ((c
= get_opts ()) != -1)
20 ior_output_file
= get_opts
.opt_arg ();
25 ACE_ERROR_RETURN ((LM_ERROR
,
32 // Indicates successful parsing of the command line
36 class Service_Shutdown_Functor
: public Shutdown_Functor
39 Service_Shutdown_Functor (CORBA::ORB_ptr orb
)
40 : orb_(CORBA::ORB::_duplicate (orb
))
44 void operator() (int which_signal
)
47 "shutting down on signal %d\n", which_signal
));
48 (void) this->orb_
->shutdown ();
56 write_ior_to_file (const char *ior
)
58 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
62 ACE_ERROR_RETURN ((LM_ERROR
,
63 "Cannot open output files for writing IOR: %s\n",
68 int result
= ACE_OS::fprintf (output_file
,
73 ACE_ERROR_RETURN ((LM_ERROR
,
74 "ACE_OS::fprintf failed while writing %s to %s\n",
80 ACE_OS::fclose (output_file
);
86 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
90 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
92 if (parse_args (argc
, argv
) != 0)
95 Service_Shutdown_Functor
killer (orb
.in ());
96 Service_Shutdown
kill_contractor (killer
);
98 CORBA::Object_var poa_object
=
99 orb
->resolve_initial_references ("RootPOA");
101 PortableServer::POA_var root_poa
=
102 PortableServer::POA::_narrow (poa_object
.in ());
104 PortableServer::POAManager_var poa_manager
=
105 root_poa
->the_POAManager ();
107 poa_manager
->activate ();
109 inventory_i servant_impl
;
111 warehouse::inventory_var servant
=
112 servant_impl
._this ();
114 CORBA::String_var ior
=
115 orb
->object_to_string (servant
.in ());
117 int write_result
= write_ior_to_file (ior
.in ());
119 if (write_result
!= 0)
121 ACE_ERROR_RETURN ((LM_ERROR
,
123 "write_ior_to_file"),
129 root_poa
->destroy (true, true);
133 catch (const CORBA::Exception
& ex
)
135 ex
._tao_print_exception ("server exception:");