1 #include "Messenger_i.h"
2 #include "orbsvcs/CosNamingC.h"
5 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
9 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
11 //Get reference to Root POA
12 CORBA::Object_var obj
= orb
->resolve_initial_references( "RootPOA" );
13 PortableServer::POA_var poa
= PortableServer::POA::_narrow( obj
.in() );
15 // Activate POA Manager
16 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
19 // Find the Naming Service
20 CORBA::Object_var naming_obj
=
21 orb
->resolve_initial_references( "NameService" );
22 CosNaming::NamingContext_var root
=
23 CosNaming::NamingContext::_narrow( naming_obj
.in() );
24 if (CORBA::is_nil(root
.in())) {
25 std::cerr
<< "Nil Naming Context reference" << std::endl
;
29 // Bind the example Naming Context, if necessary
32 name
[0].id
= CORBA::string_dup( "example" );
34 CORBA::Object_var dummy
= root
->resolve( name
);
36 catch(const CosNaming::NamingContext::NotFound
&) {
37 CosNaming::NamingContext_var dummy
= root
->bind_new_context( name
);
40 // Bind the Messenger object
42 name
[1].id
= CORBA::string_dup( "Messenger" );
45 PortableServer::Servant_var
<Messenger_i
> messenger_servant
= new Messenger_i
;
46 PortableServer::ObjectId_var oid
= poa
->activate_object(messenger_servant
.in());
47 obj
= poa
->id_to_reference( oid
.in() );
48 root
->rebind(name
, obj
.in());
50 std::cout
<< "Messenger object bound in Naming Service" << std::endl
;
56 catch(const CORBA::Exception
& ex
) {
57 std::cerr
<< "Caught a CORBA exception: " << ex
<< std::endl
;