Program Listing for File monitor.hpp
↰ Return to documentation for file (monitoring/monitor.hpp)
#ifndef FELIX_MONITOR_H_
#define FELIX_MONITOR_H_
#include <string>
#include <memory>
#include <nlohmann/json.hpp>
#include <ers/ers.h>
#include "writer.hpp"
ERS_DECLARE_ISSUE(felix_log, monitor_issue, issue_message, ((const std::string&)issue_message))
class Monitor
{
public:
explicit Monitor(std::unique_ptr<Writer> writer) : m_writer{std::move(writer)} {}
virtual ~Monitor() = default;
Monitor(Monitor&&) noexcept = default;
Monitor& operator=(Monitor&&) noexcept = default;
Monitor(const Monitor&) = delete;
Monitor& operator=(const Monitor&) = delete;
[[nodiscard]] std::string get_serialized_message() {
return m_message.dump();
}
void write_message() {
m_writer->write_message(m_message);
}
void create_new_message(const std::string& hostname) {
m_message = nlohmann::json();
m_message["hostname"] = hostname;
m_message["devices"] = nlohmann::json::array();
}
protected:
nlohmann::json m_message{};
std::unique_ptr<Writer> m_writer;
};
#endif /* FELIX_MONITOR_H_ */