blob: 3eaf8972f4d5b829140a704a910f01f8d371c1e9 [file] [log] [blame]
Zev Weissdabd48d2022-08-03 15:43:17 -07001#pragma once
2#include <Utils.hpp>
3#include <boost/container/flat_map.hpp>
4
5#include <functional>
6#include <optional>
7#include <string_view>
8
9struct I2CDeviceType
10{
11 const char* name;
12 bool createsHWMon;
13};
14
15using I2CDeviceTypeMap =
16 boost::container::flat_map<std::string, I2CDeviceType, std::less<>>;
17
Zev Weiss3ee959a2022-09-21 17:16:28 -070018struct I2CDeviceParams
Zev Weissdabd48d2022-08-03 15:43:17 -070019{
Zev Weiss3ee959a2022-09-21 17:16:28 -070020 I2CDeviceParams(const I2CDeviceType& type, uint64_t bus, uint64_t address) :
Zev Weissdabd48d2022-08-03 15:43:17 -070021 type(&type), bus(bus), address(address){};
22
23 const I2CDeviceType* type;
24 uint64_t bus;
25 uint64_t address;
26
Zev Weiss3ee959a2022-09-21 17:16:28 -070027 bool devicePresent(void) const;
28};
29
30std::optional<I2CDeviceParams>
31 getI2CDeviceParams(const I2CDeviceTypeMap& dtmap,
32 const SensorBaseConfigMap& cfg);
33
34class I2CDevice
35{
36 public:
37 explicit I2CDevice(I2CDeviceParams params);
38 ~I2CDevice();
39
40 private:
41 I2CDeviceParams params;
42
Zev Weissdabd48d2022-08-03 15:43:17 -070043 int create(void) const;
44 int destroy(void) const;
45};
46
Zev Weissdabd48d2022-08-03 15:43:17 -070047// HACK: this declaration "should" live in Utils.hpp, but that leads to a
48// tangle of header-dependency hell because each header needs types declared
49// in the other.
50std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
51 setupPropertiesChangedMatches(
52 sdbusplus::asio::connection& bus, const I2CDeviceTypeMap& typeMap,
53 const std::function<void(sdbusplus::message_t&)>& handler);