MICOR CORBA服务器与corbaloc访问

时间:2014-01-22 09:27:53

标签: c++ corba

我正在使用MICO创建C ++ CORBA服务器。

在我的系统中,客户端应该能够使用corbaloc地址(没有名称服务)直接访问服务器中的corba对象。 你知道MICO是否提供这样的功能吗?我该如何实现呢?我尝试过:

ORB_ptr orb = CORBA::ORB_init (argc, argv, "mico-local-orb");
Object_var obj = orb -> resolve_initial_references( "RootPOA" );
PortableServer::POA_var poa = PortableServer::POA::_narrow( obj );
PortableServer::POAManager_var pman = poa -> the_POAManager();
pman -> activate();

PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId( "hello" );

HelloImpl* servant = new HelloImpl();

poa -> activate_object_with_id( oid.in(), servant );
servant -> _remove_ref();

orb -> run();

此代码适用于OMNIORB,但不适用于MICO。

编辑:我也尝试过持久的生命周期政策,但它也不起作用:

ORB_ptr orb = ORB_init( argc, argv );
Object_var obj = orb -> resolve_initial_references( "RootPOA" );
PortableServer::POA_var poa = PortableServer::POA::_narrow( obj );
PortableServer::POAManager_var pman = poa -> the_POAManager();
pman -> activate();

PortableServer::LifespanPolicy_var lifespan = 
    poa -> create_lifespan_policy( PortableServer::PERSISTENT );
PortableServer::IdAssignmentPolicy_var idassignment = 
    poa ->  create_id_assignment_policy ( PortableServer::USER_ID );
CORBA::PolicyList policies( 2 );
policies.length( 2 );
policies[0] = PortableServer::IdAssignmentPolicy::_duplicate( idassignment );
policies[1] = PortableServer::LifespanPolicy::_duplicate( lifespan );
PortableServer::POA_var child_poa = 
    poa -> create_POA( "childPOA", pman.in(), policies );
PortableServer::POAManager_var child_pman = child_poa -> the_POAManager();
child_pman -> activate();

idassignment -> destroy();
lifespan -> destroy();

HelloImpl* servant = new HelloImpl();

PortableServer::ObjectId_var oid = child_poa -> activate_object( servant );
CORBA::Object_var ref = child_poa -> id_to_reference( oid.in() );
PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId( "hello" );
child_poa -> activate_object_with_id ( oid.in (), servant );

orb -> run();

EDIT2: 我用一个尝试string_to_object以下corbaloc地址的客户端测试了服务器:

  • corbaloc:iiop:localhost:12345/hello
  • corbaloc:iiop:localhost:12345/childPOA/hello

但它们都没有奏效。我总是得到CORBA::OBJECT_NOT_EXIST例外。

由于

1 个答案:

答案 0 :(得分:1)

对于Mico,你必须在corbalo url中使用poa层次结构。对于您的示例corbaloc::localhost:12345/childPOA/hello应该有效。

另见the Diploma thesis of Frank Pilhofer, the implementor of Mico's POA,其中说明了

 create a persistent POA with the name ``MyPOA'', and then activate an object 
 using the ``MyObject'' Object Id, you could refer to that object using the IOR

  iioploc://thishost:1234/MyService/MyPOA/MyObject

编辑:您必须使用服务名称-POAImplName MyService

启动服务可执行文件