enable unit-tests: enable for SensorManager
Enabled unit-tests in general for the project, and more
specifically started with a benign construction test for
the SensorManager object.
Tested: Verified continues to build and link, and unit-test
passes.
Tested: Ran on quanta-q71l board and it behaved as expected.
Change-Id: I4ad9a0c57efd0b9ccc37d26faa0cc1b82026b8d7
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/sensors/builder.cpp b/sensors/builder.cpp
index 2786141..4654e51 100644
--- a/sensors/builder.cpp
+++ b/sensors/builder.cpp
@@ -15,6 +15,8 @@
*/
#include <iostream>
+#include <map>
+#include <string>
/* Configuration. */
#include "conf.hpp"
@@ -33,12 +35,12 @@
static constexpr bool deferSignals = true;
-std::shared_ptr<SensorManager> BuildSensors(
+SensorManager BuildSensors(
const std::map<std::string, struct sensor>& config)
{
- auto mgmr = std::make_shared<SensorManager>();
- auto& HostSensorBus = mgmr->getHostBus();
- auto& PassiveListeningBus = mgmr->getPassiveBus();
+ SensorManager mgmr;
+ auto& HostSensorBus = mgmr.getHostBus();
+ auto& PassiveListeningBus = mgmr.getPassiveBus();
for (auto& it : config)
{
@@ -110,7 +112,7 @@
info->timeout,
std::move(ri),
std::move(wi));
- mgmr->addSensor(info->type, name, std::move(sensor));
+ mgmr.addSensor(info->type, name, std::move(sensor));
}
else if (info->type == "temp" || info->type == "margin")
{
@@ -133,7 +135,7 @@
HostSensorBus,
info->readpath.c_str(),
deferSignals);
- mgmr->addSensor(info->type, name, std::move(sensor));
+ mgmr.addSensor(info->type, name, std::move(sensor));
}
else
{
@@ -143,7 +145,7 @@
info->timeout,
std::move(ri),
std::move(wi));
- mgmr->addSensor(info->type, name, std::move(sensor));
+ mgmr.addSensor(info->type, name, std::move(sensor));
}
}
}
diff --git a/sensors/builder.hpp b/sensors/builder.hpp
index 2849c71..edb30c3 100644
--- a/sensors/builder.hpp
+++ b/sensors/builder.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <map>
-#include <memory>
#include <string>
#include "sensors/manager.hpp"
@@ -10,6 +9,6 @@
/**
* Build the sensors and associate them with a SensorManager.
*/
-std::shared_ptr<SensorManager> BuildSensors(
+SensorManager BuildSensors(
const std::map<std::string, struct sensor>& config);
diff --git a/sensors/builderconfig.cpp b/sensors/builderconfig.cpp
index b3507ae..f1d95a0 100644
--- a/sensors/builderconfig.cpp
+++ b/sensors/builderconfig.cpp
@@ -16,6 +16,8 @@
#include <iostream>
#include <libconfig.h++>
+#include <string>
+#include <unordered_map>
/* Configuration. */
#include "conf.hpp"
@@ -28,7 +30,7 @@
* parsing. I should just ditch the compile-time version to reduce the
* probability of sync bugs.
*/
-std::shared_ptr<SensorManager> BuildSensorsFromConfig(const std::string& path)
+SensorManager BuildSensorsFromConfig(const std::string& path)
{
using namespace libconfig;
diff --git a/sensors/builderconfig.hpp b/sensors/builderconfig.hpp
index 078f484..0948c69 100644
--- a/sensors/builderconfig.hpp
+++ b/sensors/builderconfig.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include <memory>
#include <string>
#include "sensors/manager.hpp"
@@ -9,4 +8,4 @@
* Given a configuration file, parsable by libconfig++, parse it and then pass
* the information onto BuildSensors.
*/
-std::shared_ptr<SensorManager> BuildSensorsFromConfig(const std::string& path);
+SensorManager BuildSensorsFromConfig(const std::string& path);
diff --git a/sensors/manager.hpp b/sensors/manager.hpp
index a3e7420..d37787a 100644
--- a/sensors/manager.hpp
+++ b/sensors/manager.hpp
@@ -17,15 +17,26 @@
class SensorManager
{
public:
- SensorManager()
- : _passiveListeningBus(std::move(sdbusplus::bus::new_default())),
- _hostSensorBus(std::move(sdbusplus::bus::new_default()))
+ SensorManager(sdbusplus::bus::bus&& pass, sdbusplus::bus::bus&& host)
+ : _passiveListeningBus(std::move(pass)),
+ _hostSensorBus(std::move(host))
{
- // Create a manager for the sensor root because we own it.
- static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
+ // manager gets its interface from the bus. :D
sdbusplus::server::manager::manager(_hostSensorBus, SensorRoot);
}
+ SensorManager()
+ : SensorManager(std::move(sdbusplus::bus::new_default()),
+ std::move(sdbusplus::bus::new_default()))
+ {
+ }
+
+ ~SensorManager() = default;
+ SensorManager(const SensorManager&) = delete;
+ SensorManager& operator=(const SensorManager&) = delete;
+ SensorManager(SensorManager&&) = default;
+ SensorManager& operator=(SensorManager&&) = default;
+
/*
* Add a Sensor to the Manager.
*/
@@ -35,7 +46,7 @@
std::unique_ptr<Sensor> sensor);
// TODO(venture): Should implement read/write by name.
- std::unique_ptr<Sensor>& getSensor(std::string name)
+ const std::unique_ptr<Sensor>& getSensor(const std::string& name) const
{
return _sensorMap.at(name);
}
@@ -56,5 +67,7 @@
sdbusplus::bus::bus _passiveListeningBus;
sdbusplus::bus::bus _hostSensorBus;
+
+ static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
};