Consolidate all util.hpp
This deletes all lower level util.hpp and cats them
into the top level util.hpp to avoid name conflicts.
Change-Id: Ia11e4a08053a3970b0aadf21d1156ab26def36bd
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/dbus/dbusactiveread.cpp b/dbus/dbusactiveread.cpp
index c444ad2..406b391 100644
--- a/dbus/dbusactiveread.cpp
+++ b/dbus/dbusactiveread.cpp
@@ -16,7 +16,7 @@
#include "dbusactiveread.hpp"
-#include "dbus/util.hpp"
+#include "util.hpp"
#include <chrono>
#include <cmath>
diff --git a/dbus/dbusactiveread.hpp b/dbus/dbusactiveread.hpp
index b703006..235f038 100644
--- a/dbus/dbusactiveread.hpp
+++ b/dbus/dbusactiveread.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include "dbus/util.hpp"
#include "interfaces.hpp"
+#include "util.hpp"
#include <memory>
#include <sdbusplus/bus.hpp>
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index e0c9f3d..2c9bbc2 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -15,7 +15,7 @@
*/
#include "conf.hpp"
-#include "dbus/util.hpp"
+#include "util.hpp"
#include <algorithm>
#include <chrono>
diff --git a/dbus/dbuspassive.cpp b/dbus/dbuspassive.cpp
index ee165b9..a154b02 100644
--- a/dbus/dbuspassive.cpp
+++ b/dbus/dbuspassive.cpp
@@ -15,7 +15,7 @@
*/
#include "dbuspassive.hpp"
-#include "dbus/util.hpp"
+#include "util.hpp"
#include <chrono>
#include <cmath>
diff --git a/dbus/dbuspassive.hpp b/dbus/dbuspassive.hpp
index 8cff245..ebc831d 100644
--- a/dbus/dbuspassive.hpp
+++ b/dbus/dbuspassive.hpp
@@ -1,8 +1,8 @@
#pragma once
#include "conf.hpp"
-#include "dbus/util.hpp"
#include "interfaces.hpp"
+#include "util.hpp"
#include <chrono>
#include <cmath>
diff --git a/dbus/dbuswrite.hpp b/dbus/dbuswrite.hpp
index 6f5b85b..757ea9b 100644
--- a/dbus/dbuswrite.hpp
+++ b/dbus/dbuswrite.hpp
@@ -16,8 +16,8 @@
#pragma once
-#include "dbus/util.hpp"
#include "interfaces.hpp"
+#include "util.hpp"
#include <memory>
#include <sdbusplus/bus.hpp>
diff --git a/dbus/util.cpp b/dbus/util.cpp
index b5b22f4..6d5d2c0 100644
--- a/dbus/util.cpp
+++ b/dbus/util.cpp
@@ -1,4 +1,4 @@
-#include "dbus/util.hpp"
+#include "util.hpp"
#include <cmath>
#include <iostream>
@@ -192,4 +192,4 @@
return;
}
value /= (max - min);
-}
\ No newline at end of file
+}
diff --git a/dbus/util.hpp b/dbus/util.hpp
deleted file mode 100644
index 69a8112..0000000
--- a/dbus/util.hpp
+++ /dev/null
@@ -1,106 +0,0 @@
-#pragma once
-
-#include <limits>
-#include <sdbusplus/bus.hpp>
-
-struct SensorProperties
-{
- int64_t scale;
- double value;
- double min;
- double max;
- std::string unit;
-};
-
-struct SensorThresholds
-{
- double lowerThreshold = std::numeric_limits<double>::quiet_NaN();
- double upperThreshold = std::numeric_limits<double>::quiet_NaN();
-};
-
-const std::string sensorintf = "xyz.openbmc_project.Sensor.Value";
-const std::string criticalThreshInf =
- "xyz.openbmc_project.Sensor.Threshold.Critical";
-const std::string propertiesintf = "org.freedesktop.DBus.Properties";
-
-class DbusHelperInterface
-{
- public:
- virtual ~DbusHelperInterface() = default;
-
- /** @brief Get the service providing the interface for the path.
- *
- * @warning Throws exception on dbus failure.
- */
- virtual std::string getService(sdbusplus::bus::bus& bus,
- const std::string& intf,
- const std::string& path) = 0;
-
- /** @brief Get all Sensor.Value properties for a service and path.
- *
- * @param[in] bus - A bus to use for the call.
- * @param[in] service - The service providing the interface.
- * @param[in] path - The dbus path.
- * @param[out] prop - A pointer to a properties struct to fill out.
- *
- * @warning Throws exception on dbus failure.
- */
- virtual void getProperties(sdbusplus::bus::bus& bus,
- const std::string& service,
- const std::string& path,
- struct SensorProperties* prop) = 0;
-
- /** @brief Get Critical Threshold current assert status
- *
- * @param[in] bus - A bus to use for the call.
- * @param[in] service - The service providing the interface.
- * @param[in] path - The dbus path.
- */
- virtual bool thresholdsAsserted(sdbusplus::bus::bus& bus,
- const std::string& service,
- const std::string& path) = 0;
-};
-
-class DbusHelper : public DbusHelperInterface
-{
- public:
- DbusHelper() = default;
- ~DbusHelper() = default;
- DbusHelper(const DbusHelper&) = default;
- DbusHelper& operator=(const DbusHelper&) = default;
- DbusHelper(DbusHelper&&) = default;
- DbusHelper& operator=(DbusHelper&&) = default;
-
- std::string getService(sdbusplus::bus::bus& bus, const std::string& intf,
- const std::string& path) override;
-
- void getProperties(sdbusplus::bus::bus& bus, const std::string& service,
- const std::string& path,
- struct SensorProperties* prop) override;
-
- bool thresholdsAsserted(sdbusplus::bus::bus& bus,
- const std::string& service,
- const std::string& path) override;
-};
-
-std::string getSensorPath(const std::string& type, const std::string& id);
-std::string getMatch(const std::string& type, const std::string& id);
-void scaleSensorReading(const double min, const double max, double& value);
-bool validType(const std::string& type);
-
-struct VariantToDoubleVisitor
-{
- template <typename T>
- std::enable_if_t<std::is_arithmetic<T>::value, double>
- operator()(const T& t) const
- {
- return static_cast<double>(t);
- }
-
- template <typename T>
- std::enable_if_t<!std::is_arithmetic<T>::value, double>
- operator()(const T& t) const
- {
- throw std::invalid_argument("Cannot translate type to double");
- }
-};
diff --git a/pid/util.cpp b/pid/util.cpp
index 5c6e5d4..0a8f892 100644
--- a/pid/util.cpp
+++ b/pid/util.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "util.hpp"
+
#include "ec/pid.hpp"
#include <cstring>
diff --git a/pid/util.hpp b/pid/util.hpp
deleted file mode 100644
index c35f0b8..0000000
--- a/pid/util.hpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-#include "ec/pid.hpp"
-
-/*
- * Given a configuration structure, fill out the information we use within the
- * PID loop.
- */
-void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial);
-
-void dumpPIDStruct(ec::pid_info_t* info);
diff --git a/sysfs/sysfsread.hpp b/sysfs/sysfsread.hpp
index 4cd2a78..aa769c4 100644
--- a/sysfs/sysfsread.hpp
+++ b/sysfs/sysfsread.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "interfaces.hpp"
-#include "sysfs/util.hpp"
+#include "util.hpp"
#include <string>
diff --git a/sysfs/sysfswrite.hpp b/sysfs/sysfswrite.hpp
index f877d4a..990855e 100644
--- a/sysfs/sysfswrite.hpp
+++ b/sysfs/sysfswrite.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "interfaces.hpp"
-#include "sysfs/util.hpp"
+#include "util.hpp"
#include <string>
diff --git a/sysfs/util.cpp b/sysfs/util.cpp
index d73ec0f..da678ce 100644
--- a/sysfs/util.cpp
+++ b/sysfs/util.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "sysfs/util.hpp"
+#include "util.hpp"
#include <filesystem>
#include <iostream>
diff --git a/sysfs/util.hpp b/sysfs/util.hpp
deleted file mode 100644
index 2d4c274..0000000
--- a/sysfs/util.hpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <string>
-
-/*
- * Given a path that optionally has a glob portion, fill it out.
- */
-std::string FixupPath(std::string original);
diff --git a/test/dbushelper_mock.hpp b/test/dbushelper_mock.hpp
index e373f8a..62e88f1 100644
--- a/test/dbushelper_mock.hpp
+++ b/test/dbushelper_mock.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "dbus/util.hpp"
+#include "util.hpp"
#include <sdbusplus/bus.hpp>
#include <string>
diff --git a/util.hpp b/util.hpp
index fdc7772..729eaf7 100644
--- a/util.hpp
+++ b/util.hpp
@@ -1,5 +1,9 @@
#pragma once
+#include "pid/ec/pid.hpp"
+
+#include <limits>
+#include <sdbusplus/bus.hpp>
#include <string>
/* This program assumes sensors use the Sensor.Value interface
@@ -24,3 +28,118 @@
IOInterfaceType getWriteInterfaceType(const std::string& path);
IOInterfaceType getReadInterfaceType(const std::string& path);
+
+/*
+ * Given a configuration structure, fill out the information we use within the
+ * PID loop.
+ */
+void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial);
+
+void dumpPIDStruct(ec::pid_info_t* info);
+
+struct SensorProperties
+{
+ int64_t scale;
+ double value;
+ double min;
+ double max;
+ std::string unit;
+};
+
+struct SensorThresholds
+{
+ double lowerThreshold = std::numeric_limits<double>::quiet_NaN();
+ double upperThreshold = std::numeric_limits<double>::quiet_NaN();
+};
+
+const std::string sensorintf = "xyz.openbmc_project.Sensor.Value";
+const std::string criticalThreshInf =
+ "xyz.openbmc_project.Sensor.Threshold.Critical";
+const std::string propertiesintf = "org.freedesktop.DBus.Properties";
+
+class DbusHelperInterface
+{
+ public:
+ virtual ~DbusHelperInterface() = default;
+
+ /** @brief Get the service providing the interface for the path.
+ *
+ * @warning Throws exception on dbus failure.
+ */
+ virtual std::string getService(sdbusplus::bus::bus& bus,
+ const std::string& intf,
+ const std::string& path) = 0;
+
+ /** @brief Get all Sensor.Value properties for a service and path.
+ *
+ * @param[in] bus - A bus to use for the call.
+ * @param[in] service - The service providing the interface.
+ * @param[in] path - The dbus path.
+ * @param[out] prop - A pointer to a properties struct to fill out.
+ *
+ * @warning Throws exception on dbus failure.
+ */
+ virtual void getProperties(sdbusplus::bus::bus& bus,
+ const std::string& service,
+ const std::string& path,
+ struct SensorProperties* prop) = 0;
+
+ /** @brief Get Critical Threshold current assert status
+ *
+ * @param[in] bus - A bus to use for the call.
+ * @param[in] service - The service providing the interface.
+ * @param[in] path - The dbus path.
+ */
+ virtual bool thresholdsAsserted(sdbusplus::bus::bus& bus,
+ const std::string& service,
+ const std::string& path) = 0;
+};
+
+class DbusHelper : public DbusHelperInterface
+{
+ public:
+ DbusHelper() = default;
+ ~DbusHelper() = default;
+ DbusHelper(const DbusHelper&) = default;
+ DbusHelper& operator=(const DbusHelper&) = default;
+ DbusHelper(DbusHelper&&) = default;
+ DbusHelper& operator=(DbusHelper&&) = default;
+
+ std::string getService(sdbusplus::bus::bus& bus, const std::string& intf,
+ const std::string& path) override;
+
+ void getProperties(sdbusplus::bus::bus& bus, const std::string& service,
+ const std::string& path,
+ struct SensorProperties* prop) override;
+
+ bool thresholdsAsserted(sdbusplus::bus::bus& bus,
+ const std::string& service,
+ const std::string& path) override;
+};
+
+std::string getSensorPath(const std::string& type, const std::string& id);
+std::string getMatch(const std::string& type, const std::string& id);
+void scaleSensorReading(const double min, const double max, double& value);
+bool validType(const std::string& type);
+
+struct VariantToDoubleVisitor
+{
+ template <typename T>
+ std::enable_if_t<std::is_arithmetic<T>::value, double>
+ operator()(const T& t) const
+ {
+ return static_cast<double>(t);
+ }
+
+ template <typename T>
+ std::enable_if_t<!std::is_arithmetic<T>::value, double>
+ operator()(const T& t) const
+ {
+ throw std::invalid_argument("Cannot translate type to double");
+ }
+};
+
+/*
+ * Given a path that optionally has a glob portion, fill it out.
+ */
+std::string FixupPath(std::string original);