1 #pragma once
2 
3 #include <fmt/format.h>
4 
5 #include <sdbusplus/server.hpp>
6 #include <xyz/openbmc_project/Common/FilePath/server.hpp>
7 
8 #include <string>
9 
10 namespace bios_bmc_smm_error_logger
11 {
12 
13 using FileNotifierInterface = sdbusplus::server::object_t<
14     sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
15 
16 /**
17  * @brief A class for notifying file paths of CPER logs.
18  */
19 class CperFileNotifier : public FileNotifierInterface
20 {
21   public:
22     /**
23      * @brief Constructor for the CperFileNotifier class.
24      *
25      * @param bus - bus to attach to.
26      * @param filePath - full path of the CPER log JSON file.
27      * @param entry - index of the DBus file path object.
28      */
29     CperFileNotifier(sdbusplus::bus_t& bus, const std::string& filePath,
30                      uint64_t entry) :
31         FileNotifierInterface(bus, generatePath(entry).c_str(),
32                               action::emit_no_signals),
33         entry(entry), bus(bus)
34     {
35         // We only need the interface added signal for the fault monitor. So
36         // stop emitting properties changed signal.
37         path(filePath, /*skipSignal=*/true);
38     }
39 
40     static constexpr const char* cperBasePath =
41         "/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER";
42 
43   private:
44     /**
45      * @brief DBus index of the entry.
46      */
47     uint64_t entry;
48 
49     sdbusplus::bus_t& bus;
50 
51     /**
52      * @brief Generate a path for the CperFileNotifier DBus object.
53      *
54      * @param[in] entry - unique index for the DBus object.
55      */
56     std::string generatePath(uint64_t entry)
57     {
58         return fmt::format("{}/entry{}", cperBasePath, entry);
59     }
60 };
61 
62 } // namespace bios_bmc_smm_error_logger
63