blob: 34177aeee6a7e06d9b391216cf0d4c26022ba963 [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
Patrick Venture2fe4c652019-05-13 07:37:33 -07006#include <memory>
Patrick Venture123b5c02019-03-05 14:01:00 -08007#include <vector>
8
Patrick Venture1470bec2019-03-06 07:33:12 -08009namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -080010{
11
12class IpmiHandler : public IpmiInterface
13{
14 public:
Patrick Venture2fe4c652019-05-13 07:37:33 -070015 /* 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 Venture123b5c02019-03-05 14:01:00 -080020 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 Venture1470bec2019-03-06 07:33:12 -080052} // namespace ipmiblob