bool Manager::updateResources(void) { YarpBroker broker; broker.init(); // finding all available yarp ports vector<string> ports; broker.getAllPorts(ports); ResourcePContainer allresources = knowledge.getResources(); for(unsigned int i=0; i<allresources.size(); i++) { Computer* comp = dynamic_cast<Computer*>(allresources[i]); if(updateResource(comp)) { //set all as unavailable for(int i=0; i<comp->peripheralCount(); i++) { ResYarpPort* res = dynamic_cast<ResYarpPort*>(&comp->getPeripheralAt(i)); if(res) res->setAvailability(false); } // adding all available yarp ports as peripherals for(unsigned int i=0; i<ports.size(); i++) { ResYarpPort resport; resport.setName(ports[i].c_str()); resport.setPort(ports[i].c_str()); bool bfound = false; for(int i=0; i<comp->peripheralCount(); i++) { ResYarpPort* res = dynamic_cast<ResYarpPort*>(&comp->getPeripheralAt(i)); if(res && (string(res->getName()) == string(resport.getName()))) { res->setAvailability(true); bfound = true; break; } } if(!bfound) comp->addPeripheral(resport); } } } // end of for return true; }
bool ResYarpPort::satisfy(GenericResource* resource) { if(!getAvailability() || getDisable()) return false; ResYarpPort* resport = dynamic_cast<ResYarpPort*>(resource); if(!resport) return false; return (strPort == string(resport->getPort()) || strPort == string(resport->getName()) ); }