DeviceMgmt: split I2CDeviceParams out of I2CDevice
The parameters struct now exists on its own, separately from the device
struct which instantiates the kernel device in its constructor and
removes it in its destructor. This allows the parameters to exist
standalone so that we can do things like use an instance of it to check
if a device is already instantiated without attempting to do so.
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: Ib1c37ee26e27e59020a8e26916e697729a3661af
diff --git a/include/DeviceMgmt.hpp b/include/DeviceMgmt.hpp
index daad381..3eaf897 100644
--- a/include/DeviceMgmt.hpp
+++ b/include/DeviceMgmt.hpp
@@ -15,23 +15,35 @@
using I2CDeviceTypeMap =
boost::container::flat_map<std::string, I2CDeviceType, std::less<>>;
-struct I2CDevice
+struct I2CDeviceParams
{
- I2CDevice(const I2CDeviceType& type, uint64_t bus, uint64_t address) :
+ I2CDeviceParams(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;
+ bool devicePresent(void) const;
+};
+
+std::optional<I2CDeviceParams>
+ getI2CDeviceParams(const I2CDeviceTypeMap& dtmap,
+ const SensorBaseConfigMap& cfg);
+
+class I2CDevice
+{
+ public:
+ explicit I2CDevice(I2CDeviceParams params);
+ ~I2CDevice();
+
+ private:
+ I2CDeviceParams params;
+
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.