我正在使用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
異常。
感謝
@Reimeus我與持久壽命政策也試過(我添加的代碼我的問題)。但它也不起作用。 –
什麼不起作用,你如何檢查? – tuergeist
@tuergeist我寫了一個使用'ORB :: string_to_object'來解析corbaloc地址'corbaloc:iiop:localhost:12345/hello'的客戶端,但它找不到遠程對象。 –