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 
41  class IGNITION_TRANSPORT_VISIBLE Publisher
42  {
44  public: Publisher() = default;
45 
52  public: Publisher(const std::string &_topic,
53  const std::string &_addr,
54  const std::string &_pUuid,
55  const std::string &_nUuid,
56  const AdvertiseOptions &_opts);
57 
59  public: virtual ~Publisher() = default;
60 
64  public: std::string Topic() const;
65 
69  public: std::string Addr() const;
70 
74  public: std::string PUuid() const;
75 
79  public: std::string NUuid() const;
80 
84  public: virtual const AdvertiseOptions &Options() const;
85 
89  public: void SetTopic(const std::string &_topic);
90 
94  public: void SetAddr(const std::string &_addr);
95 
99  public: void SetPUuid(const std::string &_pUuid);
100 
104  public: void SetNUuid(const std::string &_nUuid);
105 
109  public: void SetOptions(const AdvertiseOptions &_opts);
110 
113  public: virtual void FillDiscovery(msgs::Discovery &_msg) const;
114 
117  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
118 
124  public: bool operator==(const Publisher &_pub) const;
125 
131  public: bool operator!=(const Publisher &_pub) const;
132 
136  public: friend std::ostream &operator<<(std::ostream &_out,
137  const Publisher &_msg)
138  {
139  _out << "Publisher:" << std::endl
140  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
141  << "\tAddress: " << _msg.Addr() << std::endl
142  << "\tProcess UUID: " << _msg.PUuid() << std::endl
143  << "\tNode UUID: " << _msg.NUuid() << std::endl
144  << _msg.Options();
145 
146  return _out;
147  }
148 
149 #ifdef _WIN32
150 // Disable warning C4251 which is triggered by
151 // std::string
152 #pragma warning(push)
153 #pragma warning(disable: 4251)
154 #endif
155  protected: std::string topic;
157 
159  protected: std::string addr;
160 
162  protected: std::string pUuid;
163 
165  protected: std::string nUuid;
166 #ifdef _WIN32
167 #pragma warning(pop)
168 #endif
169 
172  private: AdvertiseOptions opts;
173  };
174 
178  class IGNITION_TRANSPORT_VISIBLE MessagePublisher : public Publisher
179  {
181  public: MessagePublisher() = default;
182 
191  public: explicit MessagePublisher(const std::string &_topic,
192  const std::string &_addr,
193  const std::string &_ctrl,
194  const std::string &_pUuid,
195  const std::string &_nUuid,
196  const std::string &_msgTypeName,
197  const AdvertiseMessageOptions &_opts);
198 
200  public: virtual ~MessagePublisher() = default;
201 
206  public: std::string Ctrl() const;
207 
211  public: void SetCtrl(const std::string &_ctrl);
212 
215  public: std::string MsgTypeName() const;
216 
220  public: void SetMsgTypeName(const std::string &_msgTypeName);
221 
225  public: virtual const AdvertiseMessageOptions &Options() const;
226 
230  public: void SetOptions(const AdvertiseMessageOptions &_opts);
231 
234  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
235 
238  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
239 
243  public: friend std::ostream &operator<<(std::ostream &_out,
244  const MessagePublisher &_msg)
245  {
246  _out << "Publisher:" << std::endl
247  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
248  << "\tAddress: " << _msg.Addr() << std::endl
249  << "\tProcess UUID: " << _msg.PUuid() << std::endl
250  << "\tNode UUID: " << _msg.NUuid() << std::endl
251  << "\tControl address: " << _msg.Ctrl() << std::endl
252  << "\tMessage type: " << _msg.MsgTypeName() << std::endl
253  << _msg.Options();
254  return _out;
255  }
256 
262  public: bool operator==(const MessagePublisher &_pub) const;
263 
269  public: bool operator!=(const MessagePublisher &_pub) const;
270 
271 #ifdef _WIN32
272 // Disable warning C4251 which is triggered by
273 // std::unique_ptr
274 #pragma warning(push)
275 #pragma warning(disable: 4251)
276 #endif
277  private: std::string ctrl;
279 
281  private: std::string msgTypeName;
282 #ifdef _WIN32
283 #pragma warning(pop)
284 #endif
285 
287  private: AdvertiseMessageOptions msgOpts;
288  };
289 
293  class IGNITION_TRANSPORT_VISIBLE ServicePublisher : public Publisher
294  {
296  public: ServicePublisher() = default;
297 
307  public: ServicePublisher(const std::string &_topic,
308  const std::string &_addr,
309  const std::string &_id,
310  const std::string &_pUuid,
311  const std::string &_nUuid,
312  const std::string &_reqType,
313  const std::string &_repType,
314  const AdvertiseServiceOptions &_opts);
315 
317  public: virtual ~ServicePublisher() = default;
318 
322  public: std::string SocketId() const;
323 
327  public: void SetSocketId(const std::string &_socketId);
328 
332  public: std::string ReqTypeName() const;
333 
337  public: std::string RepTypeName() const;
338 
342  public: void SetReqTypeName(const std::string &_reqTypeName);
343 
347  public: void SetRepTypeName(const std::string &_repTypeName);
348 
352  public: virtual const AdvertiseServiceOptions& Options() const;
353 
357  public: void SetOptions(const AdvertiseServiceOptions &_opts);
358 
361  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
362 
366  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
367 
371  public: friend std::ostream &operator<<(std::ostream &_out,
372  const ServicePublisher &_msg)
373  {
374  _out << "Publisher:" << std::endl
375  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
376  << "\tAddress: " << _msg.Addr() << std::endl
377  << "\tProcess UUID: " << _msg.PUuid() << std::endl
378  << "\tNode UUID: " << _msg.NUuid() << std::endl
379  << "\tSocket ID: " << _msg.SocketId() << std::endl
380  << "\tRequest type: " << _msg.ReqTypeName() << std::endl
381  << "\tResponse type: " << _msg.RepTypeName() << std::endl
382  << _msg.Options();
383 
384  return _out;
385  }
386 
392  public: bool operator==(const ServicePublisher &_srv) const;
393 
399  public: bool operator!=(const ServicePublisher &_srv) const;
400 
401 #ifdef _WIN32
402 // Disable warning C4251 which is triggered by
403 // std::string
404 #pragma warning(push)
405 #pragma warning(disable: 4251)
406 #endif
407  private: std::string socketId;
409 
411  private: std::string reqTypeName;
412 
414  private: std::string repTypeName;
415 #ifdef _WIN32
416 #pragma warning(pop)
417 #endif
418 
420  private: AdvertiseServiceOptions srvOpts;
421  };
422  }
423  }
424 }
425 
426 #endif
friend std::ostream & operator<<(std::ostream &_out, const Publisher &_msg)
Stream insertion operator.
Definition: gz/transport/Publisher.hh:136
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:41
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:159
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:178
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:371
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:156
std::string pUuid
Process UUID of the publisher.
Definition: gz/transport/Publisher.hh:162
STL class.
std::string nUuid
Node UUID of the publisher.
Definition: gz/transport/Publisher.hh:165
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:293
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:243
void SetPUuid(const std::string &_pUuid)
Set the process UUID of the publisher.