Add a class to create FilePath DBus objects
bios-bmc-smm-error-logger creates JSON entries for CPER logs received
from BIOS. When a new CPER log is created, fault log service has to be
notified.
This adds the necessary classes for publishing file paths of the newly
created CPER logs to DBus.
Tested:
Tested this on a real machine.
Eg DBus objects:
`-/xyz
`-/xyz/openbmc_project
`-/xyz/openbmc_project/external_storer
`-/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger
`-/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER
|-/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER/entry0
|-/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER/entry1
Signed-off-by: Kasun Athukorala <kasunath@google.com>
Change-Id: I8c35243c949dfdc1254a758136d7a8e204f58bf5
diff --git a/include/dbus/file_notifier.hpp b/include/dbus/file_notifier.hpp
new file mode 100644
index 0000000..16b61b8
--- /dev/null
+++ b/include/dbus/file_notifier.hpp
@@ -0,0 +1,62 @@
+#pragma once
+
+#include <fmt/format.h>
+
+#include <sdbusplus/server.hpp>
+#include <xyz/openbmc_project/Common/FilePath/server.hpp>
+
+#include <string>
+
+namespace bios_bmc_smm_error_logger
+{
+
+using FileNotifierInterface = sdbusplus::server::object_t<
+ sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
+
+/**
+ * @brief A class for notifying file paths of CPER logs.
+ */
+class CperFileNotifier : public FileNotifierInterface
+{
+ public:
+ /**
+ * @brief Constructor for the CperFileNotifier class.
+ *
+ * @param bus - bus to attach to.
+ * @param filePath - full path of the CPER log JSON file.
+ * @param entry - index of the DBus file path object.
+ */
+ CperFileNotifier(sdbusplus::bus::bus& bus, const std::string& filePath,
+ uint64_t entry) :
+ FileNotifierInterface(bus, generatePath(entry).c_str(),
+ action::emit_no_signals),
+ entry(entry), bus(bus)
+ {
+ // We only need the interface added signal for the fault monitor. So
+ // stop emitting properties changed signal.
+ path(filePath, /*skipSignal=*/true);
+ }
+
+ static constexpr const char* cperBasePath =
+ "/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER";
+
+ private:
+ /**
+ * @brief DBus index of the entry.
+ */
+ uint64_t entry;
+
+ sdbusplus::bus::bus& bus;
+
+ /**
+ * @brief Generate a path for the CperFileNotifier DBus object.
+ *
+ * @param[in] entry - unique index for the DBus object.
+ */
+ std::string generatePath(uint64_t entry)
+ {
+ return fmt::format("{}/entry{}", cperBasePath, entry);
+ }
+};
+
+} // namespace bios_bmc_smm_error_logger
diff --git a/include/rde/notifier_dbus_handler.hpp b/include/rde/notifier_dbus_handler.hpp
new file mode 100644
index 0000000..efcbd86
--- /dev/null
+++ b/include/rde/notifier_dbus_handler.hpp
@@ -0,0 +1,49 @@
+#pragma once
+
+#include "dbus/file_notifier.hpp"
+
+#include <memory>
+#include <vector>
+
+namespace bios_bmc_smm_error_logger
+{
+namespace rde
+{
+
+/**
+ * @brief A class to handle CPER DBus notification objects.
+ */
+class CperFileNotifierHandler
+{
+ public:
+ /**
+ * @brief Constructor for the CperFileNotifierHandler class.
+ *
+ * @param bus - bus to attache to.
+ */
+ explicit CperFileNotifierHandler(sdbusplus::bus::bus& bus);
+
+ /**
+ * @brief Create a DBus object with the provided filePath value.
+ *
+ * @param filePath - file path of the CPER log JSON file.
+ */
+ void createEntry(const std::string& filePath);
+
+ private:
+ sdbusplus::bus::bus& bus;
+ sdbusplus::server::manager::manager objManager;
+
+ /**
+ * @brief A vector to keep track of DBus FilePath objects.
+ */
+ std::vector<std::unique_ptr<CperFileNotifier>> notifierObjs;
+
+ /**
+ * @brief DBus index of the next entry.
+ */
+ uint64_t nextEntry = 0;
+};
+
+} // namespace rde
+} // namespace bios_bmc_smm_error_logger
diff --git a/src/rde/meson.build b/src/rde/meson.build
index c6831e2..1f13f18 100644
--- a/src/rde/meson.build
+++ b/src/rde/meson.build
@@ -1,14 +1,18 @@
-libbej_dep = dependency('libbej')
-
rde_pre = declare_dependency(
include_directories: [rde_inc],
- dependencies: [libbej_dep])
+ dependencies: [
+ dependency('libbej'),
+ dependency('phosphor-dbus-interfaces'),
+ dependency('sdbusplus'),
+ ]
+)
rde_lib = static_library(
'rde',
'rde_dictionary_manager.cpp',
'external_storer_file.cpp',
'rde_handler.cpp',
+ 'notifier_dbus_handler.cpp',
implicit_include_directories: false,
dependencies: rde_pre)
diff --git a/src/rde/notifier_dbus_handler.cpp b/src/rde/notifier_dbus_handler.cpp
new file mode 100644
index 0000000..c7bf310
--- /dev/null
+++ b/src/rde/notifier_dbus_handler.cpp
@@ -0,0 +1,22 @@
+#include "rde/notifier_dbus_handler.hpp"
+
+namespace bios_bmc_smm_error_logger
+{
+namespace rde
+{
+
+CperFileNotifierHandler::CperFileNotifierHandler(sdbusplus::bus::bus& bus) :
+ bus(bus), objManager(bus, CperFileNotifier::cperBasePath)
+{}
+
+void CperFileNotifierHandler::createEntry(const std::string& filePath)
+{
+ auto obj = std::make_unique<CperFileNotifier>(bus, filePath, nextEntry);
+ // Notify fault log monitor through InterfacesAdded signal.
+ obj->emit_added();
+ notifierObjs.push_back(std::move(obj));
+ ++nextEntry;
+}
+
+} // namespace rde
+} // namespace bios_bmc_smm_error_logger