blob: 1e72a6b45d7f27c044161ff4882ae1c131c4e19f [file] [log] [blame]
kasunath7cea1b92022-06-14 20:23:27 -07001#pragma once
2
kasunath3d0cd552022-08-25 20:22:58 -07003#include <sdbusplus/asio/object_server.hpp>
kasunath7cea1b92022-06-14 20:23:27 -07004#include <xyz/openbmc_project/Common/FilePath/server.hpp>
5
Patrick Williams5de90612024-02-13 21:31:53 -06006#include <format>
kasunath7cea1b92022-06-14 20:23:27 -07007#include <string>
8
9namespace bios_bmc_smm_error_logger
10{
11
kasunath7cea1b92022-06-14 20:23:27 -070012/**
13 * @brief A class for notifying file paths of CPER logs.
14 */
kasunath3d0cd552022-08-25 20:22:58 -070015class CperFileNotifier
kasunath7cea1b92022-06-14 20:23:27 -070016{
17 public:
18 /**
19 * @brief Constructor for the CperFileNotifier class.
20 *
kasunath3d0cd552022-08-25 20:22:58 -070021 * @param server - sdbusplus asio object server.
kasunath7cea1b92022-06-14 20:23:27 -070022 * @param filePath - full path of the CPER log JSON file.
23 * @param entry - index of the DBus file path object.
24 */
kasunath3d0cd552022-08-25 20:22:58 -070025 CperFileNotifier(sdbusplus::asio::object_server& server,
26 const std::string& filePath, uint64_t entry) :
27 server(server)
kasunath7cea1b92022-06-14 20:23:27 -070028 {
kasunath3d0cd552022-08-25 20:22:58 -070029 pathIface = server.add_interface(generatePath(entry).c_str(),
30 "xyz.openbmc_project.Common.FilePath");
31 pathIface->register_property("Path", filePath);
32 pathIface->initialize();
kasunath7cea1b92022-06-14 20:23:27 -070033 }
34
kasunath3d0cd552022-08-25 20:22:58 -070035 ~CperFileNotifier()
36 {
37 server.remove_interface(pathIface);
38 }
39
40 CperFileNotifier& operator=(const CperFileNotifier&) = delete;
41 CperFileNotifier& operator=(CperFileNotifier&&) = delete;
42 CperFileNotifier(const CperFileNotifier&) = delete;
43 CperFileNotifier(CperFileNotifier&&) = default;
44
kasunath7cea1b92022-06-14 20:23:27 -070045 static constexpr const char* cperBasePath =
46 "/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER";
47
48 private:
kasunath3d0cd552022-08-25 20:22:58 -070049 sdbusplus::asio::object_server& server;
50 std::shared_ptr<sdbusplus::asio::dbus_interface> pathIface;
51
kasunath7cea1b92022-06-14 20:23:27 -070052 /**
kasunath7cea1b92022-06-14 20:23:27 -070053 * @brief Generate a path for the CperFileNotifier DBus object.
54 *
55 * @param[in] entry - unique index for the DBus object.
56 */
57 std::string generatePath(uint64_t entry)
58 {
Patrick Williams5de90612024-02-13 21:31:53 -060059 return std::format("{}/entry{}", cperBasePath, entry);
kasunath7cea1b92022-06-14 20:23:27 -070060 }
61};
62
63} // namespace bios_bmc_smm_error_logger