blob: daad38197cad311a276cff8d64d65b78b797c116 [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
18struct I2CDevice
19{
20 I2CDevice(const I2CDeviceType& type, uint64_t bus, uint64_t address) :
21 type(&type), bus(bus), address(address){};
22
23 const I2CDeviceType* type;
24 uint64_t bus;
25 uint64_t address;
26
27 bool present(void) const;
28 int create(void) const;
29 int destroy(void) const;
30};
31
32std::optional<I2CDevice> getI2CDevice(const I2CDeviceTypeMap& dtmap,
33 const SensorBaseConfigMap& cfg);
34
35// HACK: this declaration "should" live in Utils.hpp, but that leads to a
36// tangle of header-dependency hell because each header needs types declared
37// in the other.
38std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
39 setupPropertiesChangedMatches(
40 sdbusplus::asio::connection& bus, const I2CDeviceTypeMap& typeMap,
41 const std::function<void(sdbusplus::message_t&)>& handler);