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