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 Manager::loadApplication(const char* szAppName) { __CHECK_NULLPTR(szAppName); if(!allStopped()) { logger->addError("Please stop current running application first."); return false; } strAppName = szAppName; // set all resources as unavailable ResourcePContainer allresources = knowledge.getResources(); for(unsigned int i=0; i<allresources.size(); i++) { Computer* comp = dynamic_cast<Computer*>(allresources[i]); if(comp) comp->setAvailability(false); } return prepare(true); }