15#include <yarp/companion/impl/Companion.h>
31 std::string ip =
it->owner_process.owner_machine.ip;
32 if (std::find(
l.begin(),
l.end(), ip) ==
l.end())
47 std::string pid =
it->owner_process.process_fullname;
48 if (std::find(
l.begin(),
l.end(), pid) ==
l.end())
69 if (!r) {
yError() <<
"getPortDetails of `" <<
it->name <<
"`failed"; }
79 for (
auto it = in.begin();
it != in.end();
it++)
82 if (
it->owner_process.owner_machine.hostname == ip) {
filtered_out.push_back(*
it); }
91 for (
auto it = in.begin();
it != in.end();
it++)
93 if (process_fullname !=
"*") {
94 if (
it->owner_process.process_fullname == process_fullname) {
filtered_out.push_back(*
it); }
103 for (
auto it = in.begin();
it != in.end();
it++)
121 for (
auto it = in.begin();
it != in.end();
it++)
139 for (
auto it = in.begin();
it != in.end();
it++)
159 if (name ==
it->name)
204 conn.src.port_number=
it->port_number;
205 conn.dst.name =
it2->port_name;
212 if (
conn.isValid() &&
213 std::find(connections.begin(), connections.end(),
conn) == connections.end())
215 connections.push_back(
conn);
231 msg.addString(
"bot");
232 msg.addString(
"list");
234 yError() <<
"Cannot write to yarp name server";
238 if(reply.
size() == 0) {
239 yError() <<
"Empty reply from yarp name server";
243 for (
size_t i=1; i<reply.
size(); i++) {
245 if(
entry !=
nullptr) {
247 std::string portname =
entry->check(
"name",
Value(
"")).asString();
258 if (
c.getCarrier() !=
"mcast")
263 portd.port_number = std::to_string(
entry->find(
"port_number").asInt32());
280 ping.setAdminMode(
true);
281 ping.setTimeout(timeout);
283 yWarning()<<
"Cannot connect to"<<portName;
293 yError()<<
"Cannot get the output connections of"<<portName;
299 cnn.port_name = name;
302 yWarning()<<
"Cannot get the details of the connection from"<<portName<<
"to"<<name;
312 yError()<<
"Cannot get the input connections of"<<portName;
319 cnn.port_name = name;
327 yError()<<
"Cannot get the info of"<<portName;
332 details.owner_process.process_name =
info.process.name;
333 details.owner_process.arguments =
info.process.arguments;
335 details.owner_process.priority =
info.process.schedPriority;
336 details.owner_process.policy =
info.process.schedPolicy;
337 details.owner_process.process_fullname =
details.owner_process.process_name +
"(" + std::to_string(
details.owner_process.pid) +
")";
339 details.owner_process.owner_machine.os =
info.platform.name;
341 details.owner_process.owner_machine.hostname =
info.port.hostname;
342 details.owner_process.owner_machine.ip =
info.port.hostname;
355 std::ostringstream str;
356 str <<
"port name: " <<
info.
name << std::endl;
357 str <<
"port ip: " <<
info.
ip << std::endl;
359 str <<
"outputs:" << std::endl;
360 std::vector<ConnectedPortInfo>::const_iterator itr;
362 str <<
" + " << (*itr).port_name <<
" (" << (*itr).carrier <<
")" << std::endl;
364 str <<
"inputs:" << std::endl;
365 for (itr =
inputs.begin(); itr !=
inputs.end(); itr++) {
366 str <<
" + " << (*itr).port_name <<
" (" << (*itr).carrier <<
")" << std::endl;
368 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.
A mini-server for performing network communication in the background.
std::string getName() const override
Get name of port.
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.
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 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.
static bool cleanUnresponsivePorts(double timeout=-1)
Clean up unresponsive ports from the name server.
virtual return_getPortInfo getPortInfo()
Give information about this port, its main thread, and the process and the platform on which it is ru...
virtual return_getConnectionInfo getConnectionInfoOut(const std::string &portname)
Give details about the output connection going from this port to another port.
virtual return_listConnections listConnectionsOut()
List the ports connected to the output of this port.
virtual return_listConnections listConnectionsIn()
List the ports connected to the input of this port.
A mini-server for network communication.
A single value (typically within a Bottle).
virtual Bottle * asList() const
Get list value.
Client side of the administrative commands defined in PortCoreMsgs.thrift and handled by PortCore::ad...
Reply of PortCoreMsgs::getConnectionInfoIn() and PortCoreMsgs::getConnectionInfoOut().
Reply of PortCoreMsgs::getPortInfo().
Reply of PortCoreMsgs::listConnectionsIn() and PortCoreMsgs::listConnectionsOut().
std::vector< std::string > connections
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 getPortsDetailedList(ports_detail_set &ports, bool complete=false, double timeout=2.0)
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, double timeout=2.0)
Get the details (connections, owner process and machine) of a port.
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 bool getMachinesList(const ports_detail_set &ports, machines_list &l)
static void filterPortsListByIp(const ports_detail_set &in, ports_detail_set &filtered_out, std::string ip="*")
std::vector< PortInfo > ports_name_set
static bool getPortInfo(const std::string &name, const ports_name_set &ports, PortInfo &p)
std::vector< std::string > machines_list
An interface to the operating system, including Port based communication.
std::vector< ConnectedPortInfo > outputs
std::vector< ConnectedPortInfo > inputs
ProcessInfo owner_process
std::string toString() const
MachineInfo owner_machine