1 #include "Messenger_i.h"
2 #include "MessengerS.h"
3 #include "ServerInitializer.h"
5 #include "tao/ORBInitializer_Registry.h"
6 // Ensure that the PI_Server library is linked in when building statically
7 #include "tao/PI_Server/PI_Server.h"
8 #include "orbsvcs/CosNamingC.h"
12 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
16 ServerInitializer
*temp_initializer
= 0;
17 temp_initializer
= new ServerInitializer
;
19 PortableInterceptor::ORBInitializer_var orb_initializer
=
22 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
25 CORBA::ORB_init (argc
, argv
, "Server ORB");
27 //Get reference to Root POA
28 CORBA::Object_var obj
= orb
->resolve_initial_references( "RootPOA" );
29 PortableServer::POA_var poa
= PortableServer::POA::_narrow( obj
.in() );
31 // Activate POA Manager
32 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
36 PortableServer::Servant_var
<Messenger_i
> messenger_servant
=
39 // Find the Naming Service
40 CORBA::Object_var naming_obj
=
41 orb
->resolve_initial_references( "NameService" );
42 CosNaming::NamingContext_var root
=
43 CosNaming::NamingContext::_narrow( naming_obj
.in() );
44 if( CORBA::is_nil( root
.in() ) ) {
45 std::cerr
<< "Nil Naming Context reference" << std::endl
;
52 name
[0].id
= CORBA::string_dup( "Messenger" );
54 PortableServer::ObjectId_var oid
=
55 poa
->activate_object( messenger_servant
.in() );
56 CORBA::Object_var messenger_obj
= poa
->id_to_reference( oid
.in() );
58 root
->rebind(name
, messenger_obj
.in());
60 std::cout
<< "Messenger bound in Naming Service" << std::endl
;
67 catch(const CORBA::Exception
& ex
)
69 std::cerr
<< "Caught CORBA exception: " << ex
<< std::endl
;