1 #include "Messenger_i.h"
2 #include "orbsvcs/CosNamingC.h"
3 #include "orbsvcs/Naming/Naming_Client.h"
6 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
10 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
12 //Get reference to Root POA
13 CORBA::Object_var obj
= orb
->resolve_initial_references( "RootPOA" );
14 PortableServer::POA_var poa
= PortableServer::POA::_narrow( obj
.in() );
16 // Activate POA Manager
17 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
20 // Find the Naming Service
21 TAO_Naming_Client naming_client
;
23 if(naming_client
.init(orb
.in()) != 0){
24 std::cerr
<< "Could not initialize naming client." << std::endl
;
28 // Bind the example Naming Context, if necessary
31 name
[0].id
= CORBA::string_dup("example");
33 CORBA::Object_var dummy
= naming_client
->resolve(name
);
35 catch(const CosNaming::NamingContext::NotFound
&) {
36 CosNaming::NamingContext_var dummy
= naming_client
->bind_new_context( name
);
39 // Bind the Messenger object
41 name
[1].id
= CORBA::string_dup( "Messenger" );
44 PortableServer::Servant_var
<Messenger_i
> servant
= new Messenger_i
;
45 PortableServer::ObjectId_var oid
= poa
->activate_object(servant
.in());
46 obj
= poa
->id_to_reference(oid
.in());
47 naming_client
->rebind(name
, obj
.in());
49 std::cout
<< "Messenger object bound in Naming Service" << std::endl
;
55 catch(const CORBA::Exception
& ex
) {
56 std::cerr
<< "Caught a CORBA exception: " << ex
<< std::endl
;