|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
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();
A dummy connection to test yarp::os::Portable implementations.
A simple collection of objects that can be described and transmitted in a portable way.
virtual bool disconnectPortFromTopic(const Contact &src, const Contact &dest, const ContactStyle &style) override
Stop publishing a port to a topic.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Contact registerName(const std::string &name) override
Record contact information to tie to a port name.
void clear()
Empties the bottle of any objects it contains.
virtual bool read(ConnectionReader &reader)=0
Read this object from a network connection.
size_type size() const
Gets the number of elements in the bottle.
Contact unregisterContact(const Contact &contact) override
Disassociate contact information (should include a port name).
static bool isLocalName(const std::string &name)
Abstract interface for a database of port names.
virtual bool disconnectTopicFromPort(const Contact &src, const Contact &dest, const ContactStyle &style) override
Stop subscribing a port to a topic.
void run() override
Main body of the new thread.
std::string getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
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.
ConnectionReader & getReader(ConnectionWriter *replyWriter=nullptr)
Get the dummy ConnectionReader loaded with whatever was written the ConnectionWriter since it was las...
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
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...
std::string getNamespace(bool refresh=false)
Contact getURI(const std::string &name)
getURI queries the Node specified in the name parameter to get Contact information about the specifie...
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void setMode(const std::string &mode)
Contact unregisterName(const std::string &name) override
Disassociate contact information from a port name.
virtual Contact detectNameServer(bool useDetectedServer, bool &scanNeeded, bool &serverUsed) override
Find a name server for this NameSpace, if applicable.
static Contact queryName(const std::string &name)
Find out information about a registered name.
Contact getParent(const std::string &name)
getParent get info about node associated with the specified port.
RosNameSpace(const Contact &contact)
static std::string fromRosNodeName(const std::string &name)
static std::string toRosName(const std::string &name)
Possible ROS names are a subset of YARP names.
bool serverAllocatesPortNumbers() const override
Check if a central server is responsible for allocating port numbers, or if this should be left up to...
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
virtual Value * getProperty(const std::string &name, const std::string &key) override
Get the value of a named key from a named port.
void setAddress(const Contact &address)
bool localOnly() const override
Check if the NameSpace is only valid for the current process ("local").
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
ConnectionWriter & getWriter()
Get the dummy ConnectionWriter loaded with whatever was written the ConnectionWriter since it was las...
virtual std::string asString() const
Get string value.
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 rosify(const Contact &contact)
virtual bool connectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style) override
Connect two ports with persistence.
void gethostname(char *hostname, size_t size)
Portable wrapper for the gethostname() function.
static std::string toRosNodeName(const std::string &name)
bool connectionHasNameOfEndpoints() const override
When connections are made involving ports managed by this NameSpace do the ports involved end up know...
virtual Contact query(const std::string &name)=0
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
virtual bool write(ConnectionWriter &writer) const =0
Write this object to a network connection.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Contact registerContact(const Contact &contact) override
Record contact information (should include a port name).
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
Bottle tail() const
Get all but the first element of a bottle.
bool toFile(bool clean=false)
bool usesCentralServer() const override
Check if a central server is involved in managing the NameSpace.
#define yCError(component,...)
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual bool disconnectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style) override
Disconnect two ports, removing any persistence.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
Contact getNameServerContact() const override
Get an address for a name server that manages the name space, if available.
std::string toString(const T &value)
convert an arbitrary type to string.
virtual Contact registerAdvanced(const Contact &contact, NameStore *store) override
Record contact information, with access to the contact information of other ports for cross-referenci...
void cat(Vector &a, const Vector &b)
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
virtual bool setProperty(const std::string &name, const std::string &key, const Value &value) override
Associate a key/value pair with a named port.
virtual Bottle * asList() const
Get list value.
bool fromFile(const char *ns=nullptr)
bool start()
Start the new thread running.
virtual bool connectTopic(Bottle &cmd, bool srcIsTopic, const Contact &src, const Contact &dest, const ContactStyle &style, bool activeRegistration)
Contact queryName(const std::string &name) override
Map from port name to contact information.
A single value (typically within a Bottle).
bool stop()
Stop the thread.
Small helper class to help deal with legacy YARP configuration files.
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.
virtual bool connectTopicToPort(const Contact &src, const Contact &dest, const ContactStyle &style) override
Subscribe a port to a topic.
static std::string fromRosName(const std::string &name)
virtual bool writeToNameServer(PortWriter &cmd, PortReader &reply, const ContactStyle &style) override
Write a message to a name server for this NameSpace, if applicable.
virtual bool connectPortToTopic(const Contact &src, const Contact &dest, const ContactStyle &style) override
Publish a port to a topic.
A class for storing options and configuration information.
static bool disconnect(const std::string &src, const std::string &dest, bool quiet)
Request that an output port disconnect from an input port.