xref: /openbmc/phosphor-dbus-monitor/src/snmp_trap.hpp (revision c5fe26a60b7a5f1c3c1a08d9cf2da71467356798)
170aafbb5SMarri Devender Rao #pragma once
270aafbb5SMarri Devender Rao #include "callback.hpp"
370aafbb5SMarri Devender Rao 
470aafbb5SMarri Devender Rao namespace phosphor
570aafbb5SMarri Devender Rao {
670aafbb5SMarri Devender Rao namespace dbus
770aafbb5SMarri Devender Rao {
870aafbb5SMarri Devender Rao namespace monitoring
970aafbb5SMarri Devender Rao {
1070aafbb5SMarri Devender Rao /** @class Trap
1170aafbb5SMarri Devender Rao  *  @brief Raises SNMP trap
1270aafbb5SMarri Devender Rao  */
1370aafbb5SMarri Devender Rao class Trap
1470aafbb5SMarri Devender Rao {
1570aafbb5SMarri Devender Rao   public:
1670aafbb5SMarri Devender Rao     Trap() = default;
1770aafbb5SMarri Devender Rao     Trap(const Trap&) = delete;
1870aafbb5SMarri Devender Rao     Trap(Trap&&) = default;
1970aafbb5SMarri Devender Rao     Trap& operator=(const Trap&) = delete;
2070aafbb5SMarri Devender Rao     Trap& operator=(Trap&&) = default;
2170aafbb5SMarri Devender Rao     virtual ~Trap() = default;
2270aafbb5SMarri Devender Rao     /** @brief Raise SNMP trap by parsing the sdbus message.
2370aafbb5SMarri Devender Rao      *  @param[in] msg - sdbus message.
2470aafbb5SMarri Devender Rao      */
25413a4857SPatrick Williams     virtual void trap(sdbusplus::message_t& msg) const = 0;
2670aafbb5SMarri Devender Rao };
2770aafbb5SMarri Devender Rao 
2870aafbb5SMarri Devender Rao /** @class ErrorTrap
2970aafbb5SMarri Devender Rao  *  @brief Sends SNMP trap for the elog error
3070aafbb5SMarri Devender Rao  */
3170aafbb5SMarri Devender Rao class ErrorTrap : public Trap
3270aafbb5SMarri Devender Rao {
3370aafbb5SMarri Devender Rao   public:
3470aafbb5SMarri Devender Rao     ErrorTrap() = default;
3570aafbb5SMarri Devender Rao     ErrorTrap(const ErrorTrap&) = delete;
3670aafbb5SMarri Devender Rao     ErrorTrap(ErrorTrap&&) = default;
3770aafbb5SMarri Devender Rao     ErrorTrap& operator=(const ErrorTrap&) = delete;
3870aafbb5SMarri Devender Rao     ErrorTrap& operator=(ErrorTrap&&) = default;
3970aafbb5SMarri Devender Rao     ~ErrorTrap() = default;
4070aafbb5SMarri Devender Rao 
4170aafbb5SMarri Devender Rao     /** @brief Raise SNMP trap by parsing the sdbus message.
4270aafbb5SMarri Devender Rao      *  @param[in] msg - sdbus message.
4370aafbb5SMarri Devender Rao      */
44413a4857SPatrick Williams     void trap(sdbusplus::message_t& msg) const override;
4570aafbb5SMarri Devender Rao };
4670aafbb5SMarri Devender Rao 
4770aafbb5SMarri Devender Rao /** @class SNMPTrap
4870aafbb5SMarri Devender Rao  *  @brief SNMP trap callback implementation.
4970aafbb5SMarri Devender Rao  */
503d6d3182SPatrick Venture template <typename T>
513d6d3182SPatrick Venture class SNMPTrap : public Callback
5270aafbb5SMarri Devender Rao {
5370aafbb5SMarri Devender Rao   public:
5470aafbb5SMarri Devender Rao     SNMPTrap(const SNMPTrap&) = delete;
5570aafbb5SMarri Devender Rao     SNMPTrap(SNMPTrap&&) = default;
5670aafbb5SMarri Devender Rao     SNMPTrap& operator=(const SNMPTrap&) = delete;
5770aafbb5SMarri Devender Rao     SNMPTrap& operator=(SNMPTrap&&) = default;
5870aafbb5SMarri Devender Rao     virtual ~SNMPTrap() = default;
SNMPTrap()59*c5fe26a6SPatrick Williams     SNMPTrap() : Callback() {}
6070aafbb5SMarri Devender Rao 
6170aafbb5SMarri Devender Rao     /** @brief Callback interface implementation.
6270aafbb5SMarri Devender Rao      *  @param[in] ctc - context.
6370aafbb5SMarri Devender Rao      */
operator ()(Context)64*c5fe26a6SPatrick Williams     void operator()(Context /* ctx */) override {}
6570aafbb5SMarri Devender Rao 
6670aafbb5SMarri Devender Rao     /** @brief Callback interface implementation.
6770aafbb5SMarri Devender Rao      *  @param[in] ctc - context.
6870aafbb5SMarri Devender Rao      *  @param[in] msg - sdbus message.
6970aafbb5SMarri Devender Rao      */
operator ()(Context,sdbusplus::message_t & msg)70413a4857SPatrick Williams     void operator()(Context /* ctx */, sdbusplus::message_t& msg) override
7170aafbb5SMarri Devender Rao     {
7270aafbb5SMarri Devender Rao         event.trap(msg);
7370aafbb5SMarri Devender Rao     }
7470aafbb5SMarri Devender Rao 
7570aafbb5SMarri Devender Rao   private:
7670aafbb5SMarri Devender Rao     T event;
7770aafbb5SMarri Devender Rao };
7870aafbb5SMarri Devender Rao 
7970aafbb5SMarri Devender Rao } // namespace monitoring
8070aafbb5SMarri Devender Rao } // namespace dbus
8170aafbb5SMarri Devender Rao } // namespace phosphor
82