YARP
Yet Another Robot Platform
RosNameSpace.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_OS_ROSNAMESPACE_H
7 #define YARP_OS_ROSNAMESPACE_H
8 
9 #include <yarp/os/Bottle.h>
10 #include <yarp/os/NameSpace.h>
11 #include <yarp/os/Network.h>
12 #include <yarp/os/Thread.h>
13 
14 #include <cstdio>
15 #include <mutex>
16 
17 namespace yarp {
18 namespace os {
19 
20 class YARP_os_API RosNameSpace : public NameSpace, public Thread
21 {
22 public:
23  RosNameSpace(const Contact& contact);
24 
25  virtual ~RosNameSpace();
26 
27  Contact getNameServerContact() const override;
28 
29  Contact queryName(const std::string& name) override;
30  Contact registerName(const std::string& name) override;
31  Contact registerContact(const Contact& contact) override;
32  Contact unregisterName(const std::string& name) override;
33  Contact unregisterContact(const Contact& contact) override;
34  virtual Contact registerAdvanced(const Contact& contact,
35  NameStore* store) override;
36  virtual Contact unregisterAdvanced(const std::string& name,
37  NameStore* store) override;
38 
39  virtual bool setProperty(const std::string& name,
40  const std::string& key,
41  const Value& value) override;
42 
43  virtual Value* getProperty(const std::string& name,
44  const std::string& key) override;
45 
46  virtual bool connectPortToTopic(const Contact& src,
47  const Contact& dest,
48  const ContactStyle& style) override;
49  virtual bool connectTopicToPort(const Contact& src,
50  const Contact& dest,
51  const ContactStyle& style) override;
52  virtual bool disconnectPortFromTopic(const Contact& src,
53  const Contact& dest,
54  const ContactStyle& style) override;
55  virtual bool disconnectTopicFromPort(const Contact& src,
56  const Contact& dest,
57  const ContactStyle& style) override;
58  virtual bool connectPortToPortPersistently(const Contact& src,
59  const Contact& dest,
60  const ContactStyle& style) override;
61  virtual bool disconnectPortToPortPersistently(const Contact& src,
62  const Contact& dest,
63  const ContactStyle& style) override;
64  virtual bool connectTopic(Bottle& cmd,
65  bool srcIsTopic,
66  const Contact& src,
67  const Contact& dest,
68  const ContactStyle& style,
69  bool activeRegistration);
70 
71  bool localOnly() const override;
72  bool usesCentralServer() const override;
73  bool serverAllocatesPortNumbers() const override;
74  bool connectionHasNameOfEndpoints() const override;
75 
76  virtual Contact detectNameServer(bool useDetectedServer,
77  bool& scanNeeded,
78  bool& serverUsed) override;
79  virtual bool writeToNameServer(PortWriter& cmd,
80  PortReader& reply,
81  const ContactStyle& style) override;
82 
83 
90  static std::string toRosName(const std::string& name);
91  static std::string fromRosName(const std::string& name);
92  static std::string toRosNodeName(const std::string& name);
93  static std::string fromRosNodeName(const std::string& name);
94  static Contact rosify(const Contact& contact);
95 
96  void run() override;
97 
98 private:
99  Contact contact;
100  Bottle pending;
101  std::mutex mutex;
102 };
103 
104 } // namespace os
105 } // namespace yarp
106 
107 #endif // YARP_OS_ROSNAMESPACE_H
static std::string fromRosName(const std::string &str)
Definition: Node.cpp:66
static std::string toRosName(const std::string &str)
Definition: Node.cpp:61
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
Preferences for how to communicate with a contact.
Definition: ContactStyle.h:24
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
An abstract name space for ports.
Definition: NameSpace.h:23
Abstract interface for a database of port names.
Definition: NameStore.h:20
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
An abstraction for a thread of execution.
Definition: Thread.h:22
A single value (typically within a Bottle).
Definition: Value.h:45
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18