Gazebo Transport

API Reference

8.5.0
gz/transport/AdvertiseOptions.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 GZ_TRANSPORT_ADVERTISEOPTIONS_HH_
19 #define GZ_TRANSPORT_ADVERTISEOPTIONS_HH_
20 
21 #include <cstdint>
22 #include <iostream>
23 #include <memory>
24 
25 #include "gz/transport/config.hh"
26 #include "gz/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 AdvertiseOptionsPrivate;
37  class AdvertiseMessageOptionsPrivate;
38  class AdvertiseServiceOptionsPrivate;
39 
42  enum class Scope_t
43  {
46  PROCESS,
49  HOST,
51  ALL
52  };
53 
59  class IGNITION_TRANSPORT_VISIBLE AdvertiseOptions
60  {
62  public: AdvertiseOptions();
63 
66  public: AdvertiseOptions(const AdvertiseOptions &_other);
67 
69  public: virtual ~AdvertiseOptions();
70 
74  public: AdvertiseOptions &operator=(const AdvertiseOptions &_other);
75 
80  public: bool operator==(const AdvertiseOptions &_other) const;
81 
86  public: bool operator!=(const AdvertiseOptions &_other) const;
87 
91  public: friend std::ostream &operator<<(std::ostream &_out,
92  const AdvertiseOptions &_other)
93  {
94  _out << "Advertise options:\n"
95  << "\tScope: ";
96  if (_other.Scope() == Scope_t::PROCESS)
97  _out << "Process" << std::endl;
98  else if (_other.Scope() == Scope_t::HOST)
99  _out << "Host" << std::endl;
100  else
101  _out << "All" << std::endl;
102  return _out;
103  }
104 
109  public: const Scope_t &Scope() const;
110 
115  public: void SetScope(const Scope_t &_scope);
116 
122  public: size_t IGN_DEPRECATED(8) Pack(char *_buffer) const;
123 
127  public: size_t IGN_DEPRECATED(8) Unpack(const char *_buffer);
128 
131  public: size_t IGN_DEPRECATED(8) MsgLength() const;
132 
133 #ifdef _WIN32
134 // Disable warning C4251 which is triggered by
135 // std::unique_ptr
136 #pragma warning(push)
137 #pragma warning(disable: 4251)
138 #endif
142 #ifdef _WIN32
143 #pragma warning(pop)
144 #endif
145  };
146 
150  class IGNITION_TRANSPORT_VISIBLE AdvertiseMessageOptions
151  : public AdvertiseOptions
152  {
154  public: AdvertiseMessageOptions();
155 
158  public: AdvertiseMessageOptions(const AdvertiseMessageOptions &_other);
159 
161  public: virtual ~AdvertiseMessageOptions();
162 
166  public: AdvertiseMessageOptions &operator=(
167  const AdvertiseMessageOptions &_other);
168 
173  public: bool operator==(const AdvertiseMessageOptions &_other) const;
174 
179  public: bool operator!=(const AdvertiseMessageOptions &_other) const;
180 
184  public: friend std::ostream &operator<<(std::ostream &_out,
185  const AdvertiseMessageOptions &_other)
186  {
187  _out << static_cast<AdvertiseOptions>(_other);
188  if (_other.Throttled())
189  {
190  _out << "\tThrottled? Yes" << std::endl;
191  _out << "\tRate: " << _other.MsgsPerSec() << " msgs/sec" << std::endl;
192  }
193  else
194  _out << "\tThrottled? No" << std::endl;
195 
196  return _out;
197  }
198 
203  public: bool Throttled() const;
204 
207  public: uint64_t MsgsPerSec() const;
208 
214  public: void SetMsgsPerSec(const uint64_t _newMsgsPerSec);
215 
221  public: size_t IGN_DEPRECATED(8) Pack(char *_buffer) const;
222 
225  public: size_t IGN_DEPRECATED(8) Unpack(const char *_buffer);
226 
229  public: size_t IGN_DEPRECATED(8) MsgLength() const;
230 
231 #ifdef _WIN32
232 // Disable warning C4251 which is triggered by
233 // std::unique_ptr
234 #pragma warning(push)
235 #pragma warning(disable: 4251)
236 #endif
240 #ifdef _WIN32
241 #pragma warning(pop)
242 #endif
243  };
244 
247  class IGNITION_TRANSPORT_VISIBLE AdvertiseServiceOptions
248  : public AdvertiseOptions
249  {
251  public: AdvertiseServiceOptions();
252 
255  public: AdvertiseServiceOptions(const AdvertiseServiceOptions &_other);
256 
258  public: virtual ~AdvertiseServiceOptions();
259 
263  public: AdvertiseServiceOptions &operator=(
264  const AdvertiseServiceOptions &_other);
265 
270  public: bool operator==(const AdvertiseServiceOptions &_other) const;
271 
276  public: bool operator!=(const AdvertiseServiceOptions &_other) const;
277 
281  public: friend std::ostream &operator<<(std::ostream &_out,
282  const AdvertiseServiceOptions &_other)
283  {
284  _out << static_cast<AdvertiseOptions>(_other);
285  return _out;
286  }
287 
293  public: size_t IGN_DEPRECATED(8) Pack(char *_buffer) const;
294 
297  public: size_t IGN_DEPRECATED(8) Unpack(const char *_buffer);
298 
301  public: size_t IGN_DEPRECATED(8) MsgLength() const;
302 
303 #ifdef _WIN32
304 // Disable warning C4251 which is triggered by
305 // std::unique_ptr
306 #pragma warning(push)
307 #pragma warning(disable: 4251)
308 #endif
312 #ifdef _WIN32
313 #pragma warning(pop)
314 #endif
315  };
316  }
317  }
318 }
319 #endif
size_t MsgLength() const
Get the total length of the message.
bool operator==(const AdvertiseServiceOptions &_other) const
Equality operator. This function checks if the given AdvertiseMessageOptions has identical content to...
void SetMsgsPerSec(const uint64_t _newMsgsPerSec)
Set the maximum number of messages per second to be published. Note that we calculate the minimum per...
bool operator!=(const AdvertiseOptions &_other) const
Inequality operator. This function checks if the given options do not have identical values to this o...
@ HOST
Topic/service only available to subscribers in the same machine as the publisher.
Definition: gz/transport/AdvertiseOptions.hh:28
bool operator!=(const AdvertiseMessageOptions &_other) const
Inequality operator. This function checks if the given options do not have identical values to this o...
friend std::ostream & operator<<(std::ostream &_out, const AdvertiseMessageOptions &_other)
Stream insertion operator.
Definition: gz/transport/AdvertiseOptions.hh:184
bool Throttled() const
Whether the publication has been throttled.
@ ALL
Topic/service available to any subscriber (default scope).
friend std::ostream & operator<<(std::ostream &_out, const AdvertiseOptions &_other)
Stream insertion operator.
Definition: gz/transport/AdvertiseOptions.hh:91
void SetScope(const Scope_t &_scope)
Set the scope of the topic or service.
A class for customizing the publication options for a topic or service advertised....
Definition: gz/transport/AdvertiseOptions.hh:59
size_t Unpack(const char *_buffer)
Unserialize the options.
size_t Pack(char *_buffer) const
Serialize the options. The caller has ownership of the buffer and is responsible for its [de]allocati...
const Scope_t & Scope() const
Get the scope used in this topic/service.
A class for customizing the publication options for a topic advertised. E.g.: Set the rate of message...
Definition: gz/transport/AdvertiseOptions.hh:150
AdvertiseMessageOptions & operator=(const AdvertiseMessageOptions &_other)
Assignment operator.
size_t Pack(char *_buffer) const
Serialize the options. The caller has ownership of the buffer and is responsible for its [de]allocati...
STL class.
bool operator!=(const AdvertiseServiceOptions &_other) const
Inequality operator. This function checks if the given options do not have identical values to this o...
size_t Unpack(const char *_buffer)
Deserialize and set the options. The input buffer is unpacked and used to set this object's options.
friend std::ostream & operator<<(std::ostream &_out, const AdvertiseServiceOptions &_other)
Stream insertion operator.
Definition: gz/transport/AdvertiseOptions.hh:281
AdvertiseServiceOptions & operator=(const AdvertiseServiceOptions &_other)
Assignment operator.
uint64_t MsgsPerSec() const
Get the maximum number of messages per second to be published.
virtual ~AdvertiseOptions()
Destructor.
size_t Pack(char *_buffer) const
Serialize the options. The caller has ownership of the buffer and is responsible for its [de]allocati...
Scope_t
This strongly typed enum defines the different options for the scope of a topic/service.
Definition: gz/transport/AdvertiseOptions.hh:42
size_t MsgLength() const
Get the total length of the message.
T endl(T... args)
bool operator==(const AdvertiseMessageOptions &_other) const
Equality operator. This function checks if the given AdvertiseMessageOptions has identical content to...
A class for customizing the publication options for a service advertised.
Definition: gz/transport/AdvertiseOptions.hh:247
AdvertiseOptions & operator=(const AdvertiseOptions &_other)
Assignment operator.
size_t MsgLength() const
Get the total length of the message.
@ PROCESS
Topic/service only available to subscribers in the same process as the publisher.
bool operator==(const AdvertiseOptions &_other) const
Equality operator. This function checks if the given AdvertiseOptions has identical content to this o...
size_t Unpack(const char *_buffer)
Unserialize the options.