2 // This initializes an ORB, a POA, an Object within that POA, and
3 // obtains and prints an IOR for that Object.
5 #include "tao/PortableServer/PortableServer.h"
6 #include "ace/Get_Opt.h"
10 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
18 while ((c
= get_opts ()) != -1)
22 ior_output_file
= get_opts
.opt_arg ();
27 ACE_ERROR_RETURN ((LM_ERROR
,
34 // Indicates successful parsing of the command line
39 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
43 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
45 CORBA::Object_var poa_object
=
46 orb
->resolve_initial_references ("RootPOA");
48 PortableServer::POA_var rp
=
49 PortableServer::POA::_narrow(poa_object
.in());
50 if (CORBA::is_nil (rp
.in()))
51 ACE_ERROR_RETURN ((LM_ERROR
, "(%P|%t) panic: nil root poa\n"), 1);
53 if (parse_args (argc
, argv
) != 0)
56 bogus
* bogus_impl
= new bogus();
57 PortableServer::ServantBase_var
owner_transfer(bogus_impl
);
58 PortableServer::ObjectId_var id
=
59 rp
->activate_object (bogus_impl
);
61 CORBA::Object_var object
= rp
->id_to_reference (id
.in ());
63 Test::bogus_var b
= Test::bogus::_narrow (object
.in ());
64 CORBA::String_var ior
=
65 orb
->object_to_string (b
.in());
67 // Output the IOR to the <ior_output_file>
68 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
70 ACE_ERROR_RETURN ((LM_ERROR
,
71 "Cannot open output file for writing IOR: %s\n",
74 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
75 ACE_OS::fclose (output_file
);
80 catch (const CORBA::Exception
& e
)
82 e
._tao_print_exception ("Caught exception:");