blob: fedc068335d1dd4919a705757fd18fe9bdad944a [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
Anh Phan626bf762024-07-12 11:51:02 +00006#include <atomic>
Patrick Venture2fe4c652019-05-13 07:37:33 -07007#include <memory>
Patrick Venture123b5c02019-03-05 14:01:00 -08008#include <vector>
9
Patrick Venture1470bec2019-03-06 07:33:12 -080010namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -080011{
12
13class IpmiHandler : public IpmiInterface
14{
15 public:
Patrick Venture2fe4c652019-05-13 07:37:33 -070016 /* Create an IpmiHandler object with default inputs. It is ill-advised to
17 * share IpmiHandlers between objects.
18 */
19 static std::unique_ptr<IpmiInterface> CreateIpmiHandler();
20
Patrick Venture92a4a622021-02-04 10:45:00 -080021 explicit IpmiHandler(std::unique_ptr<internal::Sys> sys) :
22 sys(std::move(sys)){};
Patrick Venture123b5c02019-03-05 14:01:00 -080023
24 ~IpmiHandler() = default;
25 IpmiHandler(const IpmiHandler&) = delete;
26 IpmiHandler& operator=(const IpmiHandler&) = delete;
27 IpmiHandler(IpmiHandler&&) = default;
28 IpmiHandler& operator=(IpmiHandler&&) = default;
29
30 /**
31 * Attempt to open the device node.
32 *
33 * @throws IpmiException on failure.
34 */
35 void open();
36
37 /**
38 * @throws IpmiException on failure.
39 */
40 std::vector<std::uint8_t>
Patrick Venture958f1ce2019-05-31 17:07:25 -070041 sendPacket(std::uint8_t netfn, std::uint8_t cmd,
42 std::vector<std::uint8_t>& data) override;
Patrick Venture123b5c02019-03-05 14:01:00 -080043
44 private:
Patrick Venture92a4a622021-02-04 10:45:00 -080045 const std::unique_ptr<internal::Sys> sys;
Patrick Venture123b5c02019-03-05 14:01:00 -080046 /** TODO: Use a smart file descriptor when it's ready. Until then only
47 * allow moving this object.
48 */
49 int fd = -1;
50 /* The last IPMI sequence number we used. */
Anh Phan626bf762024-07-12 11:51:02 +000051 std::atomic_int sequence = 0;
Patrick Venture123b5c02019-03-05 14:01:00 -080052};
53
Patrick Venture1470bec2019-03-06 07:33:12 -080054} // namespace ipmiblob