14 #include <yarp/companion/impl/Companion.h>
35 yError() <<
"Cannot write to yarp name server";
39 if(reply.
size() == 0) {
40 yError() <<
"Empty reply from yarp name server";
44 for (
size_t i=1; i<reply.
size(); i++) {
46 if(entry !=
nullptr) {
47 bool shouldTake =
false;
48 std::string portname = entry->
check(
"name",
Value(
"")).asString();
51 shouldTake = portname !=
"";
55 shouldTake = portname !=
"" && portname !=
"fallback" && portname != nameserver;
60 ports.push_back(*entry);
69 bool NetworkProfiler::getPortDetails(
const std::string& portName,
PortDetails& info) {
73 ping.
open(
"/yarpviz");
77 yWarning()<<
"Cannot connect to"<<portName;
85 if(!ping.
write(cmd, reply)) {
86 yError()<<
"Cannot write (list out) to"<<portName;
90 for(
size_t i=0; i<reply.
size(); i++) {
96 if (!ping.
write(cmd, reply2)) {
97 yWarning()<<
"Cannot write (list out"<<cnn.
name<<
") to"<<portName;
107 if(!ping.
write(cmd, reply)) {
108 yError()<<
"Cannot write (list in) to"<<portName;
112 for(
size_t i=0; i<reply.
size(); i++) {
116 info.
inputs.push_back(cnn);
123 if(!ping.
write(cmd, reply)) {
124 yError()<<
"Cannot write (prop get"<<portName<<
") to"<<portName;
131 yWarning()<<
"Cannot find 'process' property of port "<<portName;
142 yWarning()<<
"Cannot find 'platform' property of port "<<portName;
156 if (NetworkProfiler::progCallback) {
161 unsigned int itr_count = 0;
162 for(itr = details.begin(); itr!=details.end(); itr++) {
182 auto itrVert=graph.
insert(*process);
200 if(NetworkProfiler::progCallback) {
201 NetworkProfiler::progCallback->
onProgress((
unsigned int) (++itr_count/((
float)(details.size()*2)) * 100.0) );
207 for(itr = details.begin(); itr!=details.end(); itr++) {
216 Property edge_prop(
"(type connection)");
217 edge_prop.
put(
"carrier", cnn.carrier);
220 yWarning() <<
"Found a nonexistent port (" << cnn.name <<
")"
221 <<
"in the output list of" << (*vi1)->property.find(
"name").asString();
225 if(NetworkProfiler::progCallback) {
226 NetworkProfiler::progCallback->
onProgress((
unsigned int) (++itr_count/((
float)(details.size()*2)) * 100.0) );
229 if (NetworkProfiler::progCallback) {
230 NetworkProfiler::progCallback->
onProgress(100);
235 bool NetworkProfiler::yarpClean(
float timeout) {
241 std::stringstream sstream;
244 argv[0] = (
char*)
"--timeout";
245 argv[1] = (
char*) sstream.str().c_str();
246 yarp::companion::impl::Companion::getInstance().cmdClean(2,argv);
255 for(itr = vertices.begin(); itr!=vertices.end(); itr++) {
264 mv1->property.find(
"hostname").asString());
271 for(itr = vertices.begin(); itr!=vertices.end(); itr++) {
279 pv1->property.find(
"hostname").asString());
285 for(itr = vertices.begin(); itr!=vertices.end(); itr++) {
292 for(eitr = outs.begin(); eitr!=outs.end(); eitr++) {
293 const Edge& e = (*eitr);
298 for(peitr = pouts.begin(); peitr!=pouts.end(); peitr++) {
299 const Vertex& p2 = (*peitr).second();
303 prop.
put(
"label", label);
342 if (level ==
"NORMAL") {
345 if (level ==
"LOW") {
348 if (level ==
"HIGH") {
351 if (level ==
"CRITIC") {
354 if (level ==
"INVALID") {
365 for(itr = vertices.begin(); itr!=vertices.end(); itr++) {
366 const Vertex &v1 = (**itr);
367 for(
const auto& i : v1.
outEdges()) {
406 yError()<<
"Cannot write to"<<portName;
418 bool NetworkProfiler::detachPortmonitorPlugin(std::string portName) {
426 yError()<<
"Cannot write to"<<portName;
448 yError()<<
"Cannot write to"<<portName;
451 if(reply.
size() > 1) {
464 bool NetworkProfiler::getPortmonitorParams(std::string portName,
yarp::os::Bottle& param) {
473 yError()<<
"Cannot write to"<<portName;
476 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 std::string getNameServerName()
Get the name of the port associated with the nameserver (usually "/root", but this can be overwritten...
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
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.
std::vector< ConnectionInfo > inputs
std::vector< ConnectionInfo > outputs