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_MESSAGEPUBLISHER_HH_INCLUDED__
19 #define __IGN_TRANSPORT_MESSAGEPUBLISHER_HH_INCLUDED__
20 
21 #include <iostream>
22 #include <string>
23 
26 
27 namespace ignition
28 {
29  namespace transport
30  {
36  {
38  public: Publisher() = default;
39 
46  public: Publisher(const std::string &_topic,
47  const std::string &_addr,
48  const std::string &_pUuid,
49  const std::string &_nUuid,
50  const Scope_t &_scope);
51 
53  public: virtual ~Publisher() = default;
54 
58  public: std::string Topic() const;
59 
63  public: std::string Addr() const;
64 
68  public: std::string PUuid() const;
69 
73  public: std::string NUuid() const;
74 
78  public: Scope_t Scope() const;
79 
83  public: void SetTopic(const std::string &_topic);
84 
88  public: void SetAddr(const std::string &_addr);
89 
93  public: void SetPUuid(const std::string &_pUuid);
94 
98  public: void SetNUuid(const std::string &_nUuid);
99 
103  public: void SetScope(const Scope_t &_scope);
104 
110  public: size_t Pack(char *_buffer) const;
111 
114  public: size_t Unpack(char *_buffer);
115 
118  public: size_t MsgLength() const;
119 
125  public: bool operator==(const Publisher &_pub) const;
126 
132  public: bool operator!=(const Publisher &_srv) const;
133 
137  public: friend std::ostream &operator<<(std::ostream &_out,
138  const Publisher &_msg)
139  {
140  _out << "Publisher:" << std::endl
141  << "\tTopic: [" << _msg.Topic() << "]" << std::endl
142  << "\tAddress: " << _msg.Addr() << std::endl
143  << "\tProcess UUID: " << _msg.PUuid() << std::endl
144  << "\tNode UUID: " << _msg.NUuid() << std::endl
145  << "\tTopic Scope: ";
146  if (_msg.Scope() == Scope_t::PROCESS)
147  _out << "Process" << std::endl;
148  else if (_msg.Scope() == Scope_t::HOST)
149  _out << "Host" << std::endl;
150  else
151  _out << "All" << std::endl;
152 
153  return _out;
154  }
155 
157  protected: std::string topic;
158 
160  protected: std::string addr;
161 
163  protected: std::string pUuid;
164 
166  protected: std::string nUuid;
167 
169  protected: Scope_t scope = Scope_t::ALL;
170  };
171 
176  {
178  public: MessagePublisher() = default;
179 
188  public: MessagePublisher(const std::string &_topic,
189  const std::string &_addr,
190  const std::string &_ctrl,
191  const std::string &_pUuid,
192  const std::string &_nUuid,
193  const Scope_t &_scope,
194  const std::string &_msgTypeName);
195 
197  public: virtual ~MessagePublisher() = default;
198 
199  // Documentation inherited.
200  public: size_t Pack(char *_buffer) const;
201 
202  // Documentation inherited.
203  public: size_t Unpack(char *_buffer);
204 
205  // Documentation inherited.
206  public: size_t MsgLength() const;
207 
212  public: std::string Ctrl() const;
213 
217  public: void SetCtrl(const std::string &_ctrl);
218 
221  public: std::string MsgTypeName() const;
222 
226  public: void SetMsgTypeName(const std::string &_msgTypeName);
227 
231  public: friend std::ostream &operator<<(std::ostream &_out,
232  const MessagePublisher &_msg)
233  {
234  _out << static_cast<Publisher>(_msg)
235  << "\tControl address: " << _msg.Ctrl() << std::endl
236  << "\tMessage type: " << _msg.MsgTypeName() << std::endl;
237  return _out;
238  }
239 
245  public: bool operator==(const MessagePublisher &_pub) const;
246 
252  public: bool operator!=(const MessagePublisher &_pub) const;
253 
255  protected: std::string ctrl;
256 
258  protected: std::string msgTypeName;
259  };
260 
265  {
267  public: ServicePublisher() = default;
268 
278  public: ServicePublisher(const std::string &_topic,
279  const std::string &_addr,
280  const std::string &_id,
281  const std::string &_pUuid,
282  const std::string &_nUuid,
283  const Scope_t &_scope,
284  const std::string &_reqType,
285  const std::string &_repType);
286 
288  public: virtual ~ServicePublisher() = default;
289 
290  // Documentation inherited.
291  public: size_t Pack(char *_buffer) const;
292 
293  // Documentation inherited.
294  public: size_t Unpack(char *_buffer);
295 
296  // Documentation inherited.
297  public: size_t MsgLength() const;
298 
302  public: std::string SocketId() const;
303 
307  public: void SetSocketId(const std::string &_socketId);
308 
312  public: std::string ReqTypeName() const;
313 
317  public: std::string RepTypeName() const;
318 
322  public: void SetReqTypeName(const std::string &_reqTypeName);
323 
327  public: void SetRepTypeName(const std::string &_repTypeName);
328 
332  public: friend std::ostream &operator<<(std::ostream &_out,
333  const ServicePublisher &_msg)
334  {
335  _out << static_cast<Publisher>(_msg)
336  << "\tSocket ID: " << _msg.SocketId() << std::endl
337  << "\tRequest type: " << _msg.ReqTypeName() << std::endl
338  << "\tResponse type: " << _msg.RepTypeName() << std::endl;
339 
340  return _out;
341  }
342 
348  public: bool operator==(const ServicePublisher &_srv) const;
349 
355  public: bool operator!=(const ServicePublisher &_srv) const;
356 
358  protected: std::string socketId;
359 
361  private: std::string reqTypeName;
362 
364  private: std::string repTypeName;
365  };
366  }
367 }
368 
369 #endif
friend std::ostream & operator<<(std::ostream &_out, const Publisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:137
std::string ctrl
ZeroMQ control address of the publisher.
Definition: Publisher.hh:255
Topic/service available to any subscriber (default scope).
std::string topic
Topic name.
Definition: Publisher.hh:157
std::string RepTypeName() const
Get the name of the response&#39;s protobuf message advertised.
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:56
std::string Ctrl() const
Get the ZeroMQ control address.
ignition/transport/Publisher.hh
Definition: Publisher.hh:35
std::string addr
ZeroMQ address of the publisher.
Definition: Publisher.hh:160
std::string PUuid() const
Get the process UUID of the publisher.
std::string nUuid
Node UUID of the publisher.
Definition: Publisher.hh:166
std::string MsgTypeName() const
Get the message type advertised by this publisher.
Topic/service only available to subscribers in the same process as the publisher. ...
std::string msgTypeName
Message type advertised by this publisher.
Definition: Publisher.hh:258
std::string NUuid() const
Get the node UUID of the publisher.
ignition/transport/Publisher.hh
Definition: Publisher.hh:175
std::string ReqTypeName() const
Get the name of the request&#39;s protobuf message advertised.
ignition/transport/Publisher.hh
Definition: Publisher.hh:264
friend std::ostream & operator<<(std::ostream &_out, const ServicePublisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:332
Scope_t
Definition: AdvertiseOptions.hh:33
std::string SocketId() const
Get the ZeroMQ socket ID used by this publisher.
Scope_t Scope() const
Get the scope of the publisher&#39;s topic.
std::string Addr() const
Get the ZeroMQ address of the publisher.
Definition: AdvertiseOptions.hh:25
std::string pUuid
Process UUID of the publisher.
Definition: Publisher.hh:163
Topic/service only available to subscribers in the same machine as the publisher. ...
std::string socketId
ZeroMQ socket ID used by this publisher.
Definition: Publisher.hh:358
friend std::ostream & operator<<(std::ostream &_out, const MessagePublisher &_msg)
Stream insertion operator.
Definition: Publisher.hh:231
std::string Topic() const
Get the topic published by this publisher.