kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
kasunath | 3d0cd55 | 2022-08-25 20:22:58 -0700 | [diff] [blame] | 3 | #include <sdbusplus/asio/object_server.hpp> |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 4 | #include <xyz/openbmc_project/Common/FilePath/server.hpp> |
| 5 | |
Patrick Williams | 5de9061 | 2024-02-13 21:31:53 -0600 | [diff] [blame] | 6 | #include <format> |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 7 | #include <string> |
| 8 | |
| 9 | namespace bios_bmc_smm_error_logger |
| 10 | { |
| 11 | |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 12 | /** |
| 13 | * @brief A class for notifying file paths of CPER logs. |
| 14 | */ |
kasunath | 3d0cd55 | 2022-08-25 20:22:58 -0700 | [diff] [blame] | 15 | class CperFileNotifier |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 16 | { |
| 17 | public: |
| 18 | /** |
| 19 | * @brief Constructor for the CperFileNotifier class. |
| 20 | * |
kasunath | 3d0cd55 | 2022-08-25 20:22:58 -0700 | [diff] [blame] | 21 | * @param server - sdbusplus asio object server. |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 22 | * @param filePath - full path of the CPER log JSON file. |
| 23 | * @param entry - index of the DBus file path object. |
| 24 | */ |
kasunath | 3d0cd55 | 2022-08-25 20:22:58 -0700 | [diff] [blame] | 25 | CperFileNotifier(sdbusplus::asio::object_server& server, |
| 26 | const std::string& filePath, uint64_t entry) : |
| 27 | server(server) |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 28 | { |
kasunath | 3d0cd55 | 2022-08-25 20:22:58 -0700 | [diff] [blame] | 29 | pathIface = server.add_interface(generatePath(entry).c_str(), |
| 30 | "xyz.openbmc_project.Common.FilePath"); |
| 31 | pathIface->register_property("Path", filePath); |
| 32 | pathIface->initialize(); |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 33 | } |
| 34 | |
kasunath | 3d0cd55 | 2022-08-25 20:22:58 -0700 | [diff] [blame] | 35 | ~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 | |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 45 | static constexpr const char* cperBasePath = |
| 46 | "/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER"; |
| 47 | |
| 48 | private: |
kasunath | 3d0cd55 | 2022-08-25 20:22:58 -0700 | [diff] [blame] | 49 | sdbusplus::asio::object_server& server; |
| 50 | std::shared_ptr<sdbusplus::asio::dbus_interface> pathIface; |
| 51 | |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 52 | /** |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 53 | * @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 Williams | 5de9061 | 2024-02-13 21:31:53 -0600 | [diff] [blame] | 59 | return std::format("{}/entry{}", cperBasePath, entry); |
kasunath | 7cea1b9 | 2022-06-14 20:23:27 -0700 | [diff] [blame] | 60 | } |
| 61 | }; |
| 62 | |
| 63 | } // namespace bios_bmc_smm_error_logger |