2014-01-22 35 views
2

我正在使用MICO創建一個C++ CORBA服務器。MICBA CORBA服務器與corbaloc訪問

在我的系統中,客戶端應該能夠使用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異常。

感謝

+0

@Reimeus我與持久壽命政策也試過(我添加的代碼我的問題)。但它也不起作用。 –

+0

什麼不起作用,你如何檢查? – tuergeist

+0

@tuergeist我寫了一個使用'ORB :: string_to_object'來解析corbaloc地址'corbaloc:iiop:localhost:12345/hello'的客戶端,但它找不到遠程對象。 –

回答

1

對於美香,你必須使用POA層次的corbalo網址爲好。對於你的例子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

+0

我試過'corbaloc :: localhost:12345/childPOA/hello',但我總是得到一個'CORBA :: OBJECT_NOT_EXIST'例外 –

+0

它的工作,謝謝。我必須使用'server.exe -ORBIIOPAddr inet:localhost:12345 -POAImplName MyService'和具有'client.exe corbaloc :: localhost:12345/MyService/childPOA/hello'的客戶端啓動服務器。 –