bool RTSCompExt::getComponentPath(RTC::PortService_ptr source, std::string& out_path) { PortProfile_var portprofile = source->get_port_profile(); if(!CORBA::is_nil(portprofile->owner)){ ComponentProfile_var cprofile; try { cprofile = portprofile->owner->get_component_profile(); } catch (CORBA::SystemException& ex) { MessageView::instance()->putln( MessageView::WARNING, format(_("CORBA %1% (%2%), %3% in RTSComp::getComponentPath()")) % ex._name() % ex._rep_id() % ex.NP_minorString()); return false; } NVList properties = cprofile->properties; for(int index = 0; index < properties.length(); ++index){ string strName(properties[index].name._ptr); if(strName == "naming.names"){ const char* nvValue; properties[index].value >>= nvValue; out_path = string(nvValue); return true; } } }
vector<string> RTSPortExt::getProperty(const string& key) { vector<string> result; NVList properties = port->get_port_profile()->properties; for (int index = 0; index < properties.length(); ++index) { string strName(properties[index].name._ptr); if (strName == key) { const char* nvValue; properties[index].value >>= nvValue; string strValue(nvValue); result = RTCCommonUtil::split(strValue, ','); break; } } return result; }
/*! * @brief add_organization_property() and remove_organization_property() */ void test_remove_organization_property() { // std::cout << "test_remove_organization_property IN" << std::endl; OrganizationProperty set_prop; CORBA::Boolean ret; CORBA::Float ft; NVList nvList; NameValue nv; string str; nv.name = "hoge"; str = "hoge"; ft = 11.111; nv.value <<= ft; nvList.length(1); nvList[0] = nv; set_prop.properties = nvList; // プロパティのセット ret = m_pOi->add_organization_property(set_prop); CPPUNIT_ASSERT(ret); // InvalidParameter exceptionを確認 short sflg = -1; try { ret = m_pOi->remove_organization_property("short"); if (!ret) { cout << "Couldn't remove name: short" << endl; } sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // 戻り値:true を確認 sflg = -1; try { ret = m_pOi->remove_organization_property("hoge"); if (!ret) { cout << "Couldn't remove name: hoge" << endl; } CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // std::cout << "test_remove_organization_property OUT" << std::endl; }
/*! * @brief set_organization_property() and get_organization_property() */ void test_set_get_organization_property() { // std::cout << "test_set_get_organization_property IN" << std::endl; OrganizationProperty_var get_prop; OrganizationProperty set_prop; CORBA::Boolean ret; CORBA::Short st; CORBA::Long lg; CORBA::Float ft; CORBA::Double db; // char* strg; CORBA::Short rst; CORBA::Long rlg; CORBA::Float rft; CORBA::Double rdb; // char* rstrg; NVList nvList; NameValue nv; string str; try { // プロパティの取得 length 0のプロパティが返される。 get_prop = m_pOi->get_organization_property(); // cout << endl << "get property length: " << get_prop->properties.length() << endl; // 空のOrganizationPropertyをセットする。 OK. ret = m_pOi->add_organization_property(set_prop); nv.name = "hoge"; str = "hoge"; ft = 11.111; nv.value <<= ft; nvList.length(1); nvList[0] = nv; set_prop.properties = nvList; // プロパティのセット ret = m_pOi->add_organization_property(set_prop); // プロパティの取得 length 1のプロパティリストを持つOrganizationPropertyが返される。 get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = (get_prop->properties[0]).name; (get_prop->properties[0]).value >>= rft; CPPUNIT_ASSERT(str == "hoge"); CPPUNIT_ASSERT(rft == ft); nv.name = "hogehoge"; ft = 22.2; nv.value <<= ft; nvList.length(1); nvList[0] = nv; set_prop.properties = nvList; // プロパティのセット ret = m_pOi->add_organization_property(set_prop); // プロパティの取得 get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = ((get_prop->properties[0]).name); (get_prop->properties[0]).value >>= rft; CPPUNIT_ASSERT(str == "hogehoge"); CPPUNIT_ASSERT(rft == ft); // nvList.length(5); nvList.length(4); // cout << "short" << endl; nv.name = "short"; st = 1; nv.value <<= st; nvList[0] = nv; // cout << "long" << endl; nv.name = "long"; lg = 2222; nv.value <<= lg; nvList[1] = nv; // cout << "float" << endl; nv.name = "float"; ft = 33.3; nv.value <<= ft; nvList[2] = nv; // cout << "double" << endl; nv.name = "double"; db = 3.3; nv.value <<= db; nvList[3] = nv; // nv.name = "char"; // strg = "STRING"; // nv.value <<= CORBA::Any::from_char('C'); // ここでセグメントエラー発生 // cout << "char" << endl; // nvList[4] = nv; // cout << "string" << endl; // nv.name = "string"; // strg = "STRING"; // char * p = "STRING"; // nv.value <<= CORBA::Any::from_string(p,7); // ここでセグメントエラー発生 // nvList[4] = nv; // cout << "set_prop.properties" << endl; set_prop.properties = nvList; // cout << "set in" << endl; ret = m_pOi->add_organization_property(set_prop); // cout << "set out" << endl; get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = ((get_prop->properties[0]).name); (get_prop->properties[0]).value >>= rst; CPPUNIT_ASSERT(str == "short"); CPPUNIT_ASSERT(rst == st); str = ((get_prop->properties[1]).name); (get_prop->properties[1]).value >>= rlg; CPPUNIT_ASSERT(str == "long"); CPPUNIT_ASSERT(rlg == lg); str = ((get_prop->properties[2]).name); (get_prop->properties[2]).value >>= rft; CPPUNIT_ASSERT(str == "float"); CPPUNIT_ASSERT(rft == ft); str = ((get_prop->properties[3]).name); (get_prop->properties[3]).value >>= rdb; CPPUNIT_ASSERT(str == "double"); CPPUNIT_ASSERT(rdb == db); // str = ((get_prop->properties[4]).name); // (get_prop->properties[4]).value >>= (CORBA::Any::to_char(rch)); // CPPUNIT_ASSERT(str == "char"); // CPPUNIT_ASSERT(rch == ch); // str = ((get_prop->properties[4]).name); // char * retp; // (get_prop->properties[4]).value >>= CORBA::Any::to_string(retp,7); // CPPUNIT_ASSERT(str == "string"); // CPPUNIT_ASSERT(*retp == *p); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_organization_property OUT" << std::endl; }