blob: e98231d87e5d3d8d552c08d7c8a86a831efcc639 [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 Venture92a4a622021-02-04 10:45:00 -080020 explicit IpmiHandler(std::unique_ptr<internal::Sys> sys) :
21 sys(std::move(sys)){};
Patrick Venture123b5c02019-03-05 14:01:00 -080022
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>
Patrick Venture958f1ce2019-05-31 17:07:25 -070040 sendPacket(std::uint8_t netfn, std::uint8_t cmd,
41 std::vector<std::uint8_t>& data) override;
Patrick Venture123b5c02019-03-05 14:01:00 -080042
43 private:
Patrick Venture92a4a622021-02-04 10:45:00 -080044 const std::unique_ptr<internal::Sys> sys;
Patrick Venture123b5c02019-03-05 14:01:00 -080045 /** TODO: Use a smart file descriptor when it's ready. Until then only
46 * allow moving this object.
47 */
48 int fd = -1;
49 /* The last IPMI sequence number we used. */
50 int sequence = 0;
51};
52
Patrick Venture1470bec2019-03-06 07:33:12 -080053} // namespace ipmiblob