Ignition Transport

API Reference

7.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 <iostream>
22 #include <string>
23 
25 #include "ignition/transport/config.hh"
26 #include "ignition/transport/Export.hh"
27 
28 namespace ignition
29 {
30  namespace transport
31  {
32  // Inline bracket to help doxygen filtering.
33  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
34  //
35  // Forward declarations.
36  class MessagePublisherPrivate;
37 
42  class IGNITION_TRANSPORT_VISIBLE Publisher
43  {
45  public: Publisher() = default;
46 
53  public: Publisher(const std::string &_topic,
54  const std::string &_addr,
55  const std::string &_pUuid,
56  const std::string &_nUuid,
57  const AdvertiseOptions &_opts);
58 
61  public: Publisher(const Publisher &_other);
62 
64  public: virtual ~Publisher() = default;
65 
69  public: std::string Topic() const;
70 
74  public: std::string Addr() const;
75 
79  public: std::string PUuid() const;
80 
84  public: std::string NUuid() const;
85 
89  public: virtual const AdvertiseOptions &Options() const;
90 
94  public: void SetTopic(const std::string &_topic);
95 
99  public: void SetAddr(const std::string &_addr);
100 
104  public: void SetPUuid(const std::string &_pUuid);
105 
109  public: void SetNUuid(const std::string &_nUuid);
110 
114  public: void SetOptions(const AdvertiseOptions &_opts);
115 
121  public: virtual size_t Pack(char *_buffer) const;
122 
125  public: virtual size_t Unpack(const char *_buffer);
126 
129  public: virtual size_t MsgLength() const;
130 
136  public: bool operator==(const Publisher &_pub) const;
137 
143  public: bool operator!=(const Publisher &_pub) const;
144 
148  public: Publisher &operator=(const Publisher &_other);
149 
153  public: friend std::ostream &operator<<(std::ostream &_out,
154  const Publisher &_msg)
155  {
156  _out << "Publisher:" << std::endl
157  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
158  << "\tAddress: " << _msg.Addr() << std::endl
159  << "\tProcess UUID: " << _msg.PUuid() << std::endl
160  << "\tNode UUID: " << _msg.NUuid() << std::endl
161  << _msg.Options();
162 
163  return _out;
164  }
165 
169  protected: size_t PackInternal(char *_buffer) const;
170 
174  protected: size_t UnpackInternal(const char *_buffer);
175 
181  protected: size_t MsgLengthInternal() const;
182 
183 #ifdef _WIN32
184 // Disable warning C4251 which is triggered by
185 // std::string
186 #pragma warning(push)
187 #pragma warning(disable: 4251)
188 #endif
189  protected: std::string topic;
191 
193  protected: std::string addr;
194 
196  protected: std::string pUuid;
197 
199  protected: std::string nUuid;
200 #ifdef _WIN32
201 #pragma warning(pop)
202 #endif
203 
206  private: AdvertiseOptions opts;
207  };
208 
212  class IGNITION_TRANSPORT_VISIBLE MessagePublisher : public Publisher
213  {
215  public: MessagePublisher() = default;
216 
225  public: explicit MessagePublisher(const std::string &_topic,
226  const std::string &_addr,
227  const std::string &_ctrl,
228  const std::string &_pUuid,
229  const std::string &_nUuid,
230  const std::string &_msgTypeName,
231  const AdvertiseMessageOptions &_opts);
232 
235  public: MessagePublisher(const MessagePublisher &_other);
236 
238  public: virtual ~MessagePublisher() = default;
239 
240  // Documentation inherited.
241  public: virtual size_t Pack(char *_buffer) const;
242 
243  // Documentation inherited.
244  public: virtual size_t Unpack(const char *_buffer);
245 
246  // Documentation inherited.
247  public: virtual size_t MsgLength() const;
248 
253  public: std::string Ctrl() const;
254 
258  public: void SetCtrl(const std::string &_ctrl);
259 
262  public: std::string MsgTypeName() const;
263 
267  public: void SetMsgTypeName(const std::string &_msgTypeName);
268 
272  public: virtual const AdvertiseMessageOptions &Options() const;
273 
277  public: void SetOptions(const AdvertiseMessageOptions &_opts);
278 
282  public: friend std::ostream &operator<<(std::ostream &_out,
283  const MessagePublisher &_msg)
284  {
285  _out << "Publisher:" << std::endl
286  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
287  << "\tAddress: " << _msg.Addr() << std::endl
288  << "\tProcess UUID: " << _msg.PUuid() << std::endl
289  << "\tNode UUID: " << _msg.NUuid() << std::endl
290  << "\tControl address: " << _msg.Ctrl() << std::endl
291  << "\tMessage type: " << _msg.MsgTypeName() << std::endl
292  << _msg.Options();
293  return _out;
294  }
295 
301  public: bool operator==(const MessagePublisher &_pub) const;
302 
308  public: bool operator!=(const MessagePublisher &_pub) const;
309 
313  public: MessagePublisher &operator=(const MessagePublisher &_other);
314 
315 #ifdef _WIN32
316 // Disable warning C4251 which is triggered by
317 // std::unique_ptr
318 #pragma warning(push)
319 #pragma warning(disable: 4251)
320 #endif
321  private: std::string ctrl;
323 
325  private: std::string msgTypeName;
326 #ifdef _WIN32
327 #pragma warning(pop)
328 #endif
329 
331  private: AdvertiseMessageOptions msgOpts;
332  };
333 
337  class IGNITION_TRANSPORT_VISIBLE ServicePublisher : public Publisher
338  {
340  public: ServicePublisher() = default;
341 
351  public: ServicePublisher(const std::string &_topic,
352  const std::string &_addr,
353  const std::string &_id,
354  const std::string &_pUuid,
355  const std::string &_nUuid,
356  const std::string &_reqType,
357  const std::string &_repType,
358  const AdvertiseServiceOptions &_opts);
359 
362  public: ServicePublisher(const ServicePublisher &_other);
363 
365  public: virtual ~ServicePublisher() = default;
366 
367  // Documentation inherited.
368  public: size_t Pack(char *_buffer) const;
369 
370  // Documentation inherited.
371  public: size_t Unpack(const char *_buffer);
372 
373  // Documentation inherited.
374  public: size_t MsgLength() const;
375 
379  public: std::string SocketId() const;
380 
384  public: void SetSocketId(const std::string &_socketId);
385 
389  public: std::string ReqTypeName() const;
390 
394  public: std::string RepTypeName() const;
395 
399  public: void SetReqTypeName(const std::string &_reqTypeName);
400 
404  public: void SetRepTypeName(const std::string &_repTypeName);
405 
409  public: virtual const AdvertiseServiceOptions& Options() const;
410 
414  public: void SetOptions(const AdvertiseServiceOptions &_opts);
415 
419  public: friend std::ostream &operator<<(std::ostream &_out,
420  const ServicePublisher &_msg)
421  {
422  _out << "Publisher:" << std::endl
423  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
424  << "\tAddress: " << _msg.Addr() << std::endl
425  << "\tProcess UUID: " << _msg.PUuid() << std::endl
426  << "\tNode UUID: " << _msg.NUuid() << std::endl
427  << "\tSocket ID: " << _msg.SocketId() << std::endl
428  << "\tRequest type: " << _msg.ReqTypeName() << std::endl
429  << "\tResponse type: " << _msg.RepTypeName() << std::endl
430  << _msg.Options();
431 
432  return _out;
433  }
434 
440  public: bool operator==(const ServicePublisher &_srv) const;
441 
447  public: bool operator!=(const ServicePublisher &_srv) const;
448 
449 #ifdef _WIN32
450 // Disable warning C4251 which is triggered by
451 // std::string
452 #pragma warning(push)
453 #pragma warning(disable: 4251)
454 #endif
455  private: std::string socketId;
457 
459  private: std::string reqTypeName;
460 
462  private: std::string repTypeName;
463 #ifdef _WIN32
464 #pragma warning(pop)
465 #endif
466 
468  private: AdvertiseServiceOptions srvOpts;
469  };
470  }
471  }
472 }
473 
474 #endif
friend std::ostream & operator<<(std::ostream &_out, const Publisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:153
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:42
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:199
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:212
std::string pUuid
Process UUID of the publisher.
Definition: Publisher.hh:196
This class stores all the information about a service publisher.
Definition: Publisher.hh:337
friend std::ostream & operator<<(std::ostream &_out, const ServicePublisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:419
Definition: AdvertiseOptions.hh:28
std::string addr
ZeroMQ address of the publisher.
Definition: Publisher.hh:193
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:282