Gazebo Transport

API Reference

13.4.0
Publisher.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GZ_TRANSPORT_PUBLISHER_HH_
19 #define GZ_TRANSPORT_PUBLISHER_HH_
20 
21 #include <gz/msgs/discovery.pb.h>
22 
23 #include <iostream>
24 #include <string>
25 
27 #include "gz/transport/config.hh"
28 #include "gz/transport/Export.hh"
29 
30 namespace gz
31 {
32  namespace transport
33  {
34  // Inline bracket to help doxygen filtering.
35  inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
36  //
37  // Forward declarations.
38  class MessagePublisherPrivate;
39 
44  class GZ_TRANSPORT_VISIBLE Publisher
45  {
47  public: Publisher() = default;
48 
55  public: Publisher(const std::string &_topic,
56  const std::string &_addr,
57  const std::string &_pUuid,
58  const std::string &_nUuid,
59  const AdvertiseOptions &_opts);
60 
62  public: virtual ~Publisher() = default;
63 
67  public: std::string Topic() const;
68 
72  public: std::string Addr() const;
73 
77  public: std::string PUuid() const;
78 
82  public: std::string NUuid() const;
83 
87  public: virtual const AdvertiseOptions &Options() const;
88 
92  public: void SetTopic(const std::string &_topic);
93 
97  public: void SetAddr(const std::string &_addr);
98 
102  public: void SetPUuid(const std::string &_pUuid);
103 
107  public: void SetNUuid(const std::string &_nUuid);
108 
112  public: void SetOptions(const AdvertiseOptions &_opts);
113 
116  public: virtual void FillDiscovery(msgs::Discovery &_msg) const;
117 
120  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
121 
127  public: bool operator==(const Publisher &_pub) const;
128 
134  public: bool operator!=(const Publisher &_pub) const;
135 
139  public: friend std::ostream &operator<<(std::ostream &_out,
140  const Publisher &_msg)
141  {
142  _out << "Publisher:" << std::endl
143  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
144  << "\tAddress: " << _msg.Addr() << std::endl
145  << "\tProcess UUID: " << _msg.PUuid() << std::endl
146  << "\tNode UUID: " << _msg.NUuid() << std::endl
147  << _msg.Options();
148 
149  return _out;
150  }
151 
152 #ifdef _WIN32
153 // Disable warning C4251 which is triggered by
154 // std::string
155 #pragma warning(push)
156 #pragma warning(disable: 4251)
157 #endif
159  protected: std::string topic;
160 
162  protected: std::string addr;
163 
165  protected: std::string pUuid;
166 
168  protected: std::string nUuid;
169 #ifdef _WIN32
170 #pragma warning(pop)
171 #endif
172 
175  private: AdvertiseOptions opts;
176  };
177 
181  class GZ_TRANSPORT_VISIBLE MessagePublisher : public Publisher
182  {
184  public: MessagePublisher() = default;
185 
194  public: explicit MessagePublisher(const std::string &_topic,
195  const std::string &_addr,
196  const std::string &_ctrl,
197  const std::string &_pUuid,
198  const std::string &_nUuid,
199  const std::string &_msgTypeName,
200  const AdvertiseMessageOptions &_opts);
201 
203  public: virtual ~MessagePublisher() = default;
204 
209  public: std::string Ctrl() const;
210 
214  public: void SetCtrl(const std::string &_ctrl);
215 
218  public: std::string MsgTypeName() const;
219 
223  public: void SetMsgTypeName(const std::string &_msgTypeName);
224 
228  public: virtual const AdvertiseMessageOptions &Options() const;
229 
233  public: void SetOptions(const AdvertiseMessageOptions &_opts);
234 
237  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
238 
241  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
242 
246  public: friend std::ostream &operator<<(std::ostream &_out,
247  const MessagePublisher &_msg)
248  {
249  _out << "Publisher:" << std::endl
250  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
251  << "\tAddress: " << _msg.Addr() << std::endl
252  << "\tProcess UUID: " << _msg.PUuid() << std::endl
253  << "\tNode UUID: " << _msg.NUuid() << std::endl
254  << "\tControl address: " << _msg.Ctrl() << std::endl
255  << "\tMessage type: " << _msg.MsgTypeName() << std::endl
256  << _msg.Options();
257  return _out;
258  }
259 
265  public: bool operator==(const MessagePublisher &_pub) const;
266 
272  public: bool operator!=(const MessagePublisher &_pub) const;
273 
274 #ifdef _WIN32
275 // Disable warning C4251 which is triggered by
276 // std::unique_ptr
277 #pragma warning(push)
278 #pragma warning(disable: 4251)
279 #endif
281  private: std::string ctrl;
282 
284  private: std::string msgTypeName;
285 #ifdef _WIN32
286 #pragma warning(pop)
287 #endif
288 
290  private: AdvertiseMessageOptions msgOpts;
291  };
292 
296  class GZ_TRANSPORT_VISIBLE ServicePublisher : public Publisher
297  {
299  public: ServicePublisher() = default;
300 
310  public: ServicePublisher(const std::string &_topic,
311  const std::string &_addr,
312  const std::string &_id,
313  const std::string &_pUuid,
314  const std::string &_nUuid,
315  const std::string &_reqType,
316  const std::string &_repType,
317  const AdvertiseServiceOptions &_opts);
318 
320  public: virtual ~ServicePublisher() = default;
321 
325  public: std::string SocketId() const;
326 
330  public: void SetSocketId(const std::string &_socketId);
331 
335  public: std::string ReqTypeName() const;
336 
340  public: std::string RepTypeName() const;
341 
345  public: void SetReqTypeName(const std::string &_reqTypeName);
346 
350  public: void SetRepTypeName(const std::string &_repTypeName);
351 
355  public: virtual const AdvertiseServiceOptions& Options() const;
356 
360  public: void SetOptions(const AdvertiseServiceOptions &_opts);
361 
364  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
365 
369  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
370 
374  public: friend std::ostream &operator<<(std::ostream &_out,
375  const ServicePublisher &_msg)
376  {
377  _out << "Publisher:" << std::endl
378  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
379  << "\tAddress: " << _msg.Addr() << std::endl
380  << "\tProcess UUID: " << _msg.PUuid() << std::endl
381  << "\tNode UUID: " << _msg.NUuid() << std::endl
382  << "\tSocket ID: " << _msg.SocketId() << std::endl
383  << "\tRequest type: " << _msg.ReqTypeName() << std::endl
384  << "\tResponse type: " << _msg.RepTypeName() << std::endl
385  << _msg.Options();
386 
387  return _out;
388  }
389 
395  public: bool operator==(const ServicePublisher &_srv) const;
396 
402  public: bool operator!=(const ServicePublisher &_srv) const;
403 
404 #ifdef _WIN32
405 // Disable warning C4251 which is triggered by
406 // std::string
407 #pragma warning(push)
408 #pragma warning(disable: 4251)
409 #endif
411  private: std::string socketId;
412 
414  private: std::string reqTypeName;
415 
417  private: std::string repTypeName;
418 #ifdef _WIN32
419 #pragma warning(pop)
420 #endif
421 
423  private: AdvertiseServiceOptions srvOpts;
424  };
425  }
426  }
427 }
428 
429 #endif