Move the sensor utils into their own module
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I22f6a951921095660fd2be502e59a38161565a95
diff --git a/Makefile.am b/Makefile.am
index 2daf76f..edbebfa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -56,7 +56,7 @@
$(PHOSPHOR_LOGGING_CFLAGS) \
$(CODE_COVERAGE_CXXFLAGS)
-swampd_SOURCES = main.cpp util.cpp
+swampd_SOURCES = main.cpp
swampd_LDADD = \
$(SDBUSPLUS_LIBS) \
libswampd.la
@@ -94,6 +94,7 @@
sensors/builder.cpp \
sensors/buildjson.cpp \
sensors/manager.cpp \
+ sensors/build_utils.cpp \
pid/ec/pid.cpp \
pid/ec/stepwise.cpp \
pid/fancontroller.cpp \
diff --git a/util.cpp b/sensors/build_utils.cpp
similarity index 94%
rename from util.cpp
rename to sensors/build_utils.cpp
index ec60d7a..c3c7ce1 100644
--- a/util.cpp
+++ b/sensors/build_utils.cpp
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-#include "util.hpp"
+#include "build_utils.hpp"
-#include <string>
+namespace pid_control
+{
static constexpr auto external_sensor =
"/xyz/openbmc_project/extsensors/"; // type/
@@ -68,3 +69,5 @@
return IOInterfaceType::UNKNOWN;
}
+
+} // namespace pid_control
diff --git a/sensors/build_utils.hpp b/sensors/build_utils.hpp
new file mode 100644
index 0000000..bb2b41c
--- /dev/null
+++ b/sensors/build_utils.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <string>
+
+namespace pid_control
+{
+
+/* This program assumes sensors use the Sensor.Value interface
+ * and for sensor->write() I only implemented sysfs as a type,
+ * but -- how would it know whether to use Control.FanSpeed or Control.FanPwm?
+ *
+ * One could get the interface list for the object and search for Control.*
+ * but, it needs to know the maximum, minimum. The only sensors it wants to
+ * write in this code base are Fans...
+ */
+enum class IOInterfaceType
+{
+ NONE, // There is no interface.
+ EXTERNAL,
+ DBUSPASSIVE,
+ DBUSACTIVE, // This means for write that it needs to look up the interface.
+ SYSFS,
+ UNKNOWN
+};
+
+/* WriteInterfaceType is different because Dbusactive/passive. how to know... */
+IOInterfaceType getWriteInterfaceType(const std::string& path);
+
+IOInterfaceType getReadInterfaceType(const std::string& path);
+
+} // namespace pid_control
diff --git a/sensors/builder.cpp b/sensors/builder.cpp
index 4da1cf2..1cea61a 100644
--- a/sensors/builder.cpp
+++ b/sensors/builder.cpp
@@ -26,6 +26,7 @@
#include "interfaces.hpp"
#include "notimpl/readonly.hpp"
#include "notimpl/writeonly.hpp"
+#include "sensors/build_utils.hpp"
#include "sensors/builder.hpp"
#include "sensors/host.hpp"
#include "sensors/manager.hpp"
@@ -37,6 +38,10 @@
static constexpr bool deferSignals = true;
static DbusHelper helper;
+using ::pid_control::getReadInterfaceType;
+using ::pid_control::getWriteInterfaceType;
+using ::pid_control::IOInterfaceType;
+
SensorManager
buildSensors(const std::map<std::string, struct conf::SensorConfig>& config,
sdbusplus::bus::bus& passive, sdbusplus::bus::bus& host)
diff --git a/test/Makefile.am b/test/Makefile.am
index 3d74c88..0703f73 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -40,7 +40,7 @@
sensor_host_unittest_LDADD = $(top_builddir)/sensors/host.o
util_unittest_SOURCES = util_unittest.cpp
-util_unittest_LDADD = $(top_builddir)/util.o
+util_unittest_LDADD = $(top_builddir)/sensors/build_utils.o
pid_zone_unittest_SOURCES = pid_zone_unittest.cpp
pid_zone_unittest_LDADD = $(top_builddir)/pid/ec/pid.o \
diff --git a/test/util_unittest.cpp b/test/util_unittest.cpp
index 6e5e548..457c470 100644
--- a/test/util_unittest.cpp
+++ b/test/util_unittest.cpp
@@ -1,10 +1,15 @@
-#include "util.hpp"
+#include "sensors/build_utils.hpp"
#include <string>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+namespace pid_control
+{
+namespace
+{
+
TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE)
{
// Verify it responds to an empty string.
@@ -80,3 +85,6 @@
std::string path = "asdf09as0df9a0fd";
EXPECT_EQ(IOInterfaceType::UNKNOWN, getReadInterfaceType(path));
}
+
+} // namespace
+} // namespace pid_control
diff --git a/util.hpp b/util.hpp
index 4a2c2c3..7930dba 100644
--- a/util.hpp
+++ b/util.hpp
@@ -8,29 +8,6 @@
#include <limits>
#include <string>
-/* This program assumes sensors use the Sensor.Value interface
- * and for sensor->write() I only implemented sysfs as a type,
- * but -- how would it know whether to use Control.FanSpeed or Control.FanPwm?
- *
- * One could get the interface list for the object and search for Control.*
- * but, it needs to know the maximum, minimum. The only sensors it wants to
- * write in this code base are Fans...
- */
-enum class IOInterfaceType
-{
- NONE, // There is no interface.
- EXTERNAL,
- DBUSPASSIVE,
- DBUSACTIVE, // This means for write that it needs to look up the interface.
- SYSFS,
- UNKNOWN
-};
-
-/* WriteInterfaceType is different because Dbusactive/passive. how to know... */
-IOInterfaceType getWriteInterfaceType(const std::string& path);
-
-IOInterfaceType getReadInterfaceType(const std::string& path);
-
void tryRestartControlLoops(void);
/*