Ignition Transport

API Reference

10.0.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 IGN_TRANSPORT_PUBLISHER_HH_
19 #define IGN_TRANSPORT_PUBLISHER_HH_
20 
21 #include <ignition/msgs/discovery.pb.h>
22 
23 #include <iostream>
24 #include <string>
25 
27 #include "ignition/transport/config.hh"
28 #include "ignition/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 
63  public: Publisher(const Publisher &_other);
64 
66  public: virtual ~Publisher() = default;
67 
71  public: std::string Topic() const;
72 
76  public: std::string Addr() const;
77 
81  public: std::string PUuid() const;
82 
86  public: std::string NUuid() const;
87 
91  public: virtual const AdvertiseOptions &Options() const;
92 
96  public: void SetTopic(const std::string &_topic);
97 
101  public: void SetAddr(const std::string &_addr);
102 
106  public: void SetPUuid(const std::string &_pUuid);
107 
111  public: void SetNUuid(const std::string &_nUuid);
112 
116  public: void SetOptions(const AdvertiseOptions &_opts);
117 
120  public: virtual void FillDiscovery(msgs::Discovery &_msg) const;
121 
124  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
125 
131  public: bool operator==(const Publisher &_pub) const;
132 
138  public: bool operator!=(const Publisher &_pub) const;
139 
143  public: Publisher &operator=(const Publisher &_other);
144 
148  public: friend std::ostream &operator<<(std::ostream &_out,
149  const Publisher &_msg)
150  {
151  _out << "Publisher:" << std::endl
152  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
153  << "\tAddress: " << _msg.Addr() << std::endl
154  << "\tProcess UUID: " << _msg.PUuid() << std::endl
155  << "\tNode UUID: " << _msg.NUuid() << std::endl
156  << _msg.Options();
157 
158  return _out;
159  }
160 
161 #ifdef _WIN32
162 // Disable warning C4251 which is triggered by
163 // std::string
164 #pragma warning(push)
165 #pragma warning(disable: 4251)
166 #endif
167  protected: std::string topic;
169 
171  protected: std::string addr;
172 
174  protected: std::string pUuid;
175 
177  protected: std::string nUuid;
178 #ifdef _WIN32
179 #pragma warning(pop)
180 #endif
181 
184  private: AdvertiseOptions opts;
185  };
186 
190  class IGNITION_TRANSPORT_VISIBLE MessagePublisher : public Publisher
191  {
193  public: MessagePublisher() = default;
194 
203  public: explicit MessagePublisher(const std::string &_topic,
204  const std::string &_addr,
205  const std::string &_ctrl,
206  const std::string &_pUuid,
207  const std::string &_nUuid,
208  const std::string &_msgTypeName,
209  const AdvertiseMessageOptions &_opts);
210 
213  public: MessagePublisher(const MessagePublisher &_other);
214 
216  public: virtual ~MessagePublisher() = default;
217 
222  public: std::string Ctrl() const;
223 
227  public: void SetCtrl(const std::string &_ctrl);
228 
231  public: std::string MsgTypeName() const;
232 
236  public: void SetMsgTypeName(const std::string &_msgTypeName);
237 
241  public: virtual const AdvertiseMessageOptions &Options() const;
242 
246  public: void SetOptions(const AdvertiseMessageOptions &_opts);
247 
250  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
251 
254  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
255 
259  public: friend std::ostream &operator<<(std::ostream &_out,
260  const MessagePublisher &_msg)
261  {
262  _out << "Publisher:" << std::endl
263  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
264  << "\tAddress: " << _msg.Addr() << std::endl
265  << "\tProcess UUID: " << _msg.PUuid() << std::endl
266  << "\tNode UUID: " << _msg.NUuid() << std::endl
267  << "\tControl address: " << _msg.Ctrl() << std::endl
268  << "\tMessage type: " << _msg.MsgTypeName() << std::endl
269  << _msg.Options();
270  return _out;
271  }
272 
278  public: bool operator==(const MessagePublisher &_pub) const;
279 
285  public: bool operator!=(const MessagePublisher &_pub) const;
286 
290  public: MessagePublisher &operator=(const MessagePublisher &_other);
291 
292 #ifdef _WIN32
293 // Disable warning C4251 which is triggered by
294 // std::unique_ptr
295 #pragma warning(push)
296 #pragma warning(disable: 4251)
297 #endif
298  private: std::string ctrl;
300 
302  private: std::string msgTypeName;
303 #ifdef _WIN32
304 #pragma warning(pop)
305 #endif
306 
308  private: AdvertiseMessageOptions msgOpts;
309  };
310 
314  class IGNITION_TRANSPORT_VISIBLE ServicePublisher : public Publisher
315  {
317  public: ServicePublisher() = default;
318 
328  public: ServicePublisher(const std::string &_topic,
329  const std::string &_addr,
330  const std::string &_id,
331  const std::string &_pUuid,
332  const std::string &_nUuid,
333  const std::string &_reqType,
334  const std::string &_repType,
335  const AdvertiseServiceOptions &_opts);
336 
339  public: ServicePublisher(const ServicePublisher &_other);
340 
342  public: virtual ~ServicePublisher() = default;
343 
347  public: std::string SocketId() const;
348 
352  public: void SetSocketId(const std::string &_socketId);
353 
357  public: std::string ReqTypeName() const;
358 
362  public: std::string RepTypeName() const;
363 
367  public: void SetReqTypeName(const std::string &_reqTypeName);
368 
372  public: void SetRepTypeName(const std::string &_repTypeName);
373 
377  public: virtual const AdvertiseServiceOptions& Options() const;
378 
382  public: void SetOptions(const AdvertiseServiceOptions &_opts);
383 
386  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
387 
391  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
392 
396  public: friend std::ostream &operator<<(std::ostream &_out,
397  const ServicePublisher &_msg)
398  {
399  _out << "Publisher:" << std::endl
400  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
401  << "\tAddress: " << _msg.Addr() << std::endl
402  << "\tProcess UUID: " << _msg.PUuid() << std::endl
403  << "\tNode UUID: " << _msg.NUuid() << std::endl
404  << "\tSocket ID: " << _msg.SocketId() << std::endl
405  << "\tRequest type: " << _msg.ReqTypeName() << std::endl
406  << "\tResponse type: " << _msg.RepTypeName() << std::endl
407  << _msg.Options();
408 
409  return _out;
410  }
411 
417  public: bool operator==(const ServicePublisher &_srv) const;
418 
424  public: bool operator!=(const ServicePublisher &_srv) const;
425 
429  public: ServicePublisher &operator=(const ServicePublisher &_other);
430 
431 #ifdef _WIN32
432 // Disable warning C4251 which is triggered by
433 // std::string
434 #pragma warning(push)
435 #pragma warning(disable: 4251)
436 #endif
437  private: std::string socketId;
439 
441  private: std::string reqTypeName;
442 
444  private: std::string repTypeName;
445 #ifdef _WIN32
446 #pragma warning(pop)
447 #endif
448 
450  private: AdvertiseServiceOptions srvOpts;
451  };
452  }
453  }
454 }
455 
456 #endif
friend std::ostream & operator<<(std::ostream &_out, const Publisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:148
virtual const AdvertiseMessageOptions & Options() const
Get the advertised options.
A class for customizing the publication options for a topic advertised. E.g.: Set the rate of message...
Definition: AdvertiseOptions.hh:134
This class stores all the information about a publisher. It stores the topic name that publishes...
Definition: Publisher.hh:44
virtual const AdvertiseServiceOptions & Options() const
Get the advertised options.
std::string MsgTypeName() const
Get the message type advertised by this publisher.
T endl(T... args)
std::string NUuid() const
Get the node UUID of the publisher.
std::string RepTypeName() const
Get the name of the response&#39;s protobuf message advertised.
virtual const AdvertiseOptions & Options() const
Get the advertised options.
STL class.
A class for customizing the publication options for a topic or service advertised. E.g.: Set the scope of a topic/service.
Definition: AdvertiseOptions.hh:59
std::string PUuid() const
Get the process UUID of the publisher. return Process UUID.
std::string Addr() const
Get the ZeroMQ address of the publisher.
std::string Topic() const
Get the topic published by this publisher.
std::string nUuid
Node UUID of the publisher.
Definition: Publisher.hh:177
std::string SocketId() const
Get the ZeroMQ socket ID used by this publisher.
A class for customizing the publication options for a service advertised.
Definition: AdvertiseOptions.hh:216
std::string Ctrl() const
Get the ZeroMQ control address. This address is used by the subscribers to notify the publisher about...
This class stores all the information about a message publisher.
Definition: Publisher.hh:190
std::string pUuid
Process UUID of the publisher.
Definition: Publisher.hh:174
This class stores all the information about a service publisher.
Definition: Publisher.hh:314
friend std::ostream & operator<<(std::ostream &_out, const ServicePublisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:396
Definition: AdvertiseOptions.hh:28
std::string addr
ZeroMQ address of the publisher.
Definition: Publisher.hh:171
STL class.
std::string ReqTypeName() const
Get the name of the request&#39;s protobuf message advertised.
friend std::ostream & operator<<(std::ostream &_out, const MessagePublisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:259