3 #include "ace/OS_NS_stdio.h"
4 #include "orbsvcs/Shutdown_Utilities.h"
5 #include "ace/Get_Opt.h"
9 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT("iorfile");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
37 class Service_Shutdown_Functor
: public Shutdown_Functor
40 Service_Shutdown_Functor (CORBA::ORB_ptr orb
)
41 : orb_(CORBA::ORB::_duplicate (orb
))
45 void operator() (int which_signal
)
48 "shutting down on signal %d\n", which_signal
));
49 (void) this->orb_
->shutdown ();
57 write_ior_to_file (const char *ior
)
59 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
63 ACE_ERROR_RETURN ((LM_ERROR
,
64 "Cannot open output files for writing IOR: %s\n",
69 int result
= ACE_OS::fprintf (output_file
,
74 ACE_ERROR_RETURN ((LM_ERROR
,
75 "ACE_OS::fprintf failed while writing %s to %s\n",
81 ACE_OS::fclose (output_file
);
87 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
91 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
93 if (parse_args (argc
, argv
) != 0)
96 Service_Shutdown_Functor
killer (orb
.in ());
97 Service_Shutdown
kill_contractor (killer
);
99 CORBA::Object_var poa_object
=
100 orb
->resolve_initial_references ("RootPOA");
102 PortableServer::POA_var root_poa
=
103 PortableServer::POA::_narrow (poa_object
.in ());
105 PortableServer::POAManager_var poa_manager
=
106 root_poa
->the_POAManager ();
108 poa_manager
->activate ();
110 inventory_i servant_impl
;
112 warehouse::inventory_var servant
=
113 servant_impl
._this ();
115 CORBA::String_var ior
=
116 orb
->object_to_string (servant
.in ());
118 int write_result
= write_ior_to_file (ior
.in ());
120 if (write_result
!= 0)
122 ACE_ERROR_RETURN ((LM_ERROR
,
124 "write_ior_to_file"),
130 root_poa
->destroy (1,
135 catch (const CORBA::Exception
& ex
)
137 ex
._tao_print_exception ("server exception:");