/src/Fast-DDS/include/fastdds/rtps/attributes/ServerAttributes.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | /** |
16 | | * @file ServerAttributes.h |
17 | | * |
18 | | */ |
19 | | |
20 | | #ifndef _FASTDDS_SERVERATTRIBUTES_H_ |
21 | | #define _FASTDDS_SERVERATTRIBUTES_H_ |
22 | | #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC |
23 | | |
24 | | #include <fastdds/rtps/common/Guid.h> |
25 | | #include <fastdds/rtps/common/Locator.h> |
26 | | |
27 | | #include <algorithm> |
28 | | #include <iterator> |
29 | | #include <list> |
30 | | |
31 | | namespace eprosima { |
32 | | |
33 | | namespace fastrtps { |
34 | | namespace rtps { |
35 | | class ParticipantProxyData; |
36 | | } // fastrtps |
37 | | } // rtps |
38 | | |
39 | | namespace fastdds { |
40 | | namespace rtps { |
41 | | |
42 | | /** |
43 | | * Class RemoteServerAttributes, to define the attributes of the Discovery Server Protocol. |
44 | | * @ingroup RTPS_ATTRIBUTES_MODULE |
45 | | */ |
46 | | |
47 | | class RemoteServerAttributes |
48 | | { |
49 | | public: |
50 | | |
51 | | RTPS_DllAPI inline bool operator ==( |
52 | | const RemoteServerAttributes& r) const |
53 | 0 | { |
54 | 0 | return guidPrefix == r.guidPrefix |
55 | 0 | && metatrafficUnicastLocatorList == r.metatrafficUnicastLocatorList |
56 | 0 | && metatrafficMulticastLocatorList == r.metatrafficMulticastLocatorList; |
57 | 0 | // && proxy == r.proxy; |
58 | 0 | } |
59 | | |
60 | | RTPS_DllAPI void clear() |
61 | 0 | { |
62 | 0 | guidPrefix = fastrtps::rtps::GuidPrefix_t::unknown(); |
63 | 0 | metatrafficUnicastLocatorList.clear(); |
64 | 0 | metatrafficMulticastLocatorList.clear(); |
65 | 0 | proxy = nullptr; |
66 | 0 | } |
67 | | |
68 | | RTPS_DllAPI fastrtps::rtps::GUID_t GetParticipant() const; |
69 | | |
70 | | RTPS_DllAPI fastrtps::rtps::GUID_t GetPDPReader() const; |
71 | | RTPS_DllAPI fastrtps::rtps::GUID_t GetPDPWriter() const; |
72 | | |
73 | | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
74 | | FASTDDS_DEPRECATED_UNTIL(3, "eprosima::fastrtps::rtps:GetEDPPublicationsReader()", |
75 | | "Not implemented nor used functions.") |
76 | | RTPS_DllAPI fastrtps::rtps::GUID_t GetEDPPublicationsReader() const; |
77 | | FASTDDS_DEPRECATED_UNTIL(3, "eprosima::fastrtps::rtps:GetEDPSubscriptionsWriter()", |
78 | | "Not implemented nor used functions.") |
79 | | RTPS_DllAPI fastrtps::rtps::GUID_t GetEDPSubscriptionsWriter() const; |
80 | | |
81 | | FASTDDS_DEPRECATED_UNTIL(3, "eprosima::fastrtps::rtps:GetEDPPublicationsWriter()", |
82 | | "Not implemented nor used functions.") |
83 | | RTPS_DllAPI fastrtps::rtps::GUID_t GetEDPPublicationsWriter() const; |
84 | | FASTDDS_DEPRECATED_UNTIL(3, "eprosima::fastrtps::rtps:GetEDPSubscriptionsReader()", |
85 | | "Not implemented nor used functions.") |
86 | | RTPS_DllAPI fastrtps::rtps::GUID_t GetEDPSubscriptionsReader() const; |
87 | | #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS |
88 | | |
89 | | RTPS_DllAPI inline bool ReadguidPrefix( |
90 | | const char* pfx) |
91 | 0 | { |
92 | 0 | return bool(std::istringstream(pfx) >> guidPrefix); |
93 | 0 | } |
94 | | |
95 | | //!Metatraffic Unicast Locator List |
96 | | LocatorList metatrafficUnicastLocatorList; |
97 | | //!Metatraffic Multicast Locator List. |
98 | | LocatorList metatrafficMulticastLocatorList; |
99 | | |
100 | | //!Guid prefix |
101 | | fastrtps::rtps::GuidPrefix_t guidPrefix; |
102 | | |
103 | | // Live participant proxy reference |
104 | | const fastrtps::rtps::ParticipantProxyData* proxy{}; |
105 | | }; |
106 | | |
107 | | typedef std::list<RemoteServerAttributes> RemoteServerList_t; |
108 | | |
109 | | template<class charT> |
110 | | struct server_ostream_separators |
111 | | { |
112 | | static const charT* list_separator; |
113 | | static const charT* locator_separator; |
114 | | }; |
115 | | |
116 | | #ifndef _MSC_VER |
117 | | template<> const char* server_ostream_separators<char>::list_separator; |
118 | | template<> const wchar_t* server_ostream_separators<wchar_t>::list_separator; |
119 | | |
120 | | template<> const char* server_ostream_separators<char>::locator_separator; |
121 | | template<> const wchar_t* server_ostream_separators<wchar_t>::locator_separator; |
122 | | #endif // _MSC_VER |
123 | | |
124 | | template<class charT> |
125 | | std::basic_ostream<charT>& operator <<( |
126 | | std::basic_ostream<charT>& output, |
127 | | const RemoteServerAttributes& sa) |
128 | | { |
129 | | typename std::basic_ostream<charT>::sentry s(output); |
130 | | output << sa.guidPrefix; |
131 | | if (!sa.metatrafficUnicastLocatorList.empty()) |
132 | | { |
133 | | output << server_ostream_separators<charT>::locator_separator << sa.metatrafficUnicastLocatorList; |
134 | | } |
135 | | if (!sa.metatrafficMulticastLocatorList.empty()) |
136 | | { |
137 | | output << server_ostream_separators<charT>::locator_separator << sa.metatrafficUnicastLocatorList; |
138 | | } |
139 | | return output; |
140 | | } |
141 | | |
142 | | template<class charT> |
143 | | std::basic_ostream<charT>& operator <<( |
144 | | std::basic_ostream<charT>& output, |
145 | | const RemoteServerList_t& list) |
146 | | { |
147 | | typename std::basic_ostream<charT>::sentry s(output); |
148 | | std::ostream_iterator<RemoteServerAttributes> os_iterator(output, server_ostream_separators<charT>::list_separator); |
149 | | std::copy(list.begin(), list.end(), os_iterator); |
150 | | return output; |
151 | | } |
152 | | |
153 | | // port use if the ros environment variable doesn't specified one |
154 | | constexpr uint16_t DEFAULT_ROS2_SERVER_PORT = 11811; |
155 | | // default server base guidPrefix |
156 | | const char* const DEFAULT_ROS2_SERVER_GUIDPREFIX = "44.53.00.5f.45.50.52.4f.53.49.4d.41"; |
157 | | |
158 | | /* Environment variable to specify a semicolon-separated list of UDPv4 locators (ip:port) that define remote server |
159 | | * locators. |
160 | | * The position in the list is used as a "server id" to extrapolate the server's GUID prefix. |
161 | | * For the variable to take any effect, the following pre-conditions must be met: |
162 | | * 1. The server's GUID prefix must be compliant with the schema |
163 | | * "44.53.<server_id_in_hex>.5f.45.50.52.4f.53.49.4d.41", which is the schema followed by the prefixes generated |
164 | | * when creating server using fastdds cli, being DEFAULT_ROS2_SERVER_GUIDPREFIX the prefix for ID=0. |
165 | | * 1. The discovery protocol must be either SIMPLE or SERVER. |
166 | | * 1. In the case of SIMPLE, the participant is created as a CLIENT instead. |
167 | | * 1. In the case of SERVER, the participant is created as a SERVER, using the DEFAULT_ROS2_MASTER_URI list to |
168 | | * expand the list of remote servers. |
169 | | */ |
170 | | const char* const DEFAULT_ROS2_MASTER_URI = "ROS_DISCOVERY_SERVER"; |
171 | | |
172 | | /** |
173 | | * Retrieves a semicolon-separated list of locators from a string, and |
174 | | * populates a RemoteServerList_t mapping list position to default guid. |
175 | | * @param[in] list servers listening locator list. |
176 | | * @param[out] attributes reference to a RemoteServerList_t to populate. |
177 | | * @return true if parsing succeeds, false otherwise (or if the list is empty) |
178 | | */ |
179 | | RTPS_DllAPI bool load_environment_server_info( |
180 | | const std::string& list, |
181 | | RemoteServerList_t& attributes); |
182 | | |
183 | | /** |
184 | | * Retrieves a semicolon-separated list of locators from DEFAULT_ROS2_MASTER_URI environment variable, and |
185 | | * populates a RemoteServerList_t mapping list position to default guid. |
186 | | * |
187 | | * The environment variable can be read from an environment file (which allows runtime modification of the remote |
188 | | * servers list) or directly from the environment. |
189 | | * The value contained in the file takes precedence over the environment value (if both are set). |
190 | | * This is to avoid conflicts because only new servers can be added to the list (containing thus all the previously |
191 | | * known servers). |
192 | | * |
193 | | * @param[out] attributes reference to a RemoteServerList_t to populate. |
194 | | * @return true if parsing succeeds, false otherwise |
195 | | */ |
196 | | RTPS_DllAPI bool load_environment_server_info( |
197 | | RemoteServerList_t& attributes); |
198 | | |
199 | | /** |
200 | | * Get the value of environment variable DEFAULT_ROS2_MASTER_URI |
201 | | * @return The value of environment variable DEFAULT_ROS2_MASTER_URI. Empty string if the variable is not defined. |
202 | | */ |
203 | | RTPS_DllAPI const std::string& ros_discovery_server_env(); |
204 | | |
205 | | /** |
206 | | * Returns the guidPrefix associated to the given server id |
207 | | * @param[in] id of the default server whose guidPrefix we want to retrieve |
208 | | * @param[out] guid reference to the guidPrefix to modify |
209 | | * @return true if the server guid can be delivered |
210 | | */ |
211 | | RTPS_DllAPI bool get_server_client_default_guidPrefix( |
212 | | int id, |
213 | | fastrtps::rtps::GuidPrefix_t& guid); |
214 | | |
215 | | } // namespace rtps |
216 | | } // namespace fastdds |
217 | | |
218 | | // keep former namespace references available |
219 | | namespace fastrtps { |
220 | | namespace rtps { |
221 | | |
222 | | using fastdds::rtps::RemoteServerAttributes; |
223 | | using fastdds::rtps::RemoteServerList_t; |
224 | | using fastdds::rtps::DEFAULT_ROS2_SERVER_PORT; |
225 | | using fastdds::rtps::DEFAULT_ROS2_SERVER_GUIDPREFIX; |
226 | | using fastdds::rtps::DEFAULT_ROS2_MASTER_URI; |
227 | | using fastdds::rtps::load_environment_server_info; |
228 | | using fastdds::rtps::ros_discovery_server_env; |
229 | | using fastdds::rtps::get_server_client_default_guidPrefix; |
230 | | |
231 | | } // fastrtps |
232 | | } // rtps |
233 | | |
234 | | } // namespace eprosima |
235 | | |
236 | | #endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC |
237 | | #endif /* _FASTDDS_SERVERATTRIBUTES_H_ */ |