3 #include "Messenger_i.h"
6 #include "ace/Get_Opt.h"
8 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("Messenger.ior");
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 ();
27 // Indicates successful parsing of the command line
32 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
36 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
38 if (parse_args (argc
, argv
) != 0)
41 //Get reference to Root POA
42 CORBA::Object_var obj
= orb
->resolve_initial_references( "RootPOA" );
43 PortableServer::POA_var poa
= PortableServer::POA::_narrow( obj
.in() );
45 // Activate POA Manager
46 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
50 PortableServer::Servant_var
<Messenger_i
> messenger_servant
= new Messenger_i
;
52 // Register the servant with the RootPOA, obtain its object
53 // reference, stringify it, and write it to a file.
54 PortableServer::ObjectId_var oid
=
55 poa
->activate_object( messenger_servant
.in() );
56 CORBA::Object_var messenger_obj
= poa
->id_to_reference( oid
.in() );
57 CORBA::String_var str
= orb
->object_to_string( messenger_obj
.in() );
58 std::ofstream
iorFile( ACE_TEXT_ALWAYS_CHAR(ior_output_file
) );
59 iorFile
<< str
.in() << std::endl
;
61 std::cout
<< "IOR written to file "<< ior_output_file
<< std::endl
;
68 catch(const CORBA::Exception
& ex
) {
69 std::cerr
<< "Caught a CORBA exception: " << ex
<< std::endl
;