blob: 2f931899bbaf600e1f56ab524caa4cf37cbcf71f [file] [log] [blame]
Marri Devender Rao70aafbb2018-04-12 01:11:48 -05001#pragma once
2#include "callback.hpp"
3
4namespace phosphor
5{
6namespace dbus
7{
8namespace monitoring
9{
10/** @class Trap
11 * @brief Raises SNMP trap
12 */
13class 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 */
25 virtual void trap(sdbusplus::message::message& msg) const = 0;
26};
27
28/** @class ErrorTrap
29 * @brief Sends SNMP trap for the elog error
30 */
31class 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 */
44 void trap(sdbusplus::message::message& msg) const override;
45};
46
47/** @class SNMPTrap
48 * @brief SNMP trap callback implementation.
49 */
50template <typename T> class SNMPTrap : public Callback
51{
52 public:
53 SNMPTrap(const SNMPTrap&) = delete;
54 SNMPTrap(SNMPTrap&&) = default;
55 SNMPTrap& operator=(const SNMPTrap&) = delete;
56 SNMPTrap& operator=(SNMPTrap&&) = default;
57 virtual ~SNMPTrap() = default;
58 SNMPTrap() : Callback()
59 {
60 }
61
62 /** @brief Callback interface implementation.
63 * @param[in] ctc - context.
64 */
65 void operator()(Context ctx)
66 {
67 }
68
69 /** @brief Callback interface implementation.
70 * @param[in] ctc - context.
71 * @param[in] msg - sdbus message.
72 */
73 void operator()(Context ctx, sdbusplus::message::message& msg)
74 {
75 event.trap(msg);
76 }
77
78 private:
79 T event;
80};
81
82} // namespace monitoring
83} // namespace dbus
84} // namespace phosphor