Use proper dbus path when possible.
Following methods and properties were updated to use full dbus path,
instead of internal telemetry id:
- TriggerManager.AddTrigger() - 'reportIds' arg
- Trigger.ReportIds - renamed to 'Reports'
- Report.TriggerIds - renamed to 'Triggers'
Testing done:
- UTs were updated and are passing.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I78d812d38289fac575d25b48503cc8b9c6f736fe
diff --git a/src/utils/dbus_path_utils.hpp b/src/utils/dbus_path_utils.hpp
new file mode 100644
index 0000000..a1b5709
--- /dev/null
+++ b/src/utils/dbus_path_utils.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <sdbusplus/message.hpp>
+
+#include <algorithm>
+#include <ranges>
+#include <string_view>
+
+namespace utils
+{
+
+namespace constants
+{
+constexpr std::string_view triggerDirStr =
+ "/xyz/openbmc_project/Telemetry/Triggers/";
+constexpr std::string_view reportDirStr =
+ "/xyz/openbmc_project/Telemetry/Reports/";
+
+constexpr std::string_view allowedCharactersInPath =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_/";
+constexpr size_t maxPrefixesInId = 1;
+
+const sdbusplus::message::object_path triggerDirPath =
+ sdbusplus::message::object_path(std::string(triggerDirStr));
+const sdbusplus::message::object_path reportDirPath =
+ sdbusplus::message::object_path(std::string(reportDirStr));
+} // namespace constants
+
+inline bool isValidDbusPath(const std::string& path)
+{
+ return (path.find_first_not_of(constants::allowedCharactersInPath) ==
+ std::string::npos) &&
+ !path.ends_with('/');
+}
+
+sdbusplus::message::object_path pathAppend(sdbusplus::message::object_path path,
+ const std::string& appended);
+
+std::string reportPathToId(const sdbusplus::message::object_path& path);
+
+} // namespace utils