#pragma once #include #include #include "callback.hpp" #include #include namespace phosphor { namespace dbus { namespace monitoring { /** @class ElogBase * @brief Elog callback implementation. * * The elog callback logs the elog and * elog metadata. */ class ElogBase : public Callback { public: ElogBase(const ElogBase&) = delete; ElogBase(ElogBase&&) = default; ElogBase& operator=(const ElogBase&) = delete; ElogBase& operator=(ElogBase&&) = default; virtual ~ElogBase() = default; ElogBase() : Callback() {} /** @brief Callback interface implementation. */ void operator()(Context ctx) override; private: /** @brief Delegate type specific calls to subclasses. */ virtual void log() const = 0; }; namespace detail { /** @class CallElog * @brief Provide explicit call forwarding to phosphor::logging::report. * * @tparam T - Error log type * @tparam Args - Metadata fields types. */ template struct CallElog { static void op(Args&& ...args) { phosphor::logging::report(std::forward(args)...); } }; } // namespace detail /** @class Elog * @brief C++ type specific logic for the elog callback. * The elog callback logs the elog and elog metadata. * * @tparam T - Error log type * @tparam Args - Metadata fields types. * @param[in] arguments - Metadata fields to be added to the error log */ template class Elog : public ElogBase { public: Elog(const Elog&) = delete; Elog(Elog&&) = default; Elog& operator=(const Elog&) = delete; Elog& operator=(Elog&&) = default; ~Elog() = default; Elog(Args&& ... arguments) : ElogBase(), args(std::forward(arguments)...) {} private: /** @brief elog interface implementation. */ void log() const override { std::experimental::apply( detail::CallElog::op, std::tuple_cat(args)); } std::tuple args; }; /** @brief Argument type deduction for constructing Elog instances. * * @tparam T - Error log type * @tparam Args - Metadata fields types. * @param[in] arguments - Metadata fields to be added to the error log */ template auto makeElog(Args&& ... arguments) { return std::make_unique>( std::forward(arguments)...); } } // namespace monitoring } // namespace dbus } // namespace phosphor