blob: 4a5b7a16bcd7668c5d0ebaeb7b59bd649ad13fa6 [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;
Zev Weiss41f49c02022-09-21 17:27:18 -070028 bool deviceStatic(void) const;
Zev Weiss3ee959a2022-09-21 17:16:28 -070029};
30
31std::optional<I2CDeviceParams>
32 getI2CDeviceParams(const I2CDeviceTypeMap& dtmap,
33 const SensorBaseConfigMap& cfg);
34
35class I2CDevice
36{
37 public:
38 explicit I2CDevice(I2CDeviceParams params);
39 ~I2CDevice();
40
41 private:
42 I2CDeviceParams params;
43
Zev Weissdabd48d2022-08-03 15:43:17 -070044 int create(void) const;
45 int destroy(void) const;
46};
47
Zev Weissdabd48d2022-08-03 15:43:17 -070048// HACK: this declaration "should" live in Utils.hpp, but that leads to a
49// tangle of header-dependency hell because each header needs types declared
50// in the other.
51std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
52 setupPropertiesChangedMatches(
53 sdbusplus::asio::connection& bus, const I2CDeviceTypeMap& typeMap,
54 const std::function<void(sdbusplus::message_t&)>& handler);