Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | #include "callback.hpp" |
| 3 | |
| 4 | namespace phosphor |
| 5 | { |
| 6 | namespace dbus |
| 7 | { |
| 8 | namespace monitoring |
| 9 | { |
| 10 | /** @class Trap |
| 11 | * @brief Raises SNMP trap |
| 12 | */ |
| 13 | class Trap |
| 14 | { |
| 15 | public: |
| 16 | Trap() = default; |
| 17 | Trap(const Trap&) = delete; |
| 18 | Trap(Trap&&) = default; |
| 19 | Trap& operator=(const Trap&) = delete; |
| 20 | Trap& operator=(Trap&&) = default; |
| 21 | virtual ~Trap() = default; |
| 22 | /** @brief Raise SNMP trap by parsing the sdbus message. |
| 23 | * @param[in] msg - sdbus message. |
| 24 | */ |
Patrick Williams | 413a485 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 25 | virtual void trap(sdbusplus::message_t& msg) const = 0; |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | /** @class ErrorTrap |
| 29 | * @brief Sends SNMP trap for the elog error |
| 30 | */ |
| 31 | class ErrorTrap : public Trap |
| 32 | { |
| 33 | public: |
| 34 | ErrorTrap() = default; |
| 35 | ErrorTrap(const ErrorTrap&) = delete; |
| 36 | ErrorTrap(ErrorTrap&&) = default; |
| 37 | ErrorTrap& operator=(const ErrorTrap&) = delete; |
| 38 | ErrorTrap& operator=(ErrorTrap&&) = default; |
| 39 | ~ErrorTrap() = default; |
| 40 | |
| 41 | /** @brief Raise SNMP trap by parsing the sdbus message. |
| 42 | * @param[in] msg - sdbus message. |
| 43 | */ |
Patrick Williams | 413a485 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 44 | void trap(sdbusplus::message_t& msg) const override; |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | /** @class SNMPTrap |
| 48 | * @brief SNMP trap callback implementation. |
| 49 | */ |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 50 | template <typename T> |
| 51 | class SNMPTrap : public Callback |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 52 | { |
| 53 | public: |
| 54 | SNMPTrap(const SNMPTrap&) = delete; |
| 55 | SNMPTrap(SNMPTrap&&) = default; |
| 56 | SNMPTrap& operator=(const SNMPTrap&) = delete; |
| 57 | SNMPTrap& operator=(SNMPTrap&&) = default; |
| 58 | virtual ~SNMPTrap() = default; |
| 59 | SNMPTrap() : Callback() |
George Liu | 3fe976c | 2022-06-21 09:37:04 +0800 | [diff] [blame] | 60 | {} |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 61 | |
| 62 | /** @brief Callback interface implementation. |
| 63 | * @param[in] ctc - context. |
| 64 | */ |
George Liu | ecef119 | 2022-07-07 08:59:12 +0800 | [diff] [blame] | 65 | void operator()(Context /* ctx */) override |
George Liu | 3fe976c | 2022-06-21 09:37:04 +0800 | [diff] [blame] | 66 | {} |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 67 | |
| 68 | /** @brief Callback interface implementation. |
| 69 | * @param[in] ctc - context. |
| 70 | * @param[in] msg - sdbus message. |
| 71 | */ |
Patrick Williams | 413a485 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 72 | void operator()(Context /* ctx */, sdbusplus::message_t& msg) override |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 73 | { |
| 74 | event.trap(msg); |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | T event; |
| 79 | }; |
| 80 | |
| 81 | } // namespace monitoring |
| 82 | } // namespace dbus |
| 83 | } // namespace phosphor |