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
31 {
32  namespace transport
33  {
34  // Inline bracket to help doxygen filtering.
35  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
36  //
37  // Forward declarations.
38  class MessagePublisherPrivate;
39 
44  class IGNITION_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
158  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 IGNITION_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
280  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 IGNITION_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
410  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
friend std::ostream & operator<<(std::ostream &_out, const Publisher &_msg)
Stream insertion operator.
Definition: gz/transport/Publisher.hh:139
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.
Definition: gz/transport/AdvertiseOptions.hh:28
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:44
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:162
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:181
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:59
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:374
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:134
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:159
std::string pUuid
Process UUID of the publisher.
Definition: gz/transport/Publisher.hh:165
STL class.
std::string nUuid
Node UUID of the publisher.
Definition: gz/transport/Publisher.hh:168
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)
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:296
MessagePublisher()=default
Default constructor.
A class for customizing the publication options for a service advertised.
Definition: gz/transport/AdvertiseOptions.hh:216
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:246
void SetPUuid(const std::string &_pUuid)
Set the process UUID of the publisher.