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