blob: 1c91bfff347822523c804e294180564dc0a8253e [file] [log] [blame]
Patrick Venturecf2d1b12018-12-11 18:22:36 -08001#pragma once
2
Patrick Ventureb5a97062018-12-13 16:55:23 -08003#include "internal/sys.hpp"
Patrick Venturecf2d1b12018-12-11 18:22:36 -08004#include "ipmi_interface.hpp"
5
Patrick Ventureecfd3002018-12-14 13:57:28 -08006#include <vector>
7
Patrick Venture9b534f02018-12-13 16:10:02 -08008namespace host_tool
9{
10
Patrick Venturecf2d1b12018-12-11 18:22:36 -080011class IpmiHandler : public IpmiInterface
12{
13 public:
Patrick Ventureb5a97062018-12-13 16:55:23 -080014 explicit IpmiHandler(const internal::Sys* sys = &internal::sys_impl) :
15 sys(sys){};
Patrick Venturecf2d1b12018-12-11 18:22:36 -080016
Patrick Venture2e12a432018-12-13 18:05:11 -080017 ~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 Ventureecfd3002018-12-14 13:57:28 -080026 * @throws IpmiException on failure.
Patrick Venture2e12a432018-12-13 18:05:11 -080027 */
Patrick Ventureecfd3002018-12-14 13:57:28 -080028 void open();
Patrick Venture2e12a432018-12-13 18:05:11 -080029
Patrick Ventureecfd3002018-12-14 13:57:28 -080030 /**
31 * @throws IpmiException on failure.
32 */
Patrick Venture035bbbb2018-12-12 14:59:52 -080033 std::vector<std::uint8_t>
Patrick Ventureecfd3002018-12-14 13:57:28 -080034 sendPacket(std::vector<std::uint8_t>& data) override;
Patrick Ventureb5a97062018-12-13 16:55:23 -080035
36 private:
37 const internal::Sys* sys;
Patrick Venture2e12a432018-12-13 18:05:11 -080038 /** TODO: Use a smart file descriptor when it's ready. Until then only
39 * allow moving this object.
40 */
41 int fd = -1;
Patrick Ventureecfd3002018-12-14 13:57:28 -080042 /* The last IPMI sequence number we used. */
43 int sequence = 0;
Patrick Venturecf2d1b12018-12-11 18:22:36 -080044};
Patrick Venture9b534f02018-12-13 16:10:02 -080045
46} // namespace host_tool