15 #ifndef DIAGNOSTICS_COLLECTOR_HPP_
16 #define DIAGNOSTICS_COLLECTOR_HPP_
21 #include <unordered_map>
22 #include "diagnostic_msgs/msg/diagnostic_status.hpp"
23 #include "diagnostic_updater/diagnostic_updater.hpp"
24 #include "diagnostic_updater/publisher.hpp"
45 return static_cast<unsigned char>(level_.load(std::memory_order_relaxed));
62 std::string
getValue(
const std::string & key)
const
64 std::lock_guard<std::mutex> lock(mutex_);
65 auto it = values_.find(key);
66 if (it != values_.end())
78 void summary(
unsigned char lvl,
const std::string & message)
80 std::lock_guard<std::mutex> lock(mutex_);
82 this->setMessage(message);
92 void summaryf(
unsigned char lvl,
const char * format, ...)
95 va_start(args, format);
97 vsnprintf(buffer,
sizeof(buffer), format, args);
99 summary(lvl, std::string(buffer));
108 void add(
const std::string & key,
const std::string & value)
110 std::lock_guard<std::mutex> lock(mutex_);
111 this->setValue(key, value);
121 void addf(
const std::string & key,
const char * format, ...)
124 va_start(args, format);
126 vsnprintf(buffer,
sizeof(buffer), format, args);
128 add(key, std::string(buffer));
140 unsigned char lvl,
const std::string & message,
const std::string & key,
141 const std::string & value)
143 std::lock_guard<std::mutex> lock(mutex_);
145 this->setMessage(message);
146 this->setValue(key, value);
150 std::atomic<unsigned char> level_;
151 std::string message_;
152 std::unordered_map<std::string, std::string> values_;
153 mutable std::mutex mutex_;
155 void setLevel(
unsigned char lvl)
157 level_.store(
static_cast<unsigned char>(lvl), std::memory_order_relaxed);
160 void setMessage(
const std::string & message) { message_ = message; }
162 void setValue(
const std::string & key,
const std::string & value) { values_[key] = value; }
A class to collect diagnostic information.
Definition: diagnostic_collector.hpp:34
void updateAll(unsigned char lvl, const std::string &message, const std::string &key, const std::string &value)
Update all diagnostic information.
Definition: diagnostic_collector.hpp:139
void addf(const std::string &key, const char *format,...)
Add a device state value.
Definition: diagnostic_collector.hpp:121
void summaryf(unsigned char lvl, const char *format,...)
Store current device summary.
Definition: diagnostic_collector.hpp:92
void add(const std::string &key, const std::string &value)
Add a device state value.
Definition: diagnostic_collector.hpp:108
std::string getValue(const std::string &key) const
Get the Value object Returns the current different device state values of the diagnostic.
Definition: diagnostic_collector.hpp:62
std::string getMessage() const
Get the Message object Returns the current message of the diagnostic.
Definition: diagnostic_collector.hpp:53
unsigned char getLevel() const
Get the Level Returns the current level (OK, WARN, ERROR or STALE) of the diagnostic.
Definition: diagnostic_collector.hpp:43
DiagnosticsCollector()
Definition: diagnostic_collector.hpp:36
void summary(unsigned char lvl, const std::string &message)
Store current device summary.
Definition: diagnostic_collector.hpp:78
Definition: configuration_manager.hpp:28