Add device-management infrastructure
We're moving toward having dbus-sensors take over sensor device
lifecycle management from entity-manager; this code (loosely based on
entity-manager's include/devices.hpp and src/overlay.cpp) provides some
general-purpose utilities for instantiating and destroying devices.
This also includes a variant of setupPropertiesChangedMatches() taking
an I2CDeviceTypeMap instead of a span of C strings, so that we can
support both existing sensor daemons and ones that get converted to use
that instead of the simple string arrays they currently employ.
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: I39fcd0de2c70cd58b4d132cdcae5f82319732dbb
diff --git a/include/DeviceMgmt.hpp b/include/DeviceMgmt.hpp
new file mode 100644
index 0000000..daad381
--- /dev/null
+++ b/include/DeviceMgmt.hpp
@@ -0,0 +1,41 @@
+#pragma once
+#include <Utils.hpp>
+#include <boost/container/flat_map.hpp>
+
+#include <functional>
+#include <optional>
+#include <string_view>
+
+struct I2CDeviceType
+{
+ const char* name;
+ bool createsHWMon;
+};
+
+using I2CDeviceTypeMap =
+ boost::container::flat_map<std::string, I2CDeviceType, std::less<>>;
+
+struct I2CDevice
+{
+ I2CDevice(const I2CDeviceType& type, uint64_t bus, uint64_t address) :
+ type(&type), bus(bus), address(address){};
+
+ const I2CDeviceType* type;
+ uint64_t bus;
+ uint64_t address;
+
+ bool present(void) const;
+ int create(void) const;
+ int destroy(void) const;
+};
+
+std::optional<I2CDevice> getI2CDevice(const I2CDeviceTypeMap& dtmap,
+ const SensorBaseConfigMap& cfg);
+
+// HACK: this declaration "should" live in Utils.hpp, but that leads to a
+// tangle of header-dependency hell because each header needs types declared
+// in the other.
+std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
+ setupPropertiesChangedMatches(
+ sdbusplus::asio::connection& bus, const I2CDeviceTypeMap& typeMap,
+ const std::function<void(sdbusplus::message_t&)>& handler);