RTC Toolkit  2.0.0
alertServiceIf.hpp
Go to the documentation of this file.
1 
11 #ifndef RTCTK_COMPONENTFRAMEWORK_ALERTSERVICEIF_HPP
12 #define RTCTK_COMPONENTFRAMEWORK_ALERTSERVICEIF_HPP
13 #include <iosfwd>
14 #include <string>
15 #include <sys/types.h>
16 
17 #include <boost/signals2/signal.hpp>
18 
20 
21 namespace rtctk::componentFramework {
22 
29 };
30 
42 class AlertSource {
43 public:
44  AlertSource();
45 
49  ~AlertSource() noexcept;
50 
56  AlertSource(AlertSource&& other) noexcept;
57 
63  AlertSource& operator=(AlertSource&& other) noexcept;
64 
68  using TimePoint = std::chrono::system_clock::time_point;
69 
77  void Reset() {
78  Set(false);
79  }
80 
90  void Set(bool state = true);
91 
97  bool IsSet() const noexcept {
98  return m_state;
99  }
100 
106  std::pair<bool, TimePoint> GetStatus() const noexcept {
107  return {m_state, m_since};
108  }
109 
117  using Signal = boost::signals2::signal<void(bool, TimePoint)>;
118 
125  boost::signals2::connection Connect(Signal::slot_type const& slot);
126 
127 private:
128  bool m_state;
129  TimePoint m_since;
130  Signal m_signal;
131 };
132 
146 public:
152  explicit AlertDescription(std::string id, std::string description) noexcept;
153 
157  std::string const& GetId() const noexcept {
158  return m_id;
159  }
160 
164  std::string const& GetDescription() const noexcept {
165  return m_description;
166  }
167 
168 private:
169  std::string m_id;
170  std::string m_description;
171 };
172 
180 public:
181  virtual ~AlertSourceFactoryIf() noexcept = default;
192  [[nodiscard]] virtual AlertSource MakeAlertSource(AlertDescription const& description) = 0;
193 };
194 
199 public:
200  virtual ~AlertStatusObserverIf() noexcept = default;
201 
209  using ReducedStatus = std::optional<bool>;
210 
214  using TimePoint = std::chrono::system_clock::time_point;
215 
219  struct AlertStatus {
223  bool status;
224 
229 
234  };
235 
239 
252  using ReducedStatusSignal = boost::signals2::signal<void(
253  ReducedStatus const&, std::vector<AlertStatus> const&)>;
254 
263  virtual boost::signals2::connection
264  ConnectReducedStatus(ReducedStatusSignal::slot_type slot) = 0;
266 
270 
274  [[nodiscard]] virtual ReducedStatus GetReducedStatus() const = 0;
275 
282  [[nodiscard]] virtual std::vector<AlertStatus> GetAlertStatuses() const = 0;
284 };
285 
304 public:
305  virtual ~AlertServiceIf() noexcept = default;
306 };
307 
308 std::ostream& operator<<(std::ostream& os, AlertServiceIf::AlertStatus const& status);
309 
310 } // namespace rtctk::componentFramework
311 
312 #endif // RTCTK_COMPONENTFRAMEWORK_ALERTSERVICEIF_HPP
exceptions.hpp
Provides macros and utilities for exception handling.
rtctk::componentFramework::AlertSource::IsSet
bool IsSet() const noexcept
Query alert status.
Definition: alertServiceIf.hpp:97
rtctk::componentFramework::AlertDescription::GetId
std::string const & GetId() const noexcept
Definition: alertServiceIf.hpp:157
rtctk::componentFramework::RtctkException::RtctkException
RtctkException() noexcept
Definition: exceptions.cpp:99
rtctk::componentFramework::AlertStatusObserverIf::TimePoint
std::chrono::system_clock::time_point TimePoint
Timestamp type used throughout AlertServiceIf.
Definition: alertServiceIf.hpp:214
rtctk::componentFramework::AlertSource
Models a single alert source that can be set or cleared.
Definition: alertServiceIf.hpp:42
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::AlertStatusObserverIf::~AlertStatusObserverIf
virtual ~AlertStatusObserverIf() noexcept=default
rtctk::componentFramework::AlertSourceFactoryIf
Interface to create AlertSource.
Definition: alertServiceIf.hpp:179
rtctk::componentFramework::RtctkException
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:207
rtctk::componentFramework::AlertSource::Signal
boost::signals2::signal< void(bool, TimePoint)> Signal
Signal type emitted on rising and falling alert status flanks.
Definition: alertServiceIf.hpp:117
rtctk::componentFramework::AlertStatusObserverIf::ConnectReducedStatus
virtual boost::signals2::connection ConnectReducedStatus(ReducedStatusSignal::slot_type slot)=0
Connects a slot to the reduced alert signal.
rtctk::componentFramework::AlertSourceFactoryIf::~AlertSourceFactoryIf
virtual ~AlertSourceFactoryIf() noexcept=default
rtctk::componentFramework::AlertStatusObserverIf::AlertStatus::since
TimePoint since
Time point when status was first set.
Definition: alertServiceIf.hpp:228
rtctk::componentFramework::AlertStatusObserverIf
Interface to observe alert status.
Definition: alertServiceIf.hpp:198
rtctk::componentFramework::AlertSource::TimePoint
std::chrono::system_clock::time_point TimePoint
Timestamp type.
Definition: alertServiceIf.hpp:68
rtctk::componentFramework::AlertStatusObserverIf::ReducedStatusSignal
boost::signals2::signal< void(ReducedStatus const &, std::vector< AlertStatus > const &)> ReducedStatusSignal
Signal emitted for every change in reduced alert status.
Definition: alertServiceIf.hpp:253
rtctk::componentFramework::AlertSource::GetStatus
std::pair< bool, TimePoint > GetStatus() const noexcept
Get current status with timestamp of the time the state was last changed.
Definition: alertServiceIf.hpp:106
rtctk::componentFramework::AlertStatusObserverIf::GetAlertStatuses
virtual std::vector< AlertStatus > GetAlertStatuses() const =0
Get status of all alert conditions.
rtctk::componentFramework::AlertDescription
Uniquely describes an alert.
Definition: alertServiceIf.hpp:145
rtctk::componentFramework::AlertSource::operator=
AlertSource & operator=(AlertSource &&other) noexcept
Move assigns from other to this object.
Definition: alertServiceIf.cpp:23
rtctk::componentFramework::AlertServiceIf
Alert Service interface.
Definition: alertServiceIf.hpp:303
rtctk::componentFramework::AlertStatusObserverIf::AlertStatus
Structure describing an alert condition with status from the corresponding AlertSource.
Definition: alertServiceIf.hpp:219
rtctk_ctrl_mon_tool.state
def state(ctx, str component)
Definition: rtctk_ctrl_mon_tool.py:158
rtctk::componentFramework::AlertSource::Reset
void Reset()
Clear alert.
Definition: alertServiceIf.hpp:77
rtctk::componentFramework::AlertConflictException
Exception indicating that a metric such as counter or thread conflicts with already known metrics.
Definition: alertServiceIf.hpp:27
rtctk::componentFramework::AlertStatusObserverIf::AlertStatus::status
bool status
Status of an alert.
Definition: alertServiceIf.hpp:223
std
Definition: mudpiProcessingError.hpp:119
rtctk::componentFramework::AlertSourceFactoryIf::MakeAlertSource
virtual AlertSource MakeAlertSource(AlertDescription const &description)=0
Creates a new alert source for the specified alert condition.
rtctk::componentFramework::AlertSource::Connect
boost::signals2::connection Connect(Signal::slot_type const &slot)
Connect slot to signal.
Definition: alertServiceIf.cpp:51
rtctk::componentFramework::AlertSource::~AlertSource
~AlertSource() noexcept
Resets alert.
Definition: alertServiceIf.cpp:32
rtctk::componentFramework::AlertServiceIf::~AlertServiceIf
virtual ~AlertServiceIf() noexcept=default
rtctk::componentFramework::AlertSource::AlertSource
AlertSource()
Definition: alertServiceIf.cpp:15
rtctk::componentFramework::AlertStatusObserverIf::AlertStatus::description
AlertDescription description
Information describing the alert.
Definition: alertServiceIf.hpp:233
rtctk::componentFramework::AlertSource::Set
void Set(bool state=true)
Set alert status state.
Definition: alertServiceIf.cpp:42
rtctk::componentFramework::AlertDescription::GetDescription
std::string const & GetDescription() const noexcept
Definition: alertServiceIf.hpp:164
rtctk::componentFramework::AlertDescription::AlertDescription
AlertDescription(std::string id, std::string description) noexcept
Construct instance.
Definition: alertServiceIf.cpp:55
rtctk_config_tool.default
default
Enter an interactive shell.
Definition: rtctk_config_tool.py:119
rtctk::componentFramework::AlertStatusObserverIf::GetReducedStatus
virtual ReducedStatus GetReducedStatus() const =0
Get the reduced status.
rtctk::componentFramework::AlertStatusObserverIf::ReducedStatus
std::optional< bool > ReducedStatus
Represents current alert status.
Definition: alertServiceIf.hpp:209