blob: be5f4d0baaaa9ee0a40c04fcf529bc747bcd28d9 [file] [log] [blame]
Patrick Venturef085d912019-03-15 08:50:00 -07001#pragma once
2
3#include <cstdint>
4#include <string>
5#include <tuple>
6
7namespace google
8{
9namespace ipmi
10{
11
Patrick Venturebb90d4f2019-03-15 13:42:06 -070012using VersionTuple =
13 std::tuple<std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t>;
14
Patrick Venturef085d912019-03-15 08:50:00 -070015class HandlerInterface
16{
17 public:
18 virtual ~HandlerInterface() = default;
19
20 /**
21 * Return ethernet details (hard-coded).
22 *
23 * @return tuple of ethernet details (channel, if name).
24 */
25 virtual std::tuple<std::uint8_t, std::string> getEthDetails() const = 0;
Patrick Ventured2037c62019-03-15 10:29:47 -070026
27 /**
28 * Return the value of rx_packets, given a if_name.
29 *
30 * @param[in] name, the interface name.
31 * @return the number of packets received.
32 * @throw IpmiException on failure.
33 */
34 virtual std::int64_t getRxPackets(const std::string& name) const = 0;
Patrick Venturebb90d4f2019-03-15 13:42:06 -070035
36 /**
37 * Return the values from a cpld version file.
38 *
39 * @param[in] id - the cpld id number.
40 * @return the quad of numbers as a tuple (maj,min,pt,subpt)
41 * @throw IpmiException on failure.
42 */
43 virtual VersionTuple getCpldVersion(unsigned int id) const = 0;
Patrick Ventureaa374122019-03-15 15:09:10 -070044
45 /**
46 * Set the PSU Reset delay.
47 *
48 * @param[in] delay - delay in seconds.
49 * @throw IpmiException on failure.
50 */
51 virtual void psuResetDelay(std::uint32_t delay) const = 0;
Patrick Venture07f85152019-03-15 21:36:56 -070052
53 /**
54 * Return the entity name.
55 * On the first call to this method it'll build the list of entities.
56 * @todo Consider moving the list building to construction time (and ignore
57 * failures).
58 *
59 * @param[in] id - the entity id value
60 * @param[in] instance - the entity instance
61 * @return the entity's name
62 * @throw IpmiException on failure.
63 */
64 virtual std::string getEntityName(std::uint8_t id,
65 std::uint8_t instance) = 0;
Patrick Venturef085d912019-03-15 08:50:00 -070066};
67
68class Handler : public HandlerInterface
69{
70 public:
71 Handler() = default;
72 ~Handler() = default;
73
74 std::tuple<std::uint8_t, std::string> getEthDetails() const override;
Patrick Ventured2037c62019-03-15 10:29:47 -070075 std::int64_t getRxPackets(const std::string& name) const override;
Patrick Venturebb90d4f2019-03-15 13:42:06 -070076 VersionTuple getCpldVersion(unsigned int id) const override;
Patrick Ventureaa374122019-03-15 15:09:10 -070077 void psuResetDelay(std::uint32_t delay) const override;
Patrick Venture07f85152019-03-15 21:36:56 -070078 std::string getEntityName(std::uint8_t id, std::uint8_t instance) override;
Patrick Venturef085d912019-03-15 08:50:00 -070079};
80
81extern Handler handlerImpl;
82
83} // namespace ipmi
84} // namespace google