RTC Toolkit 5.0.0
Loading...
Searching...
No Matches
alertService.hpp
Go to the documentation of this file.
1
12#ifndef RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
13#define RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
14
20
21#include <taiclock/taiClock.hpp>
22
23#include <string>
24#include <vector>
25
27
28struct AlertInfo {
29 using TimePoint = taiclock::TaiClock::time_point;
30
31 AlertInfo(bool state, TimePoint since, const std::string& id, const std::string& text);
32
33 bool state;
35 std::string id;
36 std::string text;
37};
38
40 virtual ~AlertObserverIf() = default;
41 virtual void
42 Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept = 0;
43};
44
52public:
59 AlertOldbPublisher(const std::string& name, OldbIf& oldb);
60 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
61
62private:
63 std::string m_name;
64 OldbIf& m_oldb;
65 log4cplus::Logger m_logger;
66};
67
75public:
77 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
78
79private:
80 log4cplus::Logger m_logger;
81};
82
90public:
97 AlertEventPublisher(const std::string& name, EventServiceIf& ev);
98 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
99
100private:
101 std::string m_name;
102 TypedEventService m_svc;
103 std::unique_ptr<TypedEventPublisher<AlertStatusEvent>> m_publisher;
104 log4cplus::Logger m_logger;
105};
106
108public:
109 AlertStatus();
110 ~AlertStatus();
111
112 void AddObserver(std::unique_ptr<AlertObserverIf> o);
113
114 void AddAlert(const std::string& id, const std::string& text);
115
116 void SetAlert(const std::string& id, bool state = true);
117
118 void ClearAlerts();
119
120 AlertInfo GetInfo(const std::string& id);
121
122private:
123 std::recursive_mutex m_mtx;
124 AlertInfo m_reduced;
125 std::vector<AlertInfo> m_alerts;
126 size_t m_last_size;
127 std::vector<std::unique_ptr<AlertObserverIf>> m_observers;
128};
129
131public:
132 void AddObserver(std::unique_ptr<AlertObserverIf> o) {
133 m_status.AddObserver(std::move(o));
134 }
135
136 AlertSource MakeAlertSource(const std::string& id, const std::string& text) override {
137 return AlertSource(m_status, id, text);
138 };
139
140 bool GetStatus() override {
141 return m_status.GetInfo("").state;
142 }
143
144 void ClearAll() override {
145 m_status.ClearAlerts();
146 }
147
148private:
149 AlertStatus m_status;
150};
151
152} // namespace rtctk::componentFramework
153
154#endif // RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
Declares AlertService.
Alert observer that publishes alerts to Event Channel.
Definition alertService.hpp:89
AlertEventPublisher(const std::string &name, EventServiceIf &ev)
Constructor.
Definition alertService.cpp:253
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:260
Alert observer that publishes alerts to Log Files.
Definition alertService.hpp:74
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:230
AlertLogger()
Definition alertService.cpp:227
Alert observer that publishes alerts to Online Database.
Definition alertService.hpp:51
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:204
AlertOldbPublisher(const std::string &name, OldbIf &oldb)
Constructor.
Definition alertService.cpp:190
Alert Service interface.
Definition alertServiceIf.hpp:128
Definition alertService.hpp:130
bool GetStatus() override
Returns the overall alert status.
Definition alertService.hpp:140
void ClearAll() override
Clears all active alerts.
Definition alertService.hpp:144
AlertSource MakeAlertSource(const std::string &id, const std::string &text) override
Creates a new alert source for a specified alert condition.
Definition alertService.hpp:136
void AddObserver(std::unique_ptr< AlertObserverIf > o)
Definition alertService.hpp:132
Models a single alert source that can be set or cleared.
Definition alertServiceIf.hpp:47
Definition alertService.hpp:107
void AddAlert(const std::string &id, const std::string &text)
Definition alertService.cpp:65
~AlertStatus()
Definition alertService.cpp:56
void ClearAlerts()
Definition alertService.cpp:119
void AddObserver(std::unique_ptr< AlertObserverIf > o)
Definition alertService.cpp:60
AlertInfo GetInfo(const std::string &id)
Definition alertService.cpp:150
AlertStatus()
Definition alertService.cpp:52
void SetAlert(const std::string &id, bool state=true)
Definition alertService.cpp:82
Interface class for providing pub/sub facilities for JSON events.
Definition eventServiceIf.hpp:29
Base interface for all OLDB adapters.
Definition oldbIf.hpp:25
A high-level event service API that is aware of event types.
Definition typedEventService.hpp:247
Framework-provided event definitions.
Logging Support Library based on log4cplus.
Definition commandReplier.cpp:22
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Header file for OldbIf, which defines the API for OldbAdapters.
Definition alertService.hpp:28
taiclock::TaiClock::time_point TimePoint
Definition alertService.hpp:29
std::string text
Definition alertService.hpp:36
std::string id
Definition alertService.hpp:35
AlertInfo(bool state, TimePoint since, const std::string &id, const std::string &text)
Definition alertService.cpp:45
bool state
Definition alertService.hpp:33
TimePoint since
Definition alertService.hpp:34
Definition alertService.hpp:39
virtual void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept=0
High-level API of the event service.