1 #include "orbsvcs/CosNamingC.h"
2 #include "Messenger_i.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("Messenger.ior");
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_output_file
= get_opts
.opt_arg ();
26 // Indicates successful parsing of the command line
31 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
35 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
37 if (parse_args (argc
, argv
) != 0)
40 CORBA::Object_var rootObj
= orb
->resolve_initial_references("NameService");
42 CosNaming::NamingContext_var rootNC
=
43 CosNaming::NamingContext::_narrow(rootObj
.in());
45 // Get reference to Root POA.
46 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
48 PortableServer::POA_var poa
= PortableServer::POA::_narrow(obj
.in());
50 // Activate POA manager
51 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
56 PortableServer::Servant_var
<Messenger_i
> messenger_servant
=
57 new Messenger_i(orb
.in());
59 Messenger_var messenger
= messenger_servant
->_this();
63 name
[0].id
= CORBA::string_dup("MessengerService");
65 rootNC
->rebind(name
, messenger
.in());
67 CORBA::String_var str
= orb
->object_to_string (messenger
.in());
68 std::ofstream
iorFile (ACE_TEXT_ALWAYS_CHAR(ior_output_file
));
69 iorFile
<< str
.in () << std::endl
;
71 std::cout
<< "IOR written to file " << ior_output_file
<< std::endl
;
76 catch(const CORBA::Exception
& ex
)
78 std::cerr
<< "MessengerServer::Caught exception: " << ex
<< std::endl
;