Add sensor object framework
Create a sensor object to store sensor monitoring specifications.
Tested:
Sensor objects are created and stored for each sensor
Change-Id: Idfa982f1bb8da888abbd473881870df4beec6824
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/mainloop.cpp b/mainloop.cpp
index 5243f3c..c7ede15 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -288,6 +288,8 @@
return {};
}
+ auto sensorObj = std::make_unique<sensor::Sensor>(sensor.first);
+
// Get list of return codes for removing sensors on device
auto devRmRCs = env::getEnv("REMOVERCS");
// Add sensor removal return codes defined at the device level
@@ -382,6 +384,9 @@
// and emit InterfacesAdded.
valueInterface->emit_object_added();
+ // Save sensor object specifications
+ sensorObjects[sensor.first] = std::move(sensorObj);
+
return std::make_pair(std::move(std::get<sensorLabel>(properties)),
std::move(info));
}
diff --git a/mainloop.hpp b/mainloop.hpp
index d420c28..c3ed161 100644
--- a/mainloop.hpp
+++ b/mainloop.hpp
@@ -6,19 +6,16 @@
#include <experimental/optional>
#include <memory>
#include <sdbusplus/server.hpp>
+#include "types.hpp"
#include "hwmonio.hpp"
#include "sensorset.hpp"
#include "sysfs.hpp"
#include "interface.hpp"
#include "timer.hpp"
+#include "sensor.hpp"
static constexpr auto default_interval = 1000000;
-using Object = std::map<InterfaceType, std::experimental::any>;
-using ObjectInfo = std::tuple<sdbusplus::bus::bus*, std::string, Object>;
-using RetryIO = std::tuple<size_t, std::chrono::milliseconds>;
-using ObjectStateData = std::pair<std::string, ObjectInfo>;
-
static constexpr auto sensorID = 0;
static constexpr auto sensorLabel = 1;
using SensorIdentifiers = std::tuple<std::string, std::string>;
@@ -108,6 +105,9 @@
std::unique_ptr<phosphor::hwmon::Timer> timer;
/** @brief the sd_event structure */
sd_event* loop = nullptr;
+ /** @brief Store the specifications of sensor objects */
+ std::map<SensorSet::key_type,
+ std::unique_ptr<sensor::Sensor>> sensorObjects;
/**
* @brief Map of removed sensors
diff --git a/sensor.cpp b/sensor.cpp
index cbcbfeb..5fb1f38 100644
--- a/sensor.cpp
+++ b/sensor.cpp
@@ -11,6 +11,11 @@
namespace sensor
{
+Sensor::Sensor(const SensorSet::key_type& sensor) :
+ sensor(sensor)
+{
+}
+
std::shared_ptr<StatusObject> addStatus(
const SensorSet::key_type& sensor,
const hwmonio::HwmonIO& ioAccess,
diff --git a/sensor.hpp b/sensor.hpp
index e22af0b..4d3dc3c 100644
--- a/sensor.hpp
+++ b/sensor.hpp
@@ -1,11 +1,40 @@
#pragma once
+#include "types.hpp"
#include "sensorset.hpp"
-#include "mainloop.hpp"
+#include "hwmonio.hpp"
namespace sensor
{
+/** @class Sensor
+ * @brief Sensor object based on a SensorSet container's key type
+ * @details Sensor object to create and modify an associated device's sensor
+ * attributes based on the key type of each sensor in the set provided by the
+ * device.
+ */
+class Sensor
+{
+ public:
+ Sensor() = delete;
+ Sensor(const Sensor&) = delete;
+ Sensor(Sensor&&) = default;
+ Sensor& operator=(const Sensor&) = delete;
+ Sensor& operator=(Sensor&&) = default;
+ ~Sensor() = default;
+
+ /**
+ * @brief Constructs Sensor object
+ *
+ * @param[in] sensor - A pair of sensor indentifiers
+ */
+ explicit Sensor(const SensorSet::key_type& sensor);
+
+ private:
+ /** @brief Sensor object's identifiers */
+ SensorSet::key_type sensor;
+};
+
/**
* @brief Add status interface and functional property for sensor
* @details When a sensor has an associated fault file, the OperationalStatus
diff --git a/types.hpp b/types.hpp
new file mode 100644
index 0000000..5d12e8c
--- /dev/null
+++ b/types.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <experimental/any>
+#include "interface.hpp"
+
+using Object = std::map<InterfaceType, std::experimental::any>;
+using ObjectInfo = std::tuple<sdbusplus::bus::bus*, std::string, Object>;
+using RetryIO = std::tuple<size_t, std::chrono::milliseconds>;
+using ObjectStateData = std::pair<std::string, ObjectInfo>;