dbus: Move findSensors to dbus util
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I2ba4d3c430200eb58cb4364dcce694a080531846
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index f9d7790..90c2472 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -30,7 +30,6 @@
#include <functional>
#include <iostream>
#include <list>
-#include <regex>
#include <set>
#include <unordered_map>
#include <variant>
@@ -88,22 +87,6 @@
return retString;
}
-bool findSensors(const std::unordered_map<std::string, std::string>& sensors,
- const std::string& search,
- std::vector<std::pair<std::string, std::string>>& matches)
-{
- std::smatch match;
- std::regex reg(search + '$');
- for (const auto& sensor : sensors)
- {
- if (std::regex_search(sensor.first, match, reg))
- {
- matches.push_back(sensor);
- }
- }
- return matches.size() > 0;
-}
-
// this function prints the configuration into a form similar to the cpp
// generated code to help in verification, should be turned off during normal
// use
diff --git a/dbus/dbusutil.cpp b/dbus/dbusutil.cpp
index 7545eed..6cdad14 100644
--- a/dbus/dbusutil.cpp
+++ b/dbus/dbusutil.cpp
@@ -4,9 +4,13 @@
#include <cstdint>
#include <iostream>
#include <map>
+#include <regex>
#include <set>
#include <string>
+#include <unordered_map>
+#include <utility>
#include <variant>
+#include <vector>
using Property = std::string;
using Value = std::variant<int64_t, double, std::string, bool>;
@@ -15,6 +19,22 @@
namespace pid_control
{
+bool findSensors(const std::unordered_map<std::string, std::string>& sensors,
+ const std::string& search,
+ std::vector<std::pair<std::string, std::string>>& matches)
+{
+ std::smatch match;
+ std::regex reg(search + '$');
+ for (const auto& sensor : sensors)
+ {
+ if (std::regex_search(sensor.first, match, reg))
+ {
+ matches.push_back(sensor);
+ }
+ }
+ return matches.size() > 0;
+}
+
std::string getSensorPath(const std::string& type, const std::string& id)
{
std::string layer = type;
diff --git a/dbus/dbusutil.hpp b/dbus/dbusutil.hpp
index 8bd2824..420c8fb 100644
--- a/dbus/dbusutil.hpp
+++ b/dbus/dbusutil.hpp
@@ -2,6 +2,9 @@
#include <stdexcept>
#include <string>
+#include <unordered_map>
+#include <utility>
+#include <vector>
namespace pid_control
{
@@ -28,4 +31,8 @@
void scaleSensorReading(const double min, const double max, double& value);
bool validType(const std::string& type);
+bool findSensors(const std::unordered_map<std::string, std::string>& sensors,
+ const std::string& search,
+ std::vector<std::pair<std::string, std::string>>& matches);
+
} // namespace pid_control