17 #include <yarp/companion/impl/Companion.h>
34 string nameserver = NetworkBase::getNameServerName();
39 yError() <<
"Cannot write to yarp name server";
43 if(reply.
size() == 0) {
44 yError() <<
"Empty reply from yarp name server";
48 for (
size_t i=1; i<reply.
size(); i++) {
50 if(entry !=
nullptr) {
51 bool shouldTake =
false;
52 std::string portname = entry->
check(
"name",
Value(
"")).asString();
55 shouldTake = portname !=
"";
59 shouldTake = portname !=
"" && portname !=
"fallback" && portname != nameserver;
62 Contact c = Contact::fromConfig(*entry);
64 ports.push_back(*entry);
72 bool NetworkProfiler::getPortDetails(
const string& portName,
PortDetails& info) {
76 ping.
open(
"/yarpviz");
79 if(!NetworkBase::connect(ping.
getName(), portName)) {
80 yWarning()<<
"Cannot connect to"<<portName;
88 if(!ping.
write(cmd, reply)) {
89 yError()<<
"Cannot write (list out) to"<<portName;
93 for(
size_t i=0; i<reply.
size(); i++) {
99 if(!ping.
write(cmd, reply2))
100 yWarning()<<
"Cannot write (list out"<<cnn.
name<<
") to"<<portName;
109 if(!ping.
write(cmd, reply)) {
110 yError()<<
"Cannot write (list in) to"<<portName;
114 for(
size_t i=0; i<reply.
size(); i++) {
118 info.
inputs.push_back(cnn);
124 if(!ping.
write(cmd, reply)) {
125 yError()<<
"Cannot write (prop get"<<portName<<
") to"<<portName;
132 yWarning()<<
"Cannot find 'process' property of port "<<portName;
143 yWarning()<<
"Cannot find 'platform' property of port "<<portName;
157 if(NetworkProfiler::progCallback)
161 unsigned int itr_count = 0;
162 for(itr = details.begin(); itr!=details.end(); itr++) {
181 auto itrVert=graph.
insert(*process);
198 if(NetworkProfiler::progCallback) {
199 NetworkProfiler::progCallback->
onProgress((
unsigned int) (++itr_count/((
float)(details.size()*2)) * 100.0) );
205 for(itr = details.begin(); itr!=details.end(); itr++) {
214 Property edge_prop(
"(type connection)");
215 edge_prop.
put(
"carrier", cnn.carrier);
219 yWarning()<<
"Found a nonexistent port ("<<cnn.name<<
")"<<
"in the output list of"<<(*vi1)->property.find(
"name").asString();
222 if(NetworkProfiler::progCallback) {
223 NetworkProfiler::progCallback->
onProgress((
unsigned int) (++itr_count/((
float)(details.size()*2)) * 100.0) );
226 if(NetworkProfiler::progCallback)
227 NetworkProfiler::progCallback->
onProgress(100);
231 bool NetworkProfiler::yarpClean(
float timeout) {
236 stringstream sstream;
239 argv[0] = (
char*)
"--timeout";
240 argv[1] = (
char*) sstream.str().c_str();
241 yarp::companion::impl::Companion::getInstance().cmdClean(2,argv);
250 for(itr = vertices.begin(); itr!=vertices.end(); itr++) {
260 mv1->property.find(
"hostname").asString());
267 for(itr = vertices.begin(); itr!=vertices.end(); itr++) {
274 pv1->property.find(
"hostname").asString());
280 for(itr = vertices.begin(); itr!=vertices.end(); itr++) {
286 for(eitr = outs.begin(); eitr!=outs.end(); eitr++) {
287 const Edge& e = (*eitr);
292 for(peitr = pouts.begin(); peitr!=pouts.end(); peitr++) {
293 const Vertex& p2 = (*peitr).second();
297 prop.
put(
"label", label);
349 for(itr = vertices.begin(); itr!=vertices.end(); itr++) {
350 const Vertex &v1 = (**itr);
351 for(
const auto& i : v1.
outEdges()) {
387 Contact srcCon = Contact::fromString(portName);
390 yError()<<
"Cannot write to"<<portName;
402 bool NetworkProfiler::detachPortmonitorPlugin(std::string portName) {
407 Contact srcCon = Contact::fromString(portName);
410 yError()<<
"Cannot write to"<<portName;
429 Contact srcCon = Contact::fromString(portName);
432 yError()<<
"Cannot write to"<<portName;
435 if(reply.
size() > 1) {
448 bool NetworkProfiler::getPortmonitorParams(std::string portName,
yarp::os::Bottle& param) {
454 Contact srcCon = Contact::fromString(portName);
457 yError()<<
"Cannot write to"<<portName;
460 if(param.
size() > 1) {
edge_set::const_iterator edge_const_iterator
pvertex_set::const_iterator pvertex_const_iterator
std::vector< yarp::profiler::graph::Vertex * > pvertex_set
pvertex_set::iterator pvertex_iterator
std::vector< yarp::profiler::graph::Edge > edge_set
A simple collection of objects that can be described and transmitted in a portable way.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
void fromString(const std::string &text)
Initializes bottle from a string.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void clear()
Empties the bottle of any objects it contains.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
static bool getConnectionQos(const std::string &src, const std::string &dest, QosStyle &srcStyle, QosStyle &destStyle, bool quiet=true)
Gets the Qos preferences of a connection.
static bool write(const Contact &contact, PortWriter &cmd, PortReader &reply, bool admin=false, bool quiet=false, double timeout=-1)
Send a single command to a port and await a single response.
A mini-server for network communication.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
void setAdminMode(bool adminMode=true)
Turn on/off "admin" mode.
bool setTimeout(float timeout)
Set a timeout on network operations.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
std::string toString() const override
Return a standard text representation of the content of the object.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Preferences for the port's Quality of Service.
int getThreadPolicy() const
returns the communication thread scheduling policy
int getThreadPriority() const
returns the communication thread priority level
PacketPriorityLevel
The PacketPriorityLevel defines the packets quality of service (priority) levels.
PacketPriorityLevel getPacketPriorityAsLevel() const
returns the packet TOS value
A single value (typically within a Bottle).
virtual bool isString() const
Checks if value is a string.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual Bottle * asList() const
Get list value.
virtual Property * asDict() const
Get dictionary (hash table) value.
virtual bool isInt32() const
Checks if value is a 32-bit integer.
virtual std::string asString() const
Get string value.
virtual void onProgress(unsigned int percentage)
std::vector< yarp::os::Bottle > ports_name_set
ports_detail_set::iterator ports_detail_iterator
std::vector< PortDetails > ports_detail_set
The yarp::profiler::graph::Edge class.
const yarp::profiler::graph::Vertex & second() const
yarp::os::Property property
The yarp::profiler::graph::Graph class.
void insertEdge(const Vertex &v1, const Vertex &v2, const yarp::os::Property &property="")
const pvertex_set & vertices()
const pvertex_iterator find(const Vertex &v1)
pvertex_iterator insert(const Vertex &vertex)
bool setOwner(yarp::profiler::graph::Vertex *_owner)
The yarp::profiler::graph::Vertex class.
yarp::os::Property property
const edge_set & outEdges() const
An interface to the operating system, including Port based communication.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
std::vector< ConnectionInfo > inputs
std::vector< ConnectionInfo > outputs