RTC Toolkit 6.0.0-pre2
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
21
22#include <taiclock/taiClock.hpp>
23
24#include <string>
25#include <vector>
26
28
29struct AlertInfo {
30 using TimePoint = taiclock::TaiClock::time_point;
31
32 AlertInfo(bool state, TimePoint since, const std::string& id, const std::string& text);
33
34 bool state;
36 std::string id;
37 std::string text;
38};
39
41 virtual ~AlertObserverIf() = default;
42 virtual void
43 Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept = 0;
44};
45
53public:
60 AlertOldbPublisher(const std::string& name, OldbIf& oldb);
61 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
62
63private:
64 std::string m_name;
65 OldbIf& m_oldb;
66 log4cplus::Logger m_logger;
67};
68
76public:
78 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
79
80private:
81 log4cplus::Logger m_logger;
82};
83
91public:
98 AlertEventPublisher(const std::string& name, EventServiceIf& ev);
99 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
100
101private:
102 std::string m_name;
103 EventServiceIf& m_svc;
104 std::unique_ptr<EventPublisherIf> m_publisher;
105 log4cplus::Logger m_logger;
106};
107
115public:
122 AlertTelegrafPublisher(const std::string& name, TelegrafAdapter& telegraf_adapter);
123 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
124
125private:
126 std::string m_name;
127 TelegrafAdapter& m_telegraf_adapter;
128 log4cplus::Logger m_logger;
129};
130
132public:
133 AlertStatus();
134 ~AlertStatus();
135
136 void AddObserver(std::unique_ptr<AlertObserverIf> o);
137
138 void AddAlert(const std::string& id, const std::string& text);
139
140 void SetAlert(const std::string& id, bool state = true);
141
142 void ClearAlerts();
143
144 AlertInfo GetInfo(const std::string& id);
145
146private:
147 std::recursive_mutex m_mtx;
148 AlertInfo m_reduced;
149 std::vector<AlertInfo> m_alerts;
150 size_t m_last_size = 0;
151 std::vector<std::unique_ptr<AlertObserverIf>> m_observers;
152};
153
155public:
156 void AddObserver(std::unique_ptr<AlertObserverIf> o) {
157 m_status.AddObserver(std::move(o));
158 }
159
160 AlertSource MakeAlertSource(const std::string& id, const std::string& text) override {
161 return {m_status, id, text};
162 };
163
164 bool GetStatus() override {
165 return m_status.GetInfo("").state;
166 }
167
168 void ClearAll() override {
169 m_status.ClearAlerts();
170 }
171
172private:
173 AlertStatus m_status;
174};
175
176} // namespace rtctk::componentFramework
177
178#endif // RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
Declares AlertService.
AlertEventPublisher(const std::string &name, EventServiceIf &ev)
Constructor.
Definition alertService.cpp:297
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:304
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:274
AlertLogger()
Definition alertService.cpp:271
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:237
AlertOldbPublisher(const std::string &name, OldbIf &oldb)
Constructor.
Definition alertService.cpp:212
Alert Service interface.
Definition alertServiceIf.hpp:138
Definition alertService.hpp:154
bool GetStatus() override
Returns the overall alert status.
Definition alertService.hpp:164
void ClearAll() override
Clears all active alerts.
Definition alertService.hpp:168
AlertSource MakeAlertSource(const std::string &id, const std::string &text) override
Creates a new alert source for a specified alert condition.
Definition alertService.hpp:160
void AddObserver(std::unique_ptr< AlertObserverIf > o)
Definition alertService.hpp:156
Models a single alert source that can be set or cleared.
Definition alertServiceIf.hpp:47
Definition alertService.hpp:131
void AddAlert(const std::string &id, const std::string &text)
Definition alertService.cpp:79
~AlertStatus()
Definition alertService.cpp:70
void ClearAlerts()
Definition alertService.cpp:133
void AddObserver(std::unique_ptr< AlertObserverIf > o)
Definition alertService.cpp:74
AlertInfo GetInfo(const std::string &id)
Definition alertService.cpp:164
AlertStatus()
Definition alertService.cpp:67
void SetAlert(const std::string &id, bool state=true)
Definition alertService.cpp:96
AlertTelegrafPublisher(const std::string &name, TelegrafAdapter &telegraf_adapter)
Constructor.
Definition alertService.cpp:337
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:350
Interface class for providing pub/sub facilities for JSON events.
Definition eventServiceIf.hpp:29
Base interface for all OLDB adapters.
Definition oldbIf.hpp:25
Implementation of the Telegraf Adapter.
Definition telegrafAdapter.hpp:93
Framework-provided event definitions.
Low-level interface of the event service.
Logging Support Library based on log4cplus.
Definition commandReplier.cpp:22
Header file for OldbIf, which defines the API for OldbAdapters.
Definition alertService.hpp:29
taiclock::TaiClock::time_point TimePoint
Definition alertService.hpp:30
std::string text
Definition alertService.hpp:37
std::string id
Definition alertService.hpp:36
AlertInfo(bool state, TimePoint since, const std::string &id, const std::string &text)
Definition alertService.cpp:60
bool state
Definition alertService.hpp:34
TimePoint since
Definition alertService.hpp:35
Definition alertService.hpp:40
virtual void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept=0
Header file needed to instantiate an TelegrafAdapter.