blob: 07b28b58002cdf4db6c561a898325b8fe9f298e1 [file] [log] [blame]
Zev Weissdabd48d2022-08-03 15:43:17 -07001#pragma once
Andrew Jefferye73bd0a2023-01-25 10:39:57 +10302
3#include "Utils.hpp"
4
Zev Weissdabd48d2022-08-03 15:43:17 -07005#include <boost/container/flat_map.hpp>
6
7#include <functional>
8#include <optional>
9#include <string_view>
10
11struct I2CDeviceType
12{
13 const char* name;
14 bool createsHWMon;
15};
16
17using I2CDeviceTypeMap =
18 boost::container::flat_map<std::string, I2CDeviceType, std::less<>>;
19
Zev Weiss3ee959a2022-09-21 17:16:28 -070020struct I2CDeviceParams
Zev Weissdabd48d2022-08-03 15:43:17 -070021{
Zev Weiss3ee959a2022-09-21 17:16:28 -070022 I2CDeviceParams(const I2CDeviceType& type, uint64_t bus, uint64_t address) :
Zev Weissdabd48d2022-08-03 15:43:17 -070023 type(&type), bus(bus), address(address){};
24
25 const I2CDeviceType* type;
26 uint64_t bus;
27 uint64_t address;
28
Zev Weiss3ee959a2022-09-21 17:16:28 -070029 bool devicePresent(void) const;
Zev Weiss41f49c02022-09-21 17:27:18 -070030 bool deviceStatic(void) const;
Zev Weiss3ee959a2022-09-21 17:16:28 -070031};
32
33std::optional<I2CDeviceParams>
34 getI2CDeviceParams(const I2CDeviceTypeMap& dtmap,
35 const SensorBaseConfigMap& cfg);
36
37class I2CDevice
38{
39 public:
40 explicit I2CDevice(I2CDeviceParams params);
41 ~I2CDevice();
42
43 private:
44 I2CDeviceParams params;
45
Zev Weissdabd48d2022-08-03 15:43:17 -070046 int create(void) const;
47 int destroy(void) const;
48};
49
Zev Weissdabd48d2022-08-03 15:43:17 -070050// HACK: this declaration "should" live in Utils.hpp, but that leads to a
51// tangle of header-dependency hell because each header needs types declared
52// in the other.
53std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
54 setupPropertiesChangedMatches(
55 sdbusplus::asio::connection& bus, const I2CDeviceTypeMap& typeMap,
56 const std::function<void(sdbusplus::message_t&)>& handler);