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 | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 20 | explicit IpmiHandler(const internal::Sys* sys = &internal::sys_impl) : |
| 21 | sys(sys){}; |
| 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> |
| 40 | sendPacket(std::vector<std::uint8_t>& data) override; |
| 41 | |
| 42 | private: |
| 43 | const internal::Sys* sys; |
| 44 | /** TODO: Use a smart file descriptor when it's ready. Until then only |
| 45 | * allow moving this object. |
| 46 | */ |
| 47 | int fd = -1; |
| 48 | /* The last IPMI sequence number we used. */ |
| 49 | int sequence = 0; |
| 50 | }; |
| 51 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 52 | } // namespace ipmiblob |