blob: 1c91bfff347822523c804e294180564dc0a8253e [file] [log] [blame]
Patrick Venture123b5c02019-03-05 14:01:00 -08001#pragma once
2
3#include "internal/sys.hpp"
4#include "ipmi_interface.hpp"
5
6#include <vector>
7
8namespace host_tool
9{
10
11class IpmiHandler : public IpmiInterface
12{
13 public:
14 explicit IpmiHandler(const internal::Sys* sys = &internal::sys_impl) :
15 sys(sys){};
16
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 *
26 * @throws IpmiException on failure.
27 */
28 void open();
29
30 /**
31 * @throws IpmiException on failure.
32 */
33 std::vector<std::uint8_t>
34 sendPacket(std::vector<std::uint8_t>& data) override;
35
36 private:
37 const internal::Sys* sys;
38 /** TODO: Use a smart file descriptor when it's ready. Until then only
39 * allow moving this object.
40 */
41 int fd = -1;
42 /* The last IPMI sequence number we used. */
43 int sequence = 0;
44};
45
46} // namespace host_tool