bool Manager::exist(unsigned int id) { if(id>=resources.size()) { logger->addError("Resource id is out of range."); return false; } GenericResource* res = resources[id]; if(compareString(res->getName(), "localhost")) return true; if(dynamic_cast<Computer*>(res) || dynamic_cast<ResYarpPort*>(res)) { if(res->getName()) { //YarpBroker broker; //broker.init(); string strPort = res->getName(); if(strPort[0] != '/') strPort = string("/") + strPort; res->setAvailability(connector.exists(strPort.c_str())); } } return res->getAvailability(); }
bool Computer::addPeripheral(GenericResource& res) { GenericResource* newres = (GenericResource*) res.clone(); peripheralResources.push_back(newres); return true; }
bool MultiResource::addResource(GenericResource& res) { GenericResource* newres = (GenericResource*) res.clone(); resources.push_back(newres); return true; }
bool yarp::manager::exportDotGraph(Graph& graph, const char* szFileName) { ofstream dot; dot.open(szFileName); if(!dot.is_open()) return false; dot<<"digraph G {"<<endl; dot<<"rankdir=LR;"<<endl; dot<<"ranksep=0.0;"<<endl; dot<<"nodesep=0.2;"<<endl; for(GraphIterator itr=graph.begin(); itr!=graph.end(); itr++) { switch((*itr)->getType()) { case MODULE: { Module* mod = (Module*)(*itr); dot<<"\""<<mod->getLabel()<<"\""; dot<<" [label=\""<< mod->getName()<<"\""; dot<<" shape=component, color=midnightblue, fillcolor=lightslategrey, peripheries=1, style=filled, penwidth=2];"<<endl; for(int i=0; i<mod->sucCount(); i++) { Link l = mod->getLinkAt(i); InputData* in = (InputData*)l.to(); dot<<"\""<<mod->getLabel()<<"\" -> "; dot<<"\""<<in->getLabel()<<"\""; if(!l.isVirtual()) dot<<" [label=\"\"];"<<endl; else dot<<" [label=\"\" style=dashed];"<<endl; } break; } case INPUTD: { InputData* in = (InputData*)(*itr); dot<<"\""<<in->getLabel()<<"\""; if(in->withPriority()) { dot<<" [color=red, fillcolor=lightgrey, peripheries=1, style=filled"; dot<<" label=\""<< in->getName()<<"\\n"<<in->getPort()<<"\"];"<<endl; } else { dot<<" [color=black, fillcolor=lightgrey, peripheries=1, style=filled"; dot<<" label=\""<< in->getName()<<"\\n"<<in->getPort()<<"\"];"<<endl; } for(int i=0; i<in->sucCount(); i++) { Link l = in->getLinkAt(i); OutputData* out = (OutputData*)l.to(); dot<<"\""<<in->getLabel()<<"\" -> "; dot<<"\""<<out->getLabel()<<"\""; if(!l.isVirtual()) dot<<" [label=\""<<l.weight()<<"\"];"<<endl; else dot<<" [label=\""<<l.weight()<<"\" style=dashed];"<<endl; } break; } case OUTPUTD: { OutputData* out = (OutputData*)(*itr); dot<<"\""<<out->getLabel()<<"\""; dot<<" [color=black, fillcolor=wheat, peripheries=1, style=filled"; dot<<" label=\""<< out->getName()<<"\\n"<<out->getPort()<<"\"];"<<endl; for(int i=0; i<out->sucCount(); i++) { Link l = out->getLinkAt(i); Module* mod = (Module*)l.to(); dot<<"\""<<out->getLabel()<<"\" -> "; dot<<"\""<<mod->getLabel()<<"\""; dot<<" [label=\"\" arrowhead=none];"<<endl; } break; } case APPLICATION: { Application* app = (Application*)(*itr); dot<<"\""<<app->getLabel()<<"\""; dot<<" [shape=folder, color=darkgreen, fillcolor=darkseagreen, peripheries=1, style=filled, penwidth=2"; dot<<" label=\""<<app->getLabel()<<"\""<<"];"<<endl; for(int i=0; i<app->sucCount(); i++) { Link l = app->getLinkAt(i); Module* mod = (Module*)l.to(); dot<<"\""<<app->getLabel()<<"\" -> "; dot<<"\""<<mod->getLabel()<<"\""; if(!l.isVirtual()) dot<<" [label=\"\"];"<<endl; else dot<<" [label=\"\" style=dashed];"<<endl; } break; } case RESOURCE: { GenericResource* res = (GenericResource*)(*itr); dot<<"\""<<res->getLabel()<<"\""; if(res->owner()) dot<<" [shape=rect, color=black, fillcolor=salmon, peripheries=1, style=filled "; else dot<<" [shape=house, color=maroon, fillcolor=indianred, peripheries=1, style=filled, penwidth=2"; dot<<" label=\""<<res->getName()<<"\""<<"];"<<endl; for(int i=0; i<res->sucCount(); i++) { Link l = res->getLinkAt(i); Node* prov = l.to(); dot<<"\""<<res->getLabel()<<"\" -> "; dot<<"\""<<prov->getLabel()<<"\""; dot<<" [label=\""<<l.weight()<<"\"];"<<endl; } break; } default: break; }; } dot<<GRAPH_LEGEND; dot<<"}"<<endl; dot.close(); return true; }