4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR
*ior_file
= 0;
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
15 while ((c
= get_opts ()) != -1)
19 ior_file
= get_opts
.opt_arg ();
22 ACE_ERROR_RETURN ((LM_ERROR
,
23 ACE_TEXT ("Usage: %s ")
24 ACE_TEXT ("-o IOR\n"),
33 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
38 CORBA::ORB_init (argc
, argv
);
40 CORBA::Object_var poa_object
=
41 orb
->resolve_initial_references ("RootPOA");
43 if (CORBA::is_nil (poa_object
.in ()))
44 ACE_ERROR_RETURN ((LM_ERROR
,
45 ACE_TEXT ("SERVER: Unable to initialize the POA.\n")),
48 PortableServer::POA_var root_poa
=
49 PortableServer::POA::_narrow (poa_object
.in ());
51 PortableServer::POAManager_var poa_manager
=
52 root_poa
->the_POAManager ();
54 if (::parse_args (argc
, argv
) != 0)
59 ACE_NEW_RETURN (servant
,
60 test_i (0, orb
.in ()),
62 PortableServer::ServantBase_var
safe (servant
);
64 PortableServer::ObjectId_var oid
=
65 root_poa
->activate_object (servant
);
67 CORBA::Object_var obj
=
68 root_poa
->servant_to_reference (servant
);
70 CORBA::String_var ior
=
71 orb
->object_to_string (obj
.in ());
74 ACE_TEXT ("SERVER: test_i servant: <%C>\n"),
77 poa_manager
->activate ();
80 FILE *output_file
= ACE_OS::fopen (ior_file
, "w");
82 ACE_ERROR_RETURN ((LM_ERROR
,
83 ACE_TEXT ("SERVER: Cannot open output file <%s> ")
84 ACE_TEXT ("for writting IOR: %C"),
88 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
89 ACE_OS::fclose (output_file
);
91 // Run the ORB event loop.
94 root_poa
->destroy (true, true);
98 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("SERVER: Event loop finished.\n")));
100 catch (const CORBA::Exception
& ex
)
102 ex
._tao_print_exception ("Caught exception:");