Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "internal/sys.hpp" |
| 4 | #include "ipmi_interface.hpp" |
| 5 | |
Patrick Venture | 2fe4c65 | 2019-05-13 07:37:33 -0700 | [diff] [blame] | 6 | #include <memory> |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 9 | namespace ipmiblob |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 10 | { |
| 11 | |
| 12 | class IpmiHandler : public IpmiInterface |
| 13 | { |
| 14 | public: |
Patrick Venture | 2fe4c65 | 2019-05-13 07:37:33 -0700 | [diff] [blame] | 15 | /* Create an IpmiHandler object with default inputs. It is ill-advised to |
| 16 | * share IpmiHandlers between objects. |
| 17 | */ |
| 18 | static std::unique_ptr<IpmiInterface> CreateIpmiHandler(); |
| 19 | |
Patrick Venture | 92a4a62 | 2021-02-04 10:45:00 -0800 | [diff] [blame^] | 20 | explicit IpmiHandler(std::unique_ptr<internal::Sys> sys) : |
| 21 | sys(std::move(sys)){}; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 22 | |
| 23 | ~IpmiHandler() = default; |
| 24 | IpmiHandler(const IpmiHandler&) = delete; |
| 25 | IpmiHandler& operator=(const IpmiHandler&) = delete; |
| 26 | IpmiHandler(IpmiHandler&&) = default; |
| 27 | IpmiHandler& operator=(IpmiHandler&&) = default; |
| 28 | |
| 29 | /** |
| 30 | * Attempt to open the device node. |
| 31 | * |
| 32 | * @throws IpmiException on failure. |
| 33 | */ |
| 34 | void open(); |
| 35 | |
| 36 | /** |
| 37 | * @throws IpmiException on failure. |
| 38 | */ |
| 39 | std::vector<std::uint8_t> |
Patrick Venture | 958f1ce | 2019-05-31 17:07:25 -0700 | [diff] [blame] | 40 | sendPacket(std::uint8_t netfn, std::uint8_t cmd, |
| 41 | std::vector<std::uint8_t>& data) override; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 42 | |
| 43 | private: |
Patrick Venture | 92a4a62 | 2021-02-04 10:45:00 -0800 | [diff] [blame^] | 44 | const std::unique_ptr<internal::Sys> sys; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 45 | /** TODO: Use a smart file descriptor when it's ready. Until then only |
| 46 | * allow moving this object. |
| 47 | */ |
| 48 | int fd = -1; |
| 49 | /* The last IPMI sequence number we used. */ |
| 50 | int sequence = 0; |
| 51 | }; |
| 52 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 53 | } // namespace ipmiblob |