blob: f138b0bb61fcad3b017e834a7b56f46dd828f9e7 [file] [log] [blame]
Gunnar Mills9679d432017-08-03 15:54:43 -05001#pragma once
2#include <phosphor-logging/elog-errors.hpp>
3#include <phosphor-logging/elog.hpp>
4#include "callback.hpp"
5#include <sdbusplus/exception.hpp>
6
7namespace phosphor
8{
9namespace dbus
10{
11namespace monitoring
12{
13
14/** @class ElogBase
15 * @brief Elog callback implementation.
16 *
17 * The elog callback logs the elog and
18 * elog metadata.
19 */
20class ElogBase : public Callback
21{
22 public:
23 ElogBase(const ElogBase&) = delete;
24 ElogBase(ElogBase&&) = default;
25 ElogBase& operator=(const ElogBase&) = delete;
26 ElogBase& operator=(ElogBase&&) = default;
27 virtual ~ElogBase() = default;
28 ElogBase() :
29 Callback(){}
30
31 /** @brief Callback interface implementation. */
32 void operator()() override;
33
34 private:
35 /** @brief Delegate type specific calls to subclasses. */
36 virtual void log() const = 0;
37};
38
39
40/** @class Elog
41 * @brief C++ type specific logic for the elog callback.
42 *
43 * @tparam T - Error log type
44 */
45template <typename T>
46class Elog : public ElogBase
47{
48 public:
49 Elog(const Elog&) = delete;
50 Elog(Elog&&) = default;
51 Elog& operator=(const Elog&) = delete;
52 Elog& operator=(Elog&&) = default;
53 ~Elog() = default;
54 Elog() :
55 ElogBase() {}
56
57 private:
58 /** @brief elog interface implementation. */
59 void log() const override
60 {
61
62 using namespace phosphor::logging;
63 report<T>();
64 }
65};
66
67} // namespace monitoring
68} // namespace dbus
69} // namespace phosphor