gpt4 book ai didi

c++ - 具有 corbaloc 访问权限的 MICO CORBA 服务器

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:24:33 26 4
gpt4 key购买 nike

我正在使用 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();

编辑2:我用一个客户端测试了服务器,该客户端尝试 string_to_object 以下 corbaloc 地址:

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

但它们都不起作用。我总是得到一个 CORBA::OBJECT_NOT_EXIST 异常。

谢谢

最佳答案

对于 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 启动您的服务可执行文件

关于c++ - 具有 corbaloc 访问权限的 MICO CORBA 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21278886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com