1、创建ORB、poa、poa_manager对象
CORBA::ORB_var orb = init_orb_with_naming_service(argc,argv);
CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); TAO_ORB_Manager orb_manager(orb.in(),poa.in(),poa_manager.in());
如果一切都采用默认的话,可以直接用TAO_ORB_Manager这个类协助创建。
2、创建对象并注册服务
CORBA::Object_var naming_context_object = orb->resolve_initial_references (¡±NameService¡±); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow (naming_context_object.in ()); CosNaming::Name name (1);
///创建对象
slib_ChannelFactory_i channelFactory_i(poa.in(),poa_manager.in());
///用默认poa激活
::slib::ChannelFactory_var channelFactory=channelFactory_i._this();
name.length (1);
name[0].id = CORBA::string_dup (”myFactory”);
std::cout<<”开始注册服务”<
try{
naming_context->bind (name, channelFactory.in ());
}catch(CosNaming::NamingContext::AlreadyBound& ex){
naming_context->rebind (name, channelFactory.in ());
}