RTC Toolkit  2.0.0
alertService.hpp
Go to the documentation of this file.
1 
11 #ifndef RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
12 #define RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
13 
14 #include <log4cplus/logger.h>
15 
19 
20 namespace rtctk::componentFramework {
21 
25 class AlertService : public AlertServiceIf {
26 public:
31  explicit AlertService(log4cplus::Logger logger);
35  ~AlertService() noexcept;
36 
37  boost::signals2::connection ConnectReducedStatus(ReducedStatusSignal::slot_type slot) override;
38 
39  [[nodiscard]] AlertSource MakeAlertSource(AlertDescription const& description) override;
40 
41  [[nodiscard]] ReducedStatus GetReducedStatus() const override;
42  [[nodiscard]] std::vector<AlertStatus> GetAlertStatuses() const override;
43 
44 private:
50  struct Shadow {
51  AlertStatus status;
52  boost::signals2::connection connection;
53  };
54 
60  void UpdateAlertStatus(std::string const& id, bool status, AlertSource::TimePoint since);
61 
62  void CollectGarbage();
63 
67  mutable std::recursive_mutex m_api_mtx;
68 
72  std::vector<Shadow> m_shadow = {};
73  ReducedStatus m_reduced = false;
74  ReducedStatusSignal m_reduced_signal;
75 
76  log4cplus::Logger m_logger;
77 };
78 
84 class AlertLogger {
85 public:
86  AlertLogger(log4cplus::Logger logger, AlertServiceIf& service);
87 
88 private:
89  void Slot(AlertServiceIf::ReducedStatus const& status,
90  std::vector<AlertServiceIf::AlertStatus> const& active);
91  log4cplus::Logger m_logger;
92  boost::signals2::scoped_connection m_connection;
93 };
94 
101 public:
110  AlertEventPublisher(std::string name,
111  AlertStatusObserverIf& alert_service,
112  EventServiceIf& event_service,
113  log4cplus::Logger logger);
114 
115 private:
119  void Slot(AlertServiceIf::ReducedStatus const& status,
120  std::vector<AlertStatusObserverIf::AlertStatus> const& active);
121 
122  std::string m_name;
123  TypedEventService m_event_service;
124  log4cplus::Logger m_logger;
125  boost::signals2::scoped_connection m_connection;
126 
127  std::unique_ptr<TypedEventPublisher<AlertStatusEvent>> m_publisher;
128 };
129 
130 } // namespace rtctk::componentFramework
131 
132 #endif // RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
wscript.name
name
Definition: wscript:15
rtctk::componentFramework::TypedEventService
A high-level event service API that is aware of event types.
Definition: typedEventService.hpp:245
rtctk::componentFramework::AlertSource
Models a single alert source that can be set or cleared.
Definition: alertServiceIf.hpp:42
rtctk::componentFramework
Definition: commandReplier.cpp:20
typedEventService.hpp
High-level API of the event service.
rtctk::componentFramework::AlertStatusObserverIf
Interface to observe alert status.
Definition: alertServiceIf.hpp:198
alertServiceIf.hpp
Header file for AlertServiceIf and related classes.
rtctk::componentFramework::AlertEventPublisher
Alert observer that publishes alerts to event service using the typed event AlertStatusEvent.
Definition: alertService.hpp:100
rtctk::componentFramework::AlertSource::TimePoint
std::chrono::system_clock::time_point TimePoint
Timestamp type.
Definition: alertServiceIf.hpp:68
rtctk::componentFramework::AlertEventPublisher::AlertEventPublisher
AlertEventPublisher(std::string name, AlertStatusObserverIf &alert_service, EventServiceIf &event_service, log4cplus::Logger logger)
Constructor.
Definition: alertService.cpp:157
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
eventDefinitions.hpp
Framework-provided event definitions.
rtctk::componentFramework::AlertLogger
Simple alert observer that writes alerts to log.
Definition: alertService.hpp:84
rtctk::componentFramework::AlertService::AlertService
AlertService(log4cplus::Logger logger)
Definition: alertService.cpp:28
rtctk::componentFramework::AlertDescription
Uniquely describes an alert.
Definition: alertServiceIf.hpp:145
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::componentFramework::AlertService::GetReducedStatus
ReducedStatus GetReducedStatus() const override
Get the reduced status.
Definition: alertService.cpp:34
rtctk::componentFramework::EventServiceIf
Interface class for providing pub/sub facilities for JSON events.
Definition: eventServiceIf.hpp:26
rtctk::componentFramework::AlertService::ConnectReducedStatus
boost::signals2::connection ConnectReducedStatus(ReducedStatusSignal::slot_type slot) override
Connects a slot to the reduced alert signal.
Definition: alertService.cpp:53
rtctk::componentFramework::AlertService
Implementation of AlertIf.
Definition: alertService.hpp:25
rtctk::componentFramework::AlertService::GetAlertStatuses
std::vector< AlertStatus > GetAlertStatuses() const override
Get status of all alert conditions.
Definition: alertService.cpp:39
rtctk::componentFramework::AlertService::~AlertService
~AlertService() noexcept
Destructor will automatically stop notifier.
Definition: alertService.cpp:31
rtctk::componentFramework::AlertService::MakeAlertSource
AlertSource MakeAlertSource(AlertDescription const &description) override
Creates a new alert source for the specified alert condition.
Definition: alertService.cpp:58
rtctk::componentFramework::AlertLogger::AlertLogger
AlertLogger(log4cplus::Logger logger, AlertServiceIf &service)
Definition: alertService.cpp:131
rtctk::componentFramework::AlertStatusObserverIf::ReducedStatus
std::optional< bool > ReducedStatus
Represents current alert status.
Definition: alertServiceIf.hpp:209