14#include <yarp/companion/impl/Companion.h>
23 for (
auto it = ports.begin(); it != ports.end(); it++)
25 std::string ip = it->owner_process.owner_machine.ip;
26 if (std::find(l.begin(), l.end(), ip) == l.end())
37 for (
auto it = ports.begin(); it != ports.end(); it++)
40 std::string pid = it->owner_process.process_fullname;
41 if (std::find(l.begin(), l.end(), pid) == l.end())
56 for (
auto it = port_names.begin(); it != port_names.end(); it++)
60 if (!r) {
yError() <<
"getPortDetails of `" << it->name <<
"`failed"; }
61 ports.push_back(details);
69 for (
auto it = in.begin(); it != in.end(); it++)
72 if (it->owner_process.owner_machine.hostname == ip) { filtered_out.push_back(*it); }
80 for (
auto it = in.begin(); it != in.end(); it++)
82 if (process_fullname !=
"*") {
83 if (it->owner_process.process_fullname == process_fullname) { filtered_out.push_back(*it); }
91 for (
auto it = in.begin(); it != in.end(); it++)
93 if (src_name!=
"*" && dst_name !=
"*") {
94 if (it->src.name == src_name && it->src.name == dst_name) { filtered_out.push_back(*it);}
96 else if (src_name ==
"*") {
97 if (it->dst.name == dst_name) { filtered_out.push_back(*it); }
99 else if (dst_name ==
"*") {
100 if (it->src.name == src_name) {filtered_out.push_back(*it); }
107 filtered_out.clear();
108 for (
auto it = in.begin(); it != in.end(); it++)
110 if (src_portnumber !=
"*" && dst_portnumber !=
"*") {
111 if (it->src.ip == src_portnumber && it->src.ip == dst_portnumber) { filtered_out.push_back(*it); }
113 else if (src_portnumber ==
"*") {
114 if (it->dst.ip == dst_portnumber) { filtered_out.push_back(*it); }
116 else if (dst_portnumber ==
"*") {
117 if (it->src.ip == src_portnumber) { filtered_out.push_back(*it); }
124 filtered_out.clear();
125 for (
auto it = in.begin(); it != in.end(); it++)
127 if (src_ip !=
"*" && dst_ip !=
"*") {
128 if (it->src.port_number == src_ip && it->src.port_number == dst_ip) { filtered_out.push_back(*it); }
130 else if (src_ip ==
"*") {
131 if (it->dst.port_number == dst_ip) { filtered_out.push_back(*it); }
133 else if (dst_ip ==
"*") {
134 if (it->src.port_number == src_ip) { filtered_out.push_back(*it); }
141 for (
auto it = ports.begin(); it != ports.end(); it++)
143 if (name == it->name)
161 for (
auto it = ports.begin(); it != ports.end(); it++)
181 for (
auto it2 = info.
outputs.begin(); it2 != info.
outputs.end(); it2++)
185 conn.
src.
ip = it->ip;
187 conn.
dst.
name = it2->port_name;
195 std::find(connections.begin(), connections.end(), conn) == connections.end())
197 connections.push_back(conn);
210 std::string nameserver = NetworkBase::getNameServerName();
215 yError() <<
"Cannot write to yarp name server";
219 if(reply.
size() == 0) {
220 yError() <<
"Empty reply from yarp name server";
224 for (
size_t i=1; i<reply.
size(); i++) {
226 if(entry !=
nullptr) {
227 bool shouldTake =
false;
228 std::string portname = entry->
check(
"name",
Value(
"")).asString();
231 shouldTake = portname !=
"";
235 shouldTake = portname !=
"" && portname !=
"fallback" && portname != nameserver;
238 Contact c = Contact::fromConfig(*entry);
245 ports.push_back(portd);
261 if(!NetworkBase::connect(ping.
getName(), portName)) {
262 yWarning()<<
"Cannot connect to"<<portName;
270 if(!ping.
write(cmd, reply)) {
271 yError()<<
"Cannot write (list out) to"<<portName;
275 for(
size_t i=0; i<reply.
size(); i++) {
281 if (!ping.
write(cmd, reply2)) {
286 details.
outputs.push_back(cnn);
292 if(!ping.
write(cmd, reply)) {
293 yError()<<
"Cannot write (list in) to"<<portName;
297 for(
size_t i=0; i<reply.
size(); i++) {
301 details.
inputs.push_back(cnn);
308 if(!ping.
write(cmd, reply)) {
309 yError()<<
"Cannot write (prop get"<<portName<<
") to"<<portName;
316 yWarning()<<
"Cannot find 'process' property of port "<<portName;
318 std::string process_str = process->
toString();
329 yWarning()<<
"Cannot find 'platform' property of port "<<portName;
331 std::string platform_str = platform->
toString();
347 std::stringstream sstream;
350 argv[0] = (
char*)
"--timeout";
351 argv[1] = (
char*) sstream.str().c_str();
352 yarp::companion::impl::Companion::getInstance().cmdClean(2,argv);
358 std::ostringstream str;
359 str <<
"port name: " <<
info.
name << std::endl;
360 str <<
"port ip: " <<
info.
ip << std::endl;
362 str <<
"outputs:" << std::endl;
363 std::vector<ConnectedPortInfo>::const_iterator itr;
365 str <<
" + " << (*itr).port_name <<
" (" << (*itr).carrier <<
")" << std::endl;
367 str <<
"inputs:" << std::endl;
368 for (itr =
inputs.begin(); itr !=
inputs.end(); itr++) {
369 str <<
" + " << (*itr).port_name <<
" (" << (*itr).carrier <<
")" << std::endl;
371 str <<
"owner:" << std::endl;
A simple collection of objects that can be described and transmitted in a portable way.
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.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
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.
A single value (typically within a Bottle).
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 std::string asString() const
Get string value.
std::vector< ConnectionDetails > connections_set
static bool getProcessesList(const ports_detail_set &ports, processes_list &l)
static void filterConnectionListByName(const connections_set &in, connections_set &filtered_out, std::string src_name="*", std::string dst_name="*")
static bool getPortsList(ports_name_set &ports, bool complete=false)
static void filterConnectionListByPortNumber(const connections_set &in, connections_set &filtered_out, std::string src_name="*", std::string dst_name="*")
static void filterPortsListByProcess(const ports_detail_set &in, ports_detail_set &filtered_out, std::string fullprocess="*")
std::vector< PortDetails > ports_detail_set
std::vector< std::string > processes_list
static bool getPortDetails(const std::string &portName, PortDetails &info)
static bool yarpClean(float timeout=0.1)
static void filterConnectionListByIp(const connections_set &in, connections_set &filtered_out, std::string src_name="*", std::string dst_name="*")
static bool getConnectionsList(connections_set &connections)
static void filterPortsListByIp(const ports_detail_set &in, ports_detail_set &filtered_out, std::string ip="*")
std::vector< PortInfo > ports_name_set
static bool getPortsDetailedList(ports_detail_set &ports, bool complete=false)
static bool getPortInfo(const std::string &name, const ports_name_set &ports, PortInfo &p)
std::vector< std::string > machines_list
std::string to_string(IntegerType x)
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< ConnectedPortInfo > outputs
std::vector< ConnectedPortInfo > inputs
ProcessInfo owner_process
std::string toString() const
MachineInfo owner_machine
std::string process_fullname