53 for (
auto ns : spaces) {
61 _usesCentralServer =
false;
62 _serverAllocatesPortNumbers =
false;
63 _connectionHasNameOfEndpoints =
true;
70 _usesCentralServer =
false;
71 _serverAllocatesPortNumbers =
true;
73 for (
auto ns : spaces) {
78 if (!ns->localOnly()) {
82 if (ns->usesCentralServer()) {
83 _usesCentralServer =
true;
87 if (!ns->serverAllocatesPortNumbers()) {
88 _serverAllocatesPortNumbers =
false;
92 if (!ns->connectionHasNameOfEndpoints()) {
93 _connectionHasNameOfEndpoints =
false;
105 spaces.push_back(ns);
119 if (!spaces.empty()) {
126 static double last_shown =
now - 10;
127 if (
now - last_shown > 3) {
129 yCWarning(MULTINAMESPACE,
"YARP name server(s) not configured, ports will be anonymous\n");
130 yCWarning(MULTINAMESPACE,
"check your namespace and settings with 'yarp detect'\n");
136 for (
size_t i = 0; i < ns.
size(); i++) {
141 yCWarning(MULTINAMESPACE,
"Could not find namespace %s\n", n.c_str());
144 std::string mode = conf2.
getMode();
147 if (mode ==
"yarp" || mode ==
"//") {
150 spaces.push_back(ns);
151 }
else if (mode ==
"ros") {
154 spaces.push_back(ns);
155 }
else if (mode ==
"local") {
157 spaces.push_back(ns);
160 yCError(MULTINAMESPACE,
"cannot deal with namespace of type %s", mode.c_str());
172 if (!spaces.empty()) {
174 return spaces[0]->getNameServerContact();
183 for (
auto ns : spaces) {
187 if (ns->getNameServerName() == name) {
190 return ns->getNameServerContact();
192 Contact result = ns->queryName(name);
206 if (spaces.empty()) {
220 #define HELPER(x) (*((MultiNameSpaceHelper*)((x)->system_resource)))
226 yCAssert(MULTINAMESPACE, system_resource !=
nullptr);
231 if (system_resource !=
nullptr) {
233 system_resource =
nullptr;
239 return HELPER(
this).setLocalMode(flag);
245 return HELPER(
this)._localOnly;
251 return HELPER(
this)._usesCentralServer;
257 return HELPER(
this)._connectionHasNameOfEndpoints;
273 return HELPER(
this)._serverAllocatesPortNumbers;
278 return HELPER(
this).activate(force);
288 return HELPER(
this).queryName(name);
362 for (
size_t i = 0; i < lst.size(); i++) {
368 iresult = lst[i]->registerName(name);
370 iresult = lst[i]->registerContact(result);
372 if (i == 0 || result.
getPort() <= 0) {
383 for (
size_t i = 0; i < lst.size(); i++) {
385 Contact iresult = lst[i]->registerContact(contact);
397 for (
size_t i = 0; i < lst.size(); i++) {
399 Contact iresult = lst[i]->unregisterName(name);
411 for (
size_t i = 0; i < lst.size(); i++) {
413 Contact iresult = lst[i]->unregisterContact(contact);
451 if (name.find(
"/ros") != std::string::npos) {
454 if (r.
isValid() && useDetectedServer && scanNeeded) {
455 HELPER(
this).activate(
true);
460 if (r.
isValid() && useDetectedServer && scanNeeded) {
461 HELPER(
this).activate(
true);
std::vector< NameSpace * > SpaceList
bool setLocalMode(bool flag)
bool _serverAllocatesPortNumbers
Contact getNameServerContact()
Contact queryName(const std::string &name)
bool _connectionHasNameOfEndpoints
bool activate(bool force=false)
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.
Contact getNameServerContact() const override
Get an address for a name server that manages the name space, if available.
Contact registerName(const std::string &name) override
Record contact information to tie to a port name.
virtual ~MultiNameSpace()
virtual bool connectPortToTopic(const Contact &src, const Contact &dest, const ContactStyle &style) override
Publish a port to a topic.
virtual NameStore * getQueryBypass()
Get any alternative place to make name queries, if one was set by queryBypass()
virtual bool connectTopicToPort(const Contact &src, const Contact &dest, const ContactStyle &style) override
Subscribe a port to a topic.
virtual bool connectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style) override
Connect two ports with persistence.
Value * getProperty(const std::string &name, const std::string &key) override
Get the value of a named key from a named port.
virtual bool disconnectTopicFromPort(const Contact &src, const Contact &dest, const ContactStyle &style) override
Stop subscribing a port to a topic.
virtual bool disconnectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style) override
Disconnect two ports, removing any persistence.
virtual void queryBypass(NameStore *store)
Set an alternative place to make name queries.
bool connectionHasNameOfEndpoints() const override
When connections are made involving ports managed by this NameSpace do the ports involved end up know...
Contact queryName(const std::string &name) override
Map from port name to contact information.
bool localOnly() const override
Check if the NameSpace is only valid for the current process ("local").
bool serverAllocatesPortNumbers() const override
Check if a central server is responsible for allocating port numbers, or if this should be left up to...
bool usesCentralServer() const override
Check if a central server is involved in managing the NameSpace.
bool activate(bool force=false)
virtual bool disconnectPortFromTopic(const Contact &src, const Contact &dest, const ContactStyle &style) override
Stop publishing a port to a topic.
Contact unregisterName(const std::string &name) override
Disassociate contact information from a port name.
Contact registerContact(const Contact &contact) override
Record contact information (should include a port name).
Contact unregisterContact(const Contact &contact) override
Disassociate contact information (should include a port name).
virtual bool setProperty(const std::string &name, const std::string &key, const Value &value) override
Associate a key/value pair with a named port.
bool setLocalMode(bool flag)
virtual Contact detectNameServer(bool useDetectedServer, bool &scanNeeded, bool &serverUsed) override
Find a name server for this NameSpace, if applicable.
virtual bool writeToNameServer(PortWriter &cmd, PortReader &reply, const ContactStyle &style) override
Write a message to a name server for this NameSpace, if applicable.
An abstract name space for ports.
virtual bool disconnectTopicFromPort(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Stop subscribing a port to a topic.
virtual bool disconnectPortFromTopic(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Stop publishing a port to a topic.
virtual bool connectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Connect two ports with persistence.
virtual bool connectTopicToPort(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Subscribe a port to a topic.
virtual bool writeToNameServer(PortWriter &cmd, PortReader &reply, const ContactStyle &style)=0
Write a message to a name server for this NameSpace, if applicable.
virtual bool connectPortToTopic(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Publish a port to a topic.
virtual bool setProperty(const std::string &name, const std::string &key, const Value &value)=0
Associate a key/value pair with a named port.
virtual Value * getProperty(const std::string &name, const std::string &key)=0
Get the value of a named key from a named port.
virtual bool disconnectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Disconnect two ports, removing any persistence.
Abstract interface for a database of port names.
static std::string getNameServerName()
Get the name of the port associated with the nameserver (usually "/root", but this can be overwritten...
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
virtual Contact detectNameServer(bool useDetectedServer, bool &scanNeeded, bool &serverUsed) override
Find a name server for this NameSpace, if applicable.
static double nowSystem()
A single value (typically within a Bottle).
virtual std::string asString() const
Get string value.
virtual Contact detectNameServer(bool useDetectedServer, bool &scanNeeded, bool &serverUsed) override
Find a name server for this NameSpace, if applicable.
Small helper class to help deal with legacy YARP configuration files.
bool fromFile(const char *ns=nullptr)
yarp::os::Bottle getNamespaces(bool refresh=false)
#define yCError(component,...)
#define yCAssert(component, x)
#define yCWarning(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.