All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
26 
27 namespace ignition
28 {
29  namespace transport
30  {
31  class MessagePublisherPrivate;
32 
38  {
40  public: Publisher() = default;
41 
48  public: Publisher(const std::string &_topic,
49  const std::string &_addr,
50  const std::string &_pUuid,
51  const std::string &_nUuid,
52  const AdvertiseOptions &_opts);
53 
56  public: Publisher(const Publisher &_other);
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 
116  public: virtual size_t Pack(char *_buffer) const;
117 
120  public: virtual size_t Unpack(const char *_buffer);
121 
124  public: virtual size_t MsgLength() const;
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 
164  protected: size_t PackInternal(char *_buffer) const;
165 
169  protected: size_t UnpackInternal(const char *_buffer);
170 
176  protected: size_t MsgLengthInternal() const;
177 
179  protected: std::string topic;
180 
182  protected: std::string addr;
183 
185  protected: std::string pUuid;
186 
188  protected: std::string nUuid;
189 
192  private: AdvertiseOptions opts;
193  };
194 
199  {
201  public: MessagePublisher() = default;
202 
211  public: explicit MessagePublisher(const std::string &_topic,
212  const std::string &_addr,
213  const std::string &_ctrl,
214  const std::string &_pUuid,
215  const std::string &_nUuid,
216  const std::string &_msgTypeName,
217  const AdvertiseMessageOptions &_opts);
218 
221  public: MessagePublisher(const MessagePublisher &_other);
222 
224  public: virtual ~MessagePublisher() = default;
225 
226  // Documentation inherited.
227  public: virtual size_t Pack(char *_buffer) const;
228 
229  // Documentation inherited.
230  public: virtual size_t Unpack(const char *_buffer);
231 
232  // Documentation inherited.
233  public: virtual size_t MsgLength() const;
234 
239  public: std::string Ctrl() const;
240 
244  public: void SetCtrl(const std::string &_ctrl);
245 
248  public: std::string MsgTypeName() const;
249 
253  public: void SetMsgTypeName(const std::string &_msgTypeName);
254 
258  public: virtual const AdvertiseMessageOptions &Options() const;
259 
263  public: void SetOptions(const AdvertiseMessageOptions &_opts);
264 
268  public: friend std::ostream &operator<<(std::ostream &_out,
269  const MessagePublisher &_msg)
270  {
271  _out << "Publisher:" << std::endl
272  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
273  << "\tAddress: " << _msg.Addr() << std::endl
274  << "\tProcess UUID: " << _msg.PUuid() << std::endl
275  << "\tNode UUID: " << _msg.NUuid() << std::endl
276  << "\tControl address: " << _msg.Ctrl() << std::endl
277  << "\tMessage type: " << _msg.MsgTypeName() << std::endl
278  << _msg.Options();
279  return _out;
280  }
281 
287  public: bool operator==(const MessagePublisher &_pub) const;
288 
294  public: bool operator!=(const MessagePublisher &_pub) const;
295 
299  public: MessagePublisher &operator=(const MessagePublisher &_other);
300 
302  private: std::string ctrl;
303 
305  private: std::string msgTypeName;
306 
308  private: AdvertiseMessageOptions msgOpts;
309  };
310 
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 
344  // Documentation inherited.
345  public: size_t Pack(char *_buffer) const;
346 
347  // Documentation inherited.
348  public: size_t Unpack(const char *_buffer);
349 
350  // Documentation inherited.
351  public: size_t MsgLength() const;
352 
356  public: std::string SocketId() const;
357 
361  public: void SetSocketId(const std::string &_socketId);
362 
366  public: std::string ReqTypeName() const;
367 
371  public: std::string RepTypeName() const;
372 
376  public: void SetReqTypeName(const std::string &_reqTypeName);
377 
381  public: void SetRepTypeName(const std::string &_repTypeName);
382 
386  public: virtual const AdvertiseServiceOptions& Options() const;
387 
391  public: void SetOptions(const AdvertiseServiceOptions &_opts);
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 
427  private: std::string socketId;
428 
430  private: std::string reqTypeName;
431 
433  private: std::string repTypeName;
434 
436  private: AdvertiseServiceOptions srvOpts;
437  };
438  }
439 }
440 
441 #endif
friend std::ostream & operator<<(std::ostream &_out, const Publisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:148
std::string topic
Topic name.
Definition: Publisher.hh:179
A class for customizing the publication options for a topic advertised.
Definition: AdvertiseOptions.hh:136
ignition/transport/Publisher.hh
Definition: Publisher.hh:37
std::string addr
ZeroMQ address of the publisher.
Definition: Publisher.hh:182
std::string nUuid
Node UUID of the publisher.
Definition: Publisher.hh:188
virtual const AdvertiseOptions & Options() const
Get the advertised options.
std::string Topic() const
Get the topic published by this publisher.
std::string SocketId() const
Get the ZeroMQ socket ID used by this publisher.
ignition/transport/AdvertiseOptions.hh
Definition: AdvertiseOptions.hh:54
std::string PUuid() const
Get the process UUID of the publisher.
A class for customizing the publication options for a service advertised.
Definition: AdvertiseOptions.hh:224
std::string NUuid() const
Get the node UUID of the publisher.
#define IGNITION_TRANSPORT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:57
std::string MsgTypeName() const
Get the message type advertised by this publisher.
std::string Addr() const
Get the ZeroMQ address of the publisher.
ignition/transport/Publisher.hh
Definition: Publisher.hh:198
ignition/transport/Publisher.hh
Definition: Publisher.hh:314
virtual const AdvertiseServiceOptions & Options() const
Get the advertised options.
friend std::ostream & operator<<(std::ostream &_out, const ServicePublisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:396
virtual const AdvertiseMessageOptions & Options() const
Get the advertised options.
std::string RepTypeName() const
Get the name of the response's protobuf message advertised.
std::string Ctrl() const
Get the ZeroMQ control address.
std::string pUuid
Process UUID of the publisher.
Definition: Publisher.hh:185
std::string ReqTypeName() const
Get the name of the request's protobuf message advertised.
friend std::ostream & operator<<(std::ostream &_out, const MessagePublisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:268