sensormanager: use bus reference_wrapper over pointer
Switch the SensorManager class to use a `reference_wrapper` to the
sdbusplus connection rather than a raw pointer for code safety.
This has a side-effect of disabling the default constructor for the
class, which implicates using wrappers like `std::optional`.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I799d4564f0dbd9698951f0ec8e86a7272299ebf6
diff --git a/sensors/builder.cpp b/sensors/builder.cpp
index 166977b..1c63623 100644
--- a/sensors/builder.cpp
+++ b/sensors/builder.cpp
@@ -46,7 +46,7 @@
const std::map<std::string, conf::SensorConfig>& config,
sdbusplus::bus_t& passive, sdbusplus::bus_t& host)
{
- SensorManager mgmr(passive, host);
+ SensorManager mgmr{passive, host};
auto& hostSensorBus = mgmr.getHostBus();
auto& passiveListeningBus = mgmr.getPassiveBus();
diff --git a/sensors/manager.hpp b/sensors/manager.hpp
index e02e1c9..6ae39fd 100644
--- a/sensors/manager.hpp
+++ b/sensors/manager.hpp
@@ -20,13 +20,13 @@
{
public:
SensorManager(sdbusplus::bus_t& pass, sdbusplus::bus_t& host) :
- _passiveListeningBus(&pass), _hostSensorBus(&host)
+ _passiveListeningBus(pass), _hostSensorBus(host)
{
// manager gets its interface from the bus. :D
- sdbusplus::server::manager_t(*_hostSensorBus, SensorRoot);
+ sdbusplus::server::manager_t(_hostSensorBus, SensorRoot);
}
- SensorManager() = default;
+ SensorManager() = delete;
~SensorManager() = default;
SensorManager(const SensorManager&) = delete;
SensorManager& operator=(const SensorManager&) = delete;
@@ -47,20 +47,20 @@
sdbusplus::bus_t& getPassiveBus(void)
{
- return *_passiveListeningBus;
+ return _passiveListeningBus;
}
sdbusplus::bus_t& getHostBus(void)
{
- return *_hostSensorBus;
+ return _hostSensorBus;
}
private:
std::map<std::string, std::unique_ptr<Sensor>> _sensorMap;
std::map<std::string, std::vector<std::string>> _sensorTypeList;
- sdbusplus::bus_t* _passiveListeningBus;
- sdbusplus::bus_t* _hostSensorBus;
+ std::reference_wrapper<sdbusplus::bus_t> _passiveListeningBus;
+ std::reference_wrapper<sdbusplus::bus_t> _hostSensorBus;
static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
};