Gazebo Transport

API Reference

11.4.1
gz/transport/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 ignition::transport
31 {
32  // Inline bracket to help doxygen filtering.
33  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
34 
39  class IGNITION_TRANSPORT_VISIBLE Publisher
40  {
42  public: Publisher() = default;
43 
50  public: Publisher(const std::string &_topic,
51  const std::string &_addr,
52  const std::string &_pUuid,
53  const std::string &_nUuid,
54  const AdvertiseOptions &_opts);
55 
57  public: virtual ~Publisher() = default;
58 
62  public: std::string Topic() const;
63 
67  public: std::string Addr() const;
68 
72  public: std::string PUuid() const;
73 
77  public: std::string NUuid() const;
78 
82  public: virtual const AdvertiseOptions &Options() const;
83 
87  public: void SetTopic(const std::string &_topic);
88 
92  public: void SetAddr(const std::string &_addr);
93 
97  public: void SetPUuid(const std::string &_pUuid);
98 
102  public: void SetNUuid(const std::string &_nUuid);
103 
107  public: void SetOptions(const AdvertiseOptions &_opts);
108 
111  public: virtual void FillDiscovery(msgs::Discovery &_msg) const;
112 
115  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
116 
122  public: bool operator==(const Publisher &_pub) const;
123 
129  public: bool operator!=(const Publisher &_pub) const;
130 
134  public: friend std::ostream &operator<<(std::ostream &_out,
135  const Publisher &_msg)
136  {
137  _out << "Publisher:" << std::endl
138  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
139  << "\tAddress: " << _msg.Addr() << std::endl
140  << "\tProcess UUID: " << _msg.PUuid() << std::endl
141  << "\tNode UUID: " << _msg.NUuid() << std::endl
142  << _msg.Options();
143 
144  return _out;
145  }
146 
147 #ifdef _WIN32
148 // Disable warning C4251 which is triggered by
149 // std::string
150 #pragma warning(push)
151 #pragma warning(disable: 4251)
152 #endif
153  protected: std::string topic;
155 
157  protected: std::string addr;
158 
160  protected: std::string pUuid;
161 
163  protected: std::string nUuid;
164 #ifdef _WIN32
165 #pragma warning(pop)
166 #endif
167 
170  private: AdvertiseOptions opts;
171  };
172 
176  class IGNITION_TRANSPORT_VISIBLE MessagePublisher : public Publisher
177  {
179  public: MessagePublisher() = default;
180 
189  public: explicit MessagePublisher(const std::string &_topic,
190  const std::string &_addr,
191  const std::string &_ctrl,
192  const std::string &_pUuid,
193  const std::string &_nUuid,
194  const std::string &_msgTypeName,
195  const AdvertiseMessageOptions &_opts);
196 
198  public: virtual ~MessagePublisher() = default;
199 
204  public: std::string Ctrl() const;
205 
209  public: void SetCtrl(const std::string &_ctrl);
210 
213  public: std::string MsgTypeName() const;
214 
218  public: void SetMsgTypeName(const std::string &_msgTypeName);
219 
223  public: virtual const AdvertiseMessageOptions &Options() const;
224 
228  public: void SetOptions(const AdvertiseMessageOptions &_opts);
229 
232  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
233 
236  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
237 
241  public: friend std::ostream &operator<<(std::ostream &_out,
242  const MessagePublisher &_msg)
243  {
244  _out << "Publisher:" << std::endl
245  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
246  << "\tAddress: " << _msg.Addr() << std::endl
247  << "\tProcess UUID: " << _msg.PUuid() << std::endl
248  << "\tNode UUID: " << _msg.NUuid() << std::endl
249  << "\tControl address: " << _msg.Ctrl() << std::endl
250  << "\tMessage type: " << _msg.MsgTypeName() << std::endl
251  << _msg.Options();
252  return _out;
253  }
254 
260  public: bool operator==(const MessagePublisher &_pub) const;
261 
267  public: bool operator!=(const MessagePublisher &_pub) const;
268 
269 #ifdef _WIN32
270 // Disable warning C4251 which is triggered by
271 // std::unique_ptr
272 #pragma warning(push)
273 #pragma warning(disable: 4251)
274 #endif
275  private: std::string ctrl;
277 
279  private: std::string msgTypeName;
280 #ifdef _WIN32
281 #pragma warning(pop)
282 #endif
283 
285  private: AdvertiseMessageOptions msgOpts;
286  };
287 
291  class IGNITION_TRANSPORT_VISIBLE ServicePublisher : public Publisher
292  {
294  public: ServicePublisher() = default;
295 
305  public: ServicePublisher(const std::string &_topic,
306  const std::string &_addr,
307  const std::string &_id,
308  const std::string &_pUuid,
309  const std::string &_nUuid,
310  const std::string &_reqType,
311  const std::string &_repType,
312  const AdvertiseServiceOptions &_opts);
313 
315  public: virtual ~ServicePublisher() = default;
316 
320  public: std::string SocketId() const;
321 
325  public: void SetSocketId(const std::string &_socketId);
326 
330  public: std::string ReqTypeName() const;
331 
335  public: std::string RepTypeName() const;
336 
340  public: void SetReqTypeName(const std::string &_reqTypeName);
341 
345  public: void SetRepTypeName(const std::string &_repTypeName);
346 
350  public: virtual const AdvertiseServiceOptions& Options() const;
351 
355  public: void SetOptions(const AdvertiseServiceOptions &_opts);
356 
359  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
360 
364  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
365 
369  public: friend std::ostream &operator<<(std::ostream &_out,
370  const ServicePublisher &_msg)
371  {
372  _out << "Publisher:" << std::endl
373  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
374  << "\tAddress: " << _msg.Addr() << std::endl
375  << "\tProcess UUID: " << _msg.PUuid() << std::endl
376  << "\tNode UUID: " << _msg.NUuid() << std::endl
377  << "\tSocket ID: " << _msg.SocketId() << std::endl
378  << "\tRequest type: " << _msg.ReqTypeName() << std::endl
379  << "\tResponse type: " << _msg.RepTypeName() << std::endl
380  << _msg.Options();
381 
382  return _out;
383  }
384 
390  public: bool operator==(const ServicePublisher &_srv) const;
391 
397  public: bool operator!=(const ServicePublisher &_srv) const;
398 
399 #ifdef _WIN32
400 // Disable warning C4251 which is triggered by
401 // std::string
402 #pragma warning(push)
403 #pragma warning(disable: 4251)
404 #endif
405  private: std::string socketId;
407 
409  private: std::string reqTypeName;
410 
412  private: std::string repTypeName;
413 #ifdef _WIN32
414 #pragma warning(pop)
415 #endif
416 
418  private: AdvertiseServiceOptions srvOpts;
419  };
420  }
421 }
422 
423 #endif
friend std::ostream & operator<<(std::ostream &_out, const Publisher &_msg)
Stream insertion operator.
Definition: gz/transport/Publisher.hh:134
bool operator!=(const MessagePublisher &_pub) const
Inequality operator. This function checks if the given message publisher does not have identical Topi...
bool operator==(const MessagePublisher &_pub) const
Equality operator. This function checks if the given message publisher has identical Topic,...
virtual const AdvertiseOptions & Options() const
Get the advertised options.
STL class.
std::string ReqTypeName() const
Get the name of the request's protobuf message advertised.
void SetReqTypeName(const std::string &_reqTypeName)
Set the name of the request's protobuf message advertised.
This class stores all the information about a publisher. It stores the topic name that publishes,...
Definition: gz/transport/Publisher.hh:39
virtual const AdvertiseServiceOptions & Options() const
Get the advertised options.
virtual ~ServicePublisher()=default
Destructor.
std::string addr
ZeroMQ address of the publisher.
Definition: gz/transport/Publisher.hh:157
virtual void SetFromDiscovery(const msgs::Discovery &_msg)
Populate a discovery message.
std::string PUuid() const
Get the process UUID of the publisher. return Process UUID.
virtual void FillDiscovery(msgs::Discovery &_msg) const
Populate a discovery message.
virtual ~MessagePublisher()=default
Destructor.
bool operator==(const Publisher &_pub) const
Equality operator. This function checks if the given publisher has identical Topic,...
void SetNUuid(const std::string &_nUuid)
Set the node UUID of the publisher.
void SetCtrl(const std::string &_ctrl)
Set the ZeroMQ control address of the publisher.
This class stores all the information about a message publisher.
Definition: gz/transport/Publisher.hh:176
virtual void SetFromDiscovery(const msgs::Discovery &_msg)
Set data from a discovery message.
A class for customizing the publication options for a topic or service advertised....
Definition: gz/transport/AdvertiseOptions.hh:57
std::string Topic() const
Get the topic published by this publisher.
std::string Addr() const
Get the ZeroMQ address of the publisher.
std::string SocketId() const
Get the ZeroMQ socket ID used by this publisher.
friend std::ostream & operator<<(std::ostream &_out, const ServicePublisher &_msg)
Stream insertion operator.
Definition: gz/transport/Publisher.hh:369
bool operator!=(const ServicePublisher &_srv) const
Inequality operator. This function checks if the given service does not have identical Topic,...
A class for customizing the publication options for a topic advertised. E.g.: Set the rate of message...
Definition: gz/transport/AdvertiseOptions.hh:132
void SetMsgTypeName(const std::string &_msgTypeName)
Set the message type advertised by this publisher.
bool operator==(const ServicePublisher &_srv) const
Equality operator. This function checks if the given service has identical Topic, Addr,...
std::string topic
Topic name.
Definition: gz/transport/Publisher.hh:154
std::string pUuid
Process UUID of the publisher.
Definition: gz/transport/Publisher.hh:160
STL class.
std::string nUuid
Node UUID of the publisher.
Definition: gz/transport/Publisher.hh:163
void SetOptions(const AdvertiseServiceOptions &_opts)
Set the advertised options.
bool operator!=(const Publisher &_pub) const
Inequality operator. This function checks if the given publisher does not have identical Topic,...
void SetOptions(const AdvertiseOptions &_opts)
Set the advertised options.
std::string MsgTypeName() const
Get the message type advertised by this publisher.
virtual void FillDiscovery(msgs::Discovery &_msg) const final
Populate a discovery message.
virtual ~Publisher()=default
Destructor.
virtual const AdvertiseMessageOptions & Options() const
Get the advertised options.
void SetSocketId(const std::string &_socketId)
Set the ZeroMQ socket ID for this publisher.
Publisher()=default
Default constructor.
ServicePublisher()=default
Default constructor.
void SetOptions(const AdvertiseMessageOptions &_opts)
Set the advertised options.
void SetTopic(const std::string &_topic)
Set the topic name published by this publisher.
void SetRepTypeName(const std::string &_repTypeName)
Set the name of the response's protobuf message advertised.
virtual void SetFromDiscovery(const msgs::Discovery &_msg)
Set data from a discovery message.
T endl(T... args)
Definition: gz/transport/AdvertiseOptions.hh:28
void SetAddr(const std::string &_addr)
Set ZeroMQ address of the publisher.
This class stores all the information about a service publisher.
Definition: gz/transport/Publisher.hh:291
MessagePublisher()=default
Default constructor.
A class for customizing the publication options for a service advertised.
Definition: gz/transport/AdvertiseOptions.hh:214
std::string Ctrl() const
Get the ZeroMQ control address. This address is used by the subscribers to notify the publisher about...
virtual void FillDiscovery(msgs::Discovery &_msg) const final
Populate a discovery message.
std::string RepTypeName() const
Get the name of the response's protobuf message advertised.
std::string NUuid() const
Get the node UUID of the publisher.
friend std::ostream & operator<<(std::ostream &_out, const MessagePublisher &_msg)
Stream insertion operator.
Definition: gz/transport/Publisher.hh:241
void SetPUuid(const std::string &_pUuid)
Set the process UUID of the publisher.