RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
alertService.hpp
Go to the documentation of this file.
1
11#ifndef RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
12#define RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
13
20
21#include <taiclock/taiClock.hpp>
22
23#include <string>
24#include <vector>
25
27
35public:
36 explicit AlertUnknownException(const std::string& id);
37};
38
39struct AlertInfo {
40 using TimePoint = taiclock::TaiClock::time_point;
41
42 AlertInfo(bool state, TimePoint since, const std::string& id, const std::string& text);
43
44 bool state;
46 std::string id;
47 std::string text;
48};
49
51 virtual ~AlertObserverIf() = default;
52 virtual void
53 Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept = 0;
54};
55
63public:
70 AlertOldbPublisher(const std::string& name, OldbIf& oldb);
71 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
72
73private:
74 std::string m_name;
75 OldbIf& m_oldb;
76 log4cplus::Logger m_logger;
77};
78
86public:
88 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
89
90private:
91 log4cplus::Logger m_logger;
92};
93
101public:
108 AlertEventPublisher(const std::string& name, EventServiceIf& ev);
109 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
110
111private:
112 std::string m_name;
113 EventServiceIf& m_svc;
114 std::unique_ptr<EventPublisherIf> m_publisher;
115 log4cplus::Logger m_logger;
116};
117
125public:
132 AlertTelegrafPublisher(const std::string& name, TelegrafAdapter& telegraf_adapter);
133 void Publish(const AlertInfo& reduced, const std::vector<AlertInfo>& alerts) noexcept override;
134
135private:
136 std::string m_name;
137 TelegrafAdapter& m_telegraf_adapter;
138 log4cplus::Logger m_logger;
139};
140
142public:
143 AlertStatus();
144 ~AlertStatus();
145
146 void AddObserver(std::unique_ptr<AlertObserverIf> o);
147
148 void AddAlert(const std::string& id, const std::string& text);
149
150 void SetAlert(const std::string& id, bool state = true);
151
152 void ClearAlerts();
153
154 AlertInfo GetInfo(const std::string& id);
155
156private:
157 std::recursive_mutex m_mtx;
158 AlertInfo m_reduced;
159 std::vector<AlertInfo> m_alerts;
160 size_t m_last_size = 0;
161 std::vector<std::unique_ptr<AlertObserverIf>> m_observers;
162};
163
165public:
166 void AddObserver(std::unique_ptr<AlertObserverIf> o) {
167 m_status.AddObserver(std::move(o));
168 }
169
170 AlertSource MakeAlertSource(const std::string& id, const std::string& text) override {
171 return {m_status, id, text};
172 };
173
174 bool GetStatus() override {
175 return m_status.GetInfo("").state;
176 }
177
178 void ClearAll() override {
179 m_status.ClearAlerts();
180 }
181
182private:
183 AlertStatus m_status;
184};
185
186} // namespace rtctk::componentFramework
187
188#endif // RTCTK_COMPONENTFRAMEWORK_ALERTSERVICE_HPP
Declares AlertService.
AlertEventPublisher(const std::string &name, EventServiceIf &ev)
Constructor.
Definition alertService.cpp:287
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:294
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:264
AlertLogger()
Definition alertService.cpp:261
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:227
AlertOldbPublisher(const std::string &name, OldbIf &oldb)
Constructor.
Definition alertService.cpp:202
Alert Service interface.
Definition alertServiceIf.hpp:138
Definition alertService.hpp:164
bool GetStatus() override
Returns the overall alert status.
Definition alertService.hpp:174
void ClearAll() override
Clears all active alerts.
Definition alertService.hpp:178
AlertSource MakeAlertSource(const std::string &id, const std::string &text) override
Creates a new alert source for a specified alert condition.
Definition alertService.hpp:170
void AddObserver(std::unique_ptr< AlertObserverIf > o)
Definition alertService.hpp:166
Models a single alert source that can be set or cleared.
Definition alertServiceIf.hpp:47
Definition alertService.hpp:141
void AddAlert(const std::string &id, const std::string &text)
Definition alertService.cpp:68
~AlertStatus()
Definition alertService.cpp:59
void ClearAlerts()
Definition alertService.cpp:122
void AddObserver(std::unique_ptr< AlertObserverIf > o)
Definition alertService.cpp:63
AlertInfo GetInfo(const std::string &id)
Definition alertService.cpp:153
AlertStatus()
Definition alertService.cpp:56
void SetAlert(const std::string &id, bool state=true)
Definition alertService.cpp:85
AlertTelegrafPublisher(const std::string &name, TelegrafAdapter &telegraf_adapter)
Constructor.
Definition alertService.cpp:328
void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept override
Definition alertService.cpp:341
AlertUnknownException(const std::string &id)
Definition alertService.cpp:45
Interface class for providing pub/sub facilities for JSON events.
Definition eventServiceIf.hpp:28
Base interface for all OLDB adapters.
Definition oldbIf.hpp:24
RtctkException() noexcept
Definition exceptions.cpp:112
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:21
Header file for OldbIf, which defines the API for OldbAdapters.
Definition alertService.hpp:39
taiclock::TaiClock::time_point TimePoint
Definition alertService.hpp:40
std::string text
Definition alertService.hpp:47
std::string id
Definition alertService.hpp:46
AlertInfo(bool state, TimePoint since, const std::string &id, const std::string &text)
Definition alertService.cpp:49
bool state
Definition alertService.hpp:44
TimePoint since
Definition alertService.hpp:45
Definition alertService.hpp:50
virtual void Publish(const AlertInfo &reduced, const std::vector< AlertInfo > &alerts) noexcept=0
Header file needed to instantiate an TelegrafAdapter.