Ignition Transport

API Reference

8.1.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 
123  public: virtual size_t IGN_DEPRECATED(8) Pack(char *_buffer) const;
124 
127  public: virtual size_t IGN_DEPRECATED(8) Unpack(const char *_buffer);
128 
131  public: virtual size_t IGN_DEPRECATED(8) MsgLength() const;
132 
135  public: virtual void FillDiscovery(msgs::Discovery &_msg) const;
136 
139  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
140 
146  public: bool operator==(const Publisher &_pub) const;
147 
153  public: bool operator!=(const Publisher &_pub) const;
154 
158  public: Publisher &operator=(const Publisher &_other);
159 
163  public: friend std::ostream &operator<<(std::ostream &_out,
164  const Publisher &_msg)
165  {
166  _out << "Publisher:" << std::endl
167  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
168  << "\tAddress: " << _msg.Addr() << std::endl
169  << "\tProcess UUID: " << _msg.PUuid() << std::endl
170  << "\tNode UUID: " << _msg.NUuid() << std::endl
171  << _msg.Options();
172 
173  return _out;
174  }
175 
179  protected: size_t IGN_DEPRECATED(8) PackInternal(char *_buffer) const;
180 
184  protected: size_t IGN_DEPRECATED(8) UnpackInternal(const char *_buffer);
185 
191  protected: size_t IGN_DEPRECATED(8) MsgLengthInternal() const;
192 
193 #ifdef _WIN32
194 // Disable warning C4251 which is triggered by
195 // std::string
196 #pragma warning(push)
197 #pragma warning(disable: 4251)
198 #endif
199  protected: std::string topic;
201 
203  protected: std::string addr;
204 
206  protected: std::string pUuid;
207 
209  protected: std::string nUuid;
210 #ifdef _WIN32
211 #pragma warning(pop)
212 #endif
213 
216  private: AdvertiseOptions opts;
217  };
218 
222  class IGNITION_TRANSPORT_VISIBLE MessagePublisher : public Publisher
223  {
225  public: MessagePublisher() = default;
226 
235  public: explicit MessagePublisher(const std::string &_topic,
236  const std::string &_addr,
237  const std::string &_ctrl,
238  const std::string &_pUuid,
239  const std::string &_nUuid,
240  const std::string &_msgTypeName,
241  const AdvertiseMessageOptions &_opts);
242 
245  public: MessagePublisher(const MessagePublisher &_other);
246 
248  public: virtual ~MessagePublisher() = default;
249 
250  // Documentation inherited.
251  public: virtual size_t IGN_DEPRECATED(8) Pack(char *_buffer) const;
252 
253  // Documentation inherited.
254  public: virtual size_t IGN_DEPRECATED(8) Unpack(const char *_buffer);
255 
256  // Documentation inherited.
257  public: virtual size_t IGN_DEPRECATED(8) MsgLength() const;
258 
263  public: std::string Ctrl() const;
264 
268  public: void SetCtrl(const std::string &_ctrl);
269 
272  public: std::string MsgTypeName() const;
273 
277  public: void SetMsgTypeName(const std::string &_msgTypeName);
278 
282  public: virtual const AdvertiseMessageOptions &Options() const;
283 
287  public: void SetOptions(const AdvertiseMessageOptions &_opts);
288 
291  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
292 
295  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
296 
300  public: friend std::ostream &operator<<(std::ostream &_out,
301  const MessagePublisher &_msg)
302  {
303  _out << "Publisher:" << std::endl
304  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
305  << "\tAddress: " << _msg.Addr() << std::endl
306  << "\tProcess UUID: " << _msg.PUuid() << std::endl
307  << "\tNode UUID: " << _msg.NUuid() << std::endl
308  << "\tControl address: " << _msg.Ctrl() << std::endl
309  << "\tMessage type: " << _msg.MsgTypeName() << std::endl
310  << _msg.Options();
311  return _out;
312  }
313 
319  public: bool operator==(const MessagePublisher &_pub) const;
320 
326  public: bool operator!=(const MessagePublisher &_pub) const;
327 
331  public: MessagePublisher &operator=(const MessagePublisher &_other);
332 
333 #ifdef _WIN32
334 // Disable warning C4251 which is triggered by
335 // std::unique_ptr
336 #pragma warning(push)
337 #pragma warning(disable: 4251)
338 #endif
339  private: std::string ctrl;
341 
343  private: std::string msgTypeName;
344 #ifdef _WIN32
345 #pragma warning(pop)
346 #endif
347 
349  private: AdvertiseMessageOptions msgOpts;
350  };
351 
355  class IGNITION_TRANSPORT_VISIBLE ServicePublisher : public Publisher
356  {
358  public: ServicePublisher() = default;
359 
369  public: ServicePublisher(const std::string &_topic,
370  const std::string &_addr,
371  const std::string &_id,
372  const std::string &_pUuid,
373  const std::string &_nUuid,
374  const std::string &_reqType,
375  const std::string &_repType,
376  const AdvertiseServiceOptions &_opts);
377 
380  public: ServicePublisher(const ServicePublisher &_other);
381 
383  public: virtual ~ServicePublisher() = default;
384 
385  // Documentation inherited.
386  public: size_t IGN_DEPRECATED(8) Pack(char *_buffer) const;
387 
388  // Documentation inherited.
389  public: size_t IGN_DEPRECATED(8) Unpack(const char *_buffer);
390 
391  // Documentation inherited.
392  public: size_t IGN_DEPRECATED(8) MsgLength() const;
393 
397  public: std::string SocketId() const;
398 
402  public: void SetSocketId(const std::string &_socketId);
403 
407  public: std::string ReqTypeName() const;
408 
412  public: std::string RepTypeName() const;
413 
417  public: void SetReqTypeName(const std::string &_reqTypeName);
418 
422  public: void SetRepTypeName(const std::string &_repTypeName);
423 
427  public: virtual const AdvertiseServiceOptions& Options() const;
428 
432  public: void SetOptions(const AdvertiseServiceOptions &_opts);
433 
436  public: virtual void FillDiscovery(msgs::Discovery &_msg) const final;
437 
441  public: virtual void SetFromDiscovery(const msgs::Discovery &_msg);
442 
446  public: friend std::ostream &operator<<(std::ostream &_out,
447  const ServicePublisher &_msg)
448  {
449  _out << "Publisher:" << std::endl
450  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
451  << "\tAddress: " << _msg.Addr() << std::endl
452  << "\tProcess UUID: " << _msg.PUuid() << std::endl
453  << "\tNode UUID: " << _msg.NUuid() << std::endl
454  << "\tSocket ID: " << _msg.SocketId() << std::endl
455  << "\tRequest type: " << _msg.ReqTypeName() << std::endl
456  << "\tResponse type: " << _msg.RepTypeName() << std::endl
457  << _msg.Options();
458 
459  return _out;
460  }
461 
467  public: bool operator==(const ServicePublisher &_srv) const;
468 
474  public: bool operator!=(const ServicePublisher &_srv) const;
475 
476 #ifdef _WIN32
477 // Disable warning C4251 which is triggered by
478 // std::string
479 #pragma warning(push)
480 #pragma warning(disable: 4251)
481 #endif
482  private: std::string socketId;
484 
486  private: std::string reqTypeName;
487 
489  private: std::string repTypeName;
490 #ifdef _WIN32
491 #pragma warning(pop)
492 #endif
493 
495  private: AdvertiseServiceOptions srvOpts;
496  };
497  }
498  }
499 }
500 
501 #endif
friend std::ostream & operator<<(std::ostream &_out, const Publisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:163
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:150
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:209
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:247
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:222
std::string pUuid
Process UUID of the publisher.
Definition: Publisher.hh:206
This class stores all the information about a service publisher.
Definition: Publisher.hh:355
friend std::ostream & operator<<(std::ostream &_out, const ServicePublisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:446
Definition: AdvertiseOptions.hh:28
std::string addr
ZeroMQ address of the publisher.
Definition: Publisher.hh:203
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:300