Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | b5a9706 | 2018-12-13 16:55:23 -0800 | [diff] [blame] | 3 | #include "internal/sys.hpp" |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 4 | #include "ipmi_interface.hpp" |
| 5 | |
Patrick Venture | ecfd300 | 2018-12-14 13:57:28 -0800 | [diff] [blame] | 6 | #include <vector> |
| 7 | |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 8 | namespace host_tool |
| 9 | { |
| 10 | |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 11 | class IpmiHandler : public IpmiInterface |
| 12 | { |
| 13 | public: |
Patrick Venture | b5a9706 | 2018-12-13 16:55:23 -0800 | [diff] [blame] | 14 | explicit IpmiHandler(const internal::Sys* sys = &internal::sys_impl) : |
| 15 | sys(sys){}; |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 16 | |
Patrick Venture | 2e12a43 | 2018-12-13 18:05:11 -0800 | [diff] [blame] | 17 | ~IpmiHandler() = default; |
| 18 | IpmiHandler(const IpmiHandler&) = delete; |
| 19 | IpmiHandler& operator=(const IpmiHandler&) = delete; |
| 20 | IpmiHandler(IpmiHandler&&) = default; |
| 21 | IpmiHandler& operator=(IpmiHandler&&) = default; |
| 22 | |
| 23 | /** |
| 24 | * Attempt to open the device node. |
| 25 | * |
Patrick Venture | ecfd300 | 2018-12-14 13:57:28 -0800 | [diff] [blame] | 26 | * @throws IpmiException on failure. |
Patrick Venture | 2e12a43 | 2018-12-13 18:05:11 -0800 | [diff] [blame] | 27 | */ |
Patrick Venture | ecfd300 | 2018-12-14 13:57:28 -0800 | [diff] [blame] | 28 | void open(); |
Patrick Venture | 2e12a43 | 2018-12-13 18:05:11 -0800 | [diff] [blame] | 29 | |
Patrick Venture | ecfd300 | 2018-12-14 13:57:28 -0800 | [diff] [blame] | 30 | /** |
| 31 | * @throws IpmiException on failure. |
| 32 | */ |
Patrick Venture | 035bbbb | 2018-12-12 14:59:52 -0800 | [diff] [blame] | 33 | std::vector<std::uint8_t> |
Patrick Venture | ecfd300 | 2018-12-14 13:57:28 -0800 | [diff] [blame] | 34 | sendPacket(std::vector<std::uint8_t>& data) override; |
Patrick Venture | b5a9706 | 2018-12-13 16:55:23 -0800 | [diff] [blame] | 35 | |
| 36 | private: |
| 37 | const internal::Sys* sys; |
Patrick Venture | 2e12a43 | 2018-12-13 18:05:11 -0800 | [diff] [blame] | 38 | /** TODO: Use a smart file descriptor when it's ready. Until then only |
| 39 | * allow moving this object. |
| 40 | */ |
| 41 | int fd = -1; |
Patrick Venture | ecfd300 | 2018-12-14 13:57:28 -0800 | [diff] [blame] | 42 | /* The last IPMI sequence number we used. */ |
| 43 | int sequence = 0; |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 44 | }; |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 45 | |
| 46 | } // namespace host_tool |