diff --git a/include/gz/transport/AdvertiseOptions.hh b/include/gz/transport/AdvertiseOptions.hh index 76f1b4b55..fe6507bbc 100644 --- a/include/gz/transport/AdvertiseOptions.hh +++ b/include/gz/transport/AdvertiseOptions.hh @@ -25,94 +25,92 @@ #include "gz/transport/config.hh" #include "gz/transport/Export.hh" -namespace gz +namespace gz::transport { - namespace transport + // Inline bracket to help doxygen filtering. + inline namespace GZ_TRANSPORT_VERSION_NAMESPACE { + // + // Forward declarations. + class AdvertiseOptionsPrivate; + class AdvertiseMessageOptionsPrivate; + class AdvertiseServiceOptionsPrivate; + + /// \brief This strongly typed enum defines the different options for + /// the scope of a topic/service. + enum class Scope_t { - // Inline bracket to help doxygen filtering. - inline namespace GZ_TRANSPORT_VERSION_NAMESPACE { - // - // Forward declarations. - class AdvertiseOptionsPrivate; - class AdvertiseMessageOptionsPrivate; - class AdvertiseServiceOptionsPrivate; - - /// \brief This strongly typed enum defines the different options for - /// the scope of a topic/service. - enum class Scope_t - { - /// \brief Topic/service only available to subscribers in the same - /// process as the publisher. - PROCESS, - /// \brief Topic/service only available to subscribers in the same - /// machine as the publisher. - HOST, - /// \brief Topic/service available to any subscriber (default scope). - ALL - }; - - /// \class AdvertiseOptions AdvertiseOptions.hh - /// gz/transport/AdvertiseOptions.hh - /// \brief A class for customizing the publication options for a topic or - /// service advertised. - /// E.g.: Set the scope of a topic/service. - class GZ_TRANSPORT_VISIBLE AdvertiseOptions + /// \brief Topic/service only available to subscribers in the same + /// process as the publisher. + PROCESS, + /// \brief Topic/service only available to subscribers in the same + /// machine as the publisher. + HOST, + /// \brief Topic/service available to any subscriber (default scope). + ALL + }; + + /// \class AdvertiseOptions AdvertiseOptions.hh + /// gz/transport/AdvertiseOptions.hh + /// \brief A class for customizing the publication options for a topic or + /// service advertised. + /// E.g.: Set the scope of a topic/service. + class GZ_TRANSPORT_VISIBLE AdvertiseOptions + { + /// \brief Constructor. + public: AdvertiseOptions(); + + /// \brief Copy constructor. + /// \param[in] _other AdvertiseOptions to copy. + public: AdvertiseOptions(const AdvertiseOptions &_other); + + /// \brief Destructor. + public: virtual ~AdvertiseOptions(); + + /// \brief Assignment operator. + /// \param[in] _other The new AdvertiseOptions. + /// \return A reference to this instance. + public: AdvertiseOptions &operator=(const AdvertiseOptions &_other); + + /// \brief Equality operator. This function checks if the given + /// AdvertiseOptions has identical content to this object. + /// \param[in] _other The options to compare against. + /// \return True if this object matches the provided object. + public: bool operator==(const AdvertiseOptions &_other) const; + + /// \brief Inequality operator. This function checks if the given + /// options do not have identical values to this object. + /// \param[in] _other The options to compare against. + /// \return True if this object does not match the provided object. + public: bool operator!=(const AdvertiseOptions &_other) const; + + /// \brief Stream insertion operator. + /// \param[out] _out The output stream. + /// \param[in] _other AdvertiseOptions to write to the stream. + public: friend std::ostream &operator<<(std::ostream &_out, + const AdvertiseOptions &_other) { - /// \brief Constructor. - public: AdvertiseOptions(); - - /// \brief Copy constructor. - /// \param[in] _other AdvertiseOptions to copy. - public: AdvertiseOptions(const AdvertiseOptions &_other); - - /// \brief Destructor. - public: virtual ~AdvertiseOptions(); - - /// \brief Assignment operator. - /// \param[in] _other The new AdvertiseOptions. - /// \return A reference to this instance. - public: AdvertiseOptions &operator=(const AdvertiseOptions &_other); - - /// \brief Equality operator. This function checks if the given - /// AdvertiseOptions has identical content to this object. - /// \param[in] _other The options to compare against. - /// \return True if this object matches the provided object. - public: bool operator==(const AdvertiseOptions &_other) const; - - /// \brief Inequality operator. This function checks if the given - /// options do not have identical values to this object. - /// \param[in] _other The options to compare against. - /// \return True if this object does not match the provided object. - public: bool operator!=(const AdvertiseOptions &_other) const; - - /// \brief Stream insertion operator. - /// \param[out] _out The output stream. - /// \param[in] _other AdvertiseOptions to write to the stream. - public: friend std::ostream &operator<<(std::ostream &_out, - const AdvertiseOptions &_other) - { - _out << "Advertise options:\n" - << "\tScope: "; - if (_other.Scope() == Scope_t::PROCESS) - _out << "Process" << std::endl; - else if (_other.Scope() == Scope_t::HOST) - _out << "Host" << std::endl; - else - _out << "All" << std::endl; - return _out; - } + _out << "Advertise options:\n" + << "\tScope: "; + if (_other.Scope() == Scope_t::PROCESS) + _out << "Process" << std::endl; + else if (_other.Scope() == Scope_t::HOST) + _out << "Host" << std::endl; + else + _out << "All" << std::endl; + return _out; + } - /// \brief Get the scope used in this topic/service. - /// \return The scope. - /// \sa SetScope. - /// \sa Scope_t. - public: const Scope_t &Scope() const; + /// \brief Get the scope used in this topic/service. + /// \return The scope. + /// \sa SetScope. + /// \sa Scope_t. + public: const Scope_t &Scope() const; - /// \brief Set the scope of the topic or service. - /// \param[in] _scope The new scope. - /// \sa Scope. - /// \sa Scope_t. - public: void SetScope(const Scope_t &_scope); + /// \brief Set the scope of the topic or service. + /// \param[in] _scope The new scope. + /// \sa Scope. + /// \sa Scope_t. + public: void SetScope(const Scope_t &_scope); #ifdef _WIN32 // Disable warning C4251 which is triggered by @@ -120,82 +118,82 @@ namespace gz #pragma warning(push) #pragma warning(disable: 4251) #endif - /// \internal - /// \brief Smart pointer to private data. - private: std::unique_ptr dataPtr; + /// \internal + /// \brief Smart pointer to private data. + private: std::unique_ptr dataPtr; #ifdef _WIN32 #pragma warning(pop) #endif - }; + }; - /// \brief A class for customizing the publication options for a topic - /// advertised. - /// E.g.: Set the rate of messages per second published. - class GZ_TRANSPORT_VISIBLE AdvertiseMessageOptions - : public AdvertiseOptions + /// \brief A class for customizing the publication options for a topic + /// advertised. + /// E.g.: Set the rate of messages per second published. + class GZ_TRANSPORT_VISIBLE AdvertiseMessageOptions + : public AdvertiseOptions + { + /// \brief Constructor. + public: AdvertiseMessageOptions(); + + /// \brief Copy constructor. + /// \param[in] _other AdvertiseMessageOptions to copy. + public: AdvertiseMessageOptions(const AdvertiseMessageOptions &_other); + + /// \brief Destructor. + public: virtual ~AdvertiseMessageOptions(); + + /// \brief Assignment operator. + /// \param[in] _other The other AdvertiseMessageOptions. + /// \return A reference to this instance. + public: AdvertiseMessageOptions &operator=( + const AdvertiseMessageOptions &_other); + + /// \brief Equality operator. This function checks if the given + /// AdvertiseMessageOptions has identical content to this object. + /// \param[in] _other The options to compare against. + /// \return True if this object matches the provided object. + public: bool operator==(const AdvertiseMessageOptions &_other) const; + + /// \brief Inequality operator. This function checks if the given + /// options do not have identical values to this object. + /// \param[in] _other The options to compare against. + /// \return True if this object does not match the provided object. + public: bool operator!=(const AdvertiseMessageOptions &_other) const; + + /// \brief Stream insertion operator. + /// \param[out] _out The output stream. + /// \param[in] _other AdvertiseMessageOptions to write to the stream. + public: friend std::ostream &operator<<(std::ostream &_out, + const AdvertiseMessageOptions &_other) { - /// \brief Constructor. - public: AdvertiseMessageOptions(); - - /// \brief Copy constructor. - /// \param[in] _other AdvertiseMessageOptions to copy. - public: AdvertiseMessageOptions(const AdvertiseMessageOptions &_other); - - /// \brief Destructor. - public: virtual ~AdvertiseMessageOptions(); - - /// \brief Assignment operator. - /// \param[in] _other The other AdvertiseMessageOptions. - /// \return A reference to this instance. - public: AdvertiseMessageOptions &operator=( - const AdvertiseMessageOptions &_other); - - /// \brief Equality operator. This function checks if the given - /// AdvertiseMessageOptions has identical content to this object. - /// \param[in] _other The options to compare against. - /// \return True if this object matches the provided object. - public: bool operator==(const AdvertiseMessageOptions &_other) const; - - /// \brief Inequality operator. This function checks if the given - /// options do not have identical values to this object. - /// \param[in] _other The options to compare against. - /// \return True if this object does not match the provided object. - public: bool operator!=(const AdvertiseMessageOptions &_other) const; - - /// \brief Stream insertion operator. - /// \param[out] _out The output stream. - /// \param[in] _other AdvertiseMessageOptions to write to the stream. - public: friend std::ostream &operator<<(std::ostream &_out, - const AdvertiseMessageOptions &_other) + _out << static_cast(_other); + if (_other.Throttled()) { - _out << static_cast(_other); - if (_other.Throttled()) - { - _out << "\tThrottled? Yes" << std::endl; - _out << "\tRate: " << _other.MsgsPerSec() << " msgs/sec" << std::endl; - } - else - _out << "\tThrottled? No" << std::endl; - - return _out; + _out << "\tThrottled? Yes" << std::endl; + _out << "\tRate: " << _other.MsgsPerSec() << " msgs/sec" << std::endl; } + else + _out << "\tThrottled? No" << std::endl; - /// \brief Whether the publication has been throttled. - /// \return true when the publication is throttled or false otherwise. - /// \sa SetMsgsPerSec - /// \sa MsgsPerSec - public: bool Throttled() const; + return _out; + } - /// \brief Get the maximum number of messages per second to be published. - /// \return The maximum number of messages per second. - public: uint64_t MsgsPerSec() const; + /// \brief Whether the publication has been throttled. + /// \return true when the publication is throttled or false otherwise. + /// \sa SetMsgsPerSec + /// \sa MsgsPerSec + public: bool Throttled() const; - /// \brief Set the maximum number of messages per second to be published. - /// Note that we calculate the minimum period of a message based - /// on the msgs/sec rate. Any message sent since the last Publish() - /// and the duration of the period will be discarded. - /// \param[in] _newMsgsPerSec Maximum number of messages per second. - public: void SetMsgsPerSec(const uint64_t _newMsgsPerSec); + /// \brief Get the maximum number of messages per second to be published. + /// \return The maximum number of messages per second. + public: uint64_t MsgsPerSec() const; + + /// \brief Set the maximum number of messages per second to be published. + /// Note that we calculate the minimum period of a message based + /// on the msgs/sec rate. Any message sent since the last Publish() + /// and the duration of the period will be discarded. + /// \param[in] _newMsgsPerSec Maximum number of messages per second. + public: void SetMsgsPerSec(const uint64_t _newMsgsPerSec); #ifdef _WIN32 // Disable warning C4251 which is triggered by @@ -203,56 +201,56 @@ namespace gz #pragma warning(push) #pragma warning(disable: 4251) #endif - /// \internal - /// \brief Smart pointer to private data. - private: std::unique_ptr dataPtr; + /// \internal + /// \brief Smart pointer to private data. + private: std::unique_ptr dataPtr; #ifdef _WIN32 #pragma warning(pop) #endif - }; + }; - /// \brief A class for customizing the publication options for a service - /// advertised. - class GZ_TRANSPORT_VISIBLE AdvertiseServiceOptions - : public AdvertiseOptions + /// \brief A class for customizing the publication options for a service + /// advertised. + class GZ_TRANSPORT_VISIBLE AdvertiseServiceOptions + : public AdvertiseOptions + { + /// \brief Constructor. + public: AdvertiseServiceOptions(); + + /// \brief Copy constructor. + /// \param[in] _other AdvertiseServiceOptions to copy. + public: AdvertiseServiceOptions(const AdvertiseServiceOptions &_other); + + /// \brief Destructor. + public: virtual ~AdvertiseServiceOptions(); + + /// \brief Assignment operator. + /// \param[in] _other The other AdvertiseServiceOptions. + /// \return A reference to this instance. + public: AdvertiseServiceOptions &operator=( + const AdvertiseServiceOptions &_other); + + /// \brief Equality operator. This function checks if the given + /// AdvertiseMessageOptions has identical content to this object. + /// \param[in] _other The options to compare against. + /// \return True if this object matches the provided object. + public: bool operator==(const AdvertiseServiceOptions &_other) const; + + /// \brief Inequality operator. This function checks if the given + /// options do not have identical values to this object. + /// \param[in] _other The options to compare against. + /// \return True if this object does not match the provided object. + public: bool operator!=(const AdvertiseServiceOptions &_other) const; + + /// \brief Stream insertion operator. + /// \param[out] _out The output stream. + /// \param[in] _other AdvertiseServiceOptions to write to the stream. + public: friend std::ostream &operator<<(std::ostream &_out, + const AdvertiseServiceOptions &_other) { - /// \brief Constructor. - public: AdvertiseServiceOptions(); - - /// \brief Copy constructor. - /// \param[in] _other AdvertiseServiceOptions to copy. - public: AdvertiseServiceOptions(const AdvertiseServiceOptions &_other); - - /// \brief Destructor. - public: virtual ~AdvertiseServiceOptions(); - - /// \brief Assignment operator. - /// \param[in] _other The other AdvertiseServiceOptions. - /// \return A reference to this instance. - public: AdvertiseServiceOptions &operator=( - const AdvertiseServiceOptions &_other); - - /// \brief Equality operator. This function checks if the given - /// AdvertiseMessageOptions has identical content to this object. - /// \param[in] _other The options to compare against. - /// \return True if this object matches the provided object. - public: bool operator==(const AdvertiseServiceOptions &_other) const; - - /// \brief Inequality operator. This function checks if the given - /// options do not have identical values to this object. - /// \param[in] _other The options to compare against. - /// \return True if this object does not match the provided object. - public: bool operator!=(const AdvertiseServiceOptions &_other) const; - - /// \brief Stream insertion operator. - /// \param[out] _out The output stream. - /// \param[in] _other AdvertiseServiceOptions to write to the stream. - public: friend std::ostream &operator<<(std::ostream &_out, - const AdvertiseServiceOptions &_other) - { - _out << static_cast(_other); - return _out; - } + _out << static_cast(_other); + return _out; + } #ifdef _WIN32 // Disable warning C4251 which is triggered by @@ -260,14 +258,13 @@ namespace gz #pragma warning(push) #pragma warning(disable: 4251) #endif - /// \internal - /// \brief Smart pointer to private data. - private: std::unique_ptr dataPtr; + /// \internal + /// \brief Smart pointer to private data. + private: std::unique_ptr dataPtr; #ifdef _WIN32 #pragma warning(pop) #endif - }; - } + }; } } #endif diff --git a/include/gz/transport/Clock.hh b/include/gz/transport/Clock.hh index 4155ff268..650b0911b 100644 --- a/include/gz/transport/Clock.hh +++ b/include/gz/transport/Clock.hh @@ -26,103 +26,100 @@ #include "gz/transport/config.hh" #include "gz/transport/Export.hh" -namespace gz +namespace gz::transport { - namespace transport + // Inline bracket to help doxygen filtering. + inline namespace GZ_TRANSPORT_VERSION_NAMESPACE { + // + ////////////////////////////////////////////////// + /// \brief A Clock interface for time tracking + class GZ_TRANSPORT_VISIBLE Clock { - // Inline bracket to help doxygen filtering. - inline namespace GZ_TRANSPORT_VERSION_NAMESPACE { - // - ////////////////////////////////////////////////// - /// \brief A Clock interface for time tracking - class GZ_TRANSPORT_VISIBLE Clock - { - /// \brief Gets clock time - /// \return Current clock time, in nanoseconds - public: virtual std::chrono::nanoseconds Time() const = 0; - - /// \brief Checks whether the clock is ready to be used or not. - /// \return True if clock is ready to be used, false otherwise - public: virtual bool IsReady() const = 0; - - /// \brief Virtual destructor - public: virtual ~Clock() = default; - }; - - //////////////////////////////////////////////////////////////// - /// \brief A Clock interface implementation that uses - /// gz::msgs::Clock messages distributed across - /// the network - class GZ_TRANSPORT_VISIBLE NetworkClock : public Clock - { - /// \brief Network clock time bases - public: enum class TimeBase : int64_t - { - REAL, ///< Use Clock message `real` time field as time base - SIM, ///< Use Clock message `sim` time field as time base - SYS ///< Use Clock message `sys` time field as time base - }; - - /// \brief Constructor that sets the initial time range option - /// \param[in] _topicName Name of the gz::msgs::Clock type - /// topic to be used - /// \param[in] _timeBase Time base for this clock, defaults to - /// simulation time - public: explicit NetworkClock(const std::string &_topicName, - const TimeBase _timeBase = TimeBase::SIM); - - /// \brief Destructor - public: ~NetworkClock() override; - - // Documentation inherited - public: std::chrono::nanoseconds Time() const override; - - /// \brief Sets and distributes the given clock time - /// \param[in] _time The clock time to be set - /// \remarks No clock arbitration is performed - public: void SetTime(const std::chrono::nanoseconds _time); - - // Documentation inherited - public: bool IsReady() const override; - - /// \internal Implementation of this class - private: class Implementation; - - /// \internal Pointer to the implementation of this class - GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING - private: std::unique_ptr dataPtr; - GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING - }; - - ////////////////////////////////////////////////// - /// \brief A Clock implementation that leverages host OS time APIs - class GZ_TRANSPORT_VISIBLE WallClock : public Clock - { - /// \brief Returns system wall clock interface - /// \return The sole wall clock instance (a singleton) - public: static WallClock* Instance(); - - // Documentation inherited - public: std::chrono::nanoseconds Time() const override; - - // Documentation inherited - public: bool IsReady() const override; - - /// \internal Private singleton constructor - private: WallClock(); - - /// \brief Destructor - private: ~WallClock() override; - - /// \internal Implementation of this class - private: class Implementation; - - /// \internal Pointer to the implementation of this class - GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING - private: std::unique_ptr dataPtr; - GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING - }; - } + /// \brief Gets clock time + /// \return Current clock time, in nanoseconds + public: virtual std::chrono::nanoseconds Time() const = 0; + + /// \brief Checks whether the clock is ready to be used or not. + /// \return True if clock is ready to be used, false otherwise + public: virtual bool IsReady() const = 0; + + /// \brief Virtual destructor + public: virtual ~Clock() = default; + }; + + //////////////////////////////////////////////////////////////// + /// \brief A Clock interface implementation that uses + /// gz::msgs::Clock messages distributed across + /// the network + class GZ_TRANSPORT_VISIBLE NetworkClock : public Clock + { + /// \brief Network clock time bases + public: enum class TimeBase : int64_t + { + REAL, ///< Use Clock message `real` time field as time base + SIM, ///< Use Clock message `sim` time field as time base + SYS ///< Use Clock message `sys` time field as time base + }; + + /// \brief Constructor that sets the initial time range option + /// \param[in] _topicName Name of the gz::msgs::Clock type + /// topic to be used + /// \param[in] _timeBase Time base for this clock, defaults to + /// simulation time + public: explicit NetworkClock(const std::string &_topicName, + const TimeBase _timeBase = TimeBase::SIM); + + /// \brief Destructor + public: ~NetworkClock() override; + + // Documentation inherited + public: std::chrono::nanoseconds Time() const override; + + /// \brief Sets and distributes the given clock time + /// \param[in] _time The clock time to be set + /// \remarks No clock arbitration is performed + public: void SetTime(const std::chrono::nanoseconds _time); + + // Documentation inherited + public: bool IsReady() const override; + + /// \internal Implementation of this class + private: class Implementation; + + /// \internal Pointer to the implementation of this class + GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING + private: std::unique_ptr dataPtr; + GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING + }; + + ////////////////////////////////////////////////// + /// \brief A Clock implementation that leverages host OS time APIs + class GZ_TRANSPORT_VISIBLE WallClock : public Clock + { + /// \brief Returns system wall clock interface + /// \return The sole wall clock instance (a singleton) + public: static WallClock* Instance(); + + // Documentation inherited + public: std::chrono::nanoseconds Time() const override; + + // Documentation inherited + public: bool IsReady() const override; + + /// \internal Private singleton constructor + private: WallClock(); + + /// \brief Destructor + private: ~WallClock() override; + + /// \internal Implementation of this class + private: class Implementation; + + /// \internal Pointer to the implementation of this class + GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING + private: std::unique_ptr dataPtr; + GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING + }; } }