35 this->contact = contact;
50 yCDebug(ROSNAMESPACE,
"ROSNameSpace queryName(%s)", name.c_str());
55 bool is_service =
false;
59 if (
cat.find(
"-1") == std::string::npos) {
82 contact.
setCarrier(std::string(
"rossrv+service.") + name);
88 if (srv.empty() || !is_service) {
98 yCError(ROSNAMESPACE,
"ROS name server does not do 'raw' registrations.");
99 yCError(ROSNAMESPACE,
"Use [Buffered]Port::open to get complete registrations.");
112 yCDebug(ROSNAMESPACE,
"ROSNameSpace registerContact(%s / %s)",
114 contact.
toURI().c_str());
132 if (store !=
nullptr) {
135 Nodes& nodes = NameClient::getNameClient().getNodes();
145 }
else if (
cat ==
"+" ||
cat ==
"-") {
149 cmd.
addString((
cat ==
"+") ?
"registerPublisher" :
"registerSubscriber");
153 if (typ !=
"*" && !typ.empty()) {
155 if (typ ==
"yarp/image") {
156 typ =
"sensor_msgs/Image";
158 if (typ.find(
'/') == std::string::npos) {
159 typ = std::string(
"yarp/") + typ;
164 if (store !=
nullptr) {
167 Nodes& nodes = NameClient::getNameClient().getNodes();
176 yCError(ROSNAMESPACE,
"ROS registration error: %s", reply.
toString().c_str());
181 if ((publishers !=
nullptr) && publishers->
size() >= 1) {
190 bool need_start =
false;
191 if (pending.
size() == 0) {
210 std::string name = contact.
getName();
211 size_t pub_idx = name.find(
"+#");
212 size_t sub_idx = name.find(
"-#");
217 if (pub_idx != std::string::npos) {
218 node = name.substr(0, pub_idx);
219 pub = name.substr(pub_idx + 2, name.length());
220 yCDebug(ROSNAMESPACE,
"Publish to %s", pub.c_str());
222 if (sub_idx != std::string::npos) {
223 node = name.substr(0, sub_idx);
224 sub = name.substr(sub_idx + 2, name.length());
225 yCDebug(ROSNAMESPACE,
"Subscribe to %s", sub.c_str());
230 yCDebug(ROSNAMESPACE,
"Name [%s] Node [%s] sub [%s] pub [%s]", name.c_str(), node.c_str(), sub.c_str(), pub.c_str());
278 Nodes& nodes = NameClient::getNameClient().getNodes();
295 }
else if (
cat ==
"+" ||
cat ==
"-") {
299 cmd.
addString((
cat ==
"+") ?
"unregisterPublisher" :
"unregisterSubscriber");
303 if (store !=
nullptr) {
306 Nodes& nodes = NameClient::getNameClient().getNodes();
322 size_t pub_idx = name.find(
"+#");
323 size_t sub_idx = name.find(
"-#");
328 if (pub_idx != std::string::npos) {
329 node = name.substr(0, pub_idx);
330 pub = name.substr(pub_idx + 2, name.length());
332 if (sub_idx != std::string::npos) {
333 node = name.substr(0, sub_idx);
334 sub = name.substr(sub_idx + 2, name.length());
339 yCDebug(ROSNAMESPACE,
"Name [%s] sub [%s] pub [%s]", name.c_str(), sub.c_str(), pub.c_str());
387 const std::string& key,
397 const std::string& key)
415 return connectTopic(cmd,
false, src, dest, style,
false);
441 return connectTopic(cmd,
false, src, dest, style,
false);
453 return connectTopic(cmd,
true, src, dest, style,
false);
481 bool activeRegistration)
497 bool fail = (reply.
check(
"faultCode",
Value(0)).asInt32() != 0) || !ok;
500 yCError(ROSNAMESPACE,
"Failure: name server did not accept connection to topic.");
501 if (reply.
check(
"faultString")) {
502 yCError(ROSNAMESPACE,
"Cause: %s", reply.
check(
"faultString",
Value(
"")).asString().c_str());
507 if (activeRegistration) {
510 if (lst !=
nullptr) {
558 yCInfo(ROSNAMESPACE,
"Checking for ROS_MASTER_URI...");
588 if (key ==
"query") {
605 yCError(ROSNAMESPACE,
"Failed to contact ROS server");
615 if (parts !=
nullptr) {
616 for (
int i = 0; i < 3; i++) {
618 if (part ==
nullptr) {
621 for (
size_t j = 0; j < part->
size(); j++) {
623 if (unit ==
nullptr) {
628 if (links ==
nullptr) {
634 services.
put(stem, 1);
636 for (
size_t j = 0; j < links->
size(); j++) {
641 Property* props[3] = {&nodes, &topics, &services};
642 const char* title[3] = {
"node",
"topic",
"service"};
643 for (
int p = 0; p < 3; p++) {
645 blist.
read(*props[p]);
646 for (
size_t i = 0; i < blist.
size(); i++) {
664 if (name.find(
':') == std::string::npos) {
668 for (
char i : name) {
680 if (name.find(
"__") == std::string::npos) {
686 for (
char i : name) {
719 std::string carrier = ((contact.
getCarrier() ==
"rosrpc") ?
"rosrpc" :
"http");
720 std::string hostname = contact.
getHost();
722 char hn[HOST_NAME_MAX];
735 pct = pending.
size();
743 yCDebug(ROSNAMESPACE,
"ROS connection begins: %s", curr.
toString().c_str());
752 yCDebug(ROSNAMESPACE,
"ROS connection ends: %s", curr.
toString().c_str());
755 pending = pending.
tail();
756 pct = pending.
size();
void cat(Vector &a, const Vector &b)
A simple collection of objects that can be described and transmitted in a portable way.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
size_type size() const
Gets the number of elements in the bottle.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
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.
Bottle tail() const
Get all but the first element of a bottle.
void clear()
Empties the bottle of any objects it contains.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
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.
A dummy connection to test yarp::os::Portable implementations.
ConnectionWriter & getWriter()
Get the dummy ConnectionWriter loaded with whatever was written the ConnectionWriter since it was las...
ConnectionReader & getReader()
Get the dummy ConnectionReader loaded with whatever was written the ConnectionWriter since it was las...
Abstract interface for a database of port names.
virtual Contact query(const std::string &name)=0
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 Contact queryName(const std::string &name)
Find out information about a registered name.
static bool disconnect(const std::string &src, const std::string &dest, bool quiet)
Request that an output port disconnect from 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.
Contact getURI(const std::string &name)
getURI queries the Node specified in the name parameter to get Contact information about the specifie...
Contact getParent(const std::string &name)
getParent get info about node associated with the specified port.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
virtual bool read(ConnectionReader &reader)=0
Read this object from a network connection.
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
virtual bool write(ConnectionWriter &writer) const =0
Write this object to a network connection.
A class for storing options and configuration information.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
bool usesCentralServer() const override
Check if a central server is involved in managing the NameSpace.
Contact getNameServerContact() const override
Get an address for a name server that manages the name space, if available.
RosNameSpace(const Contact &contact)
bool localOnly() const override
Check if the NameSpace is only valid for the current process ("local").
virtual bool writeToNameServer(PortWriter &cmd, PortReader &reply, const ContactStyle &style) override
Write a message to a name server for this NameSpace, if applicable.
Contact unregisterName(const std::string &name) override
Disassociate contact information from a port name.
Contact unregisterContact(const Contact &contact) override
Disassociate contact information (should include a port name).
virtual bool disconnectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style) override
Disconnect two ports, removing any persistence.
Contact queryName(const std::string &name) override
Map from port name to contact information.
virtual bool connectTopicToPort(const Contact &src, const Contact &dest, const ContactStyle &style) override
Subscribe a port to a topic.
Contact registerContact(const Contact &contact) override
Record contact information (should include a port name).
virtual bool connectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style) override
Connect two ports with persistence.
virtual bool disconnectTopicFromPort(const Contact &src, const Contact &dest, const ContactStyle &style) override
Stop subscribing a port to a topic.
bool serverAllocatesPortNumbers() const override
Check if a central server is responsible for allocating port numbers, or if this should be left up to...
static Contact rosify(const Contact &contact)
virtual Value * getProperty(const std::string &name, const std::string &key) override
Get the value of a named key from a named port.
virtual bool connectTopic(Bottle &cmd, bool srcIsTopic, const Contact &src, const Contact &dest, const ContactStyle &style, bool activeRegistration)
virtual Contact detectNameServer(bool useDetectedServer, bool &scanNeeded, bool &serverUsed) override
Find a name server for this NameSpace, if applicable.
Contact registerName(const std::string &name) override
Record contact information to tie to a port name.
static std::string fromRosName(const std::string &name)
static std::string toRosName(const std::string &name)
Possible ROS names are a subset of YARP names.
virtual bool setProperty(const std::string &name, const std::string &key, const Value &value) override
Associate a key/value pair with a named port.
static std::string fromRosNodeName(const std::string &name)
static std::string toRosNodeName(const std::string &name)
virtual Contact unregisterAdvanced(const std::string &name, NameStore *store) override
Remove contact information, with access to the contact information of other ports for cross-referenci...
bool connectionHasNameOfEndpoints() const override
When connections are made involving ports managed by this NameSpace do the ports involved end up know...
virtual Contact registerAdvanced(const Contact &contact, NameStore *store) override
Record contact information, with access to the contact information of other ports for cross-referenci...
virtual bool connectPortToTopic(const Contact &src, const Contact &dest, const ContactStyle &style) override
Publish a port to a topic.
virtual bool disconnectPortFromTopic(const Contact &src, const Contact &dest, const ContactStyle &style) override
Stop publishing a port to a topic.
void run() override
Main body of the new thread.
bool stop()
Stop the thread.
bool start()
Start the new thread running.
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 std::string asString() const
Get string value.
Small helper class to help deal with legacy YARP configuration files.
std::string getNamespace(bool refresh=false)
static bool isLocalName(const std::string &name)
void setMode(const std::string &mode)
bool fromFile(const char *ns=nullptr)
void setAddress(const Contact &address)
bool toFile(bool clean=false)
std::string toString(const T &value)
convert an arbitrary type to string.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
std::string getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
void gethostname(char *hostname, size_t size)
Portable wrapper for the gethostname() function.