1 #pragma once
2 
3 #include "dump_manager.hpp"
4 
5 #include <fmt/core.h>
6 
7 #include <phosphor-logging/elog-errors.hpp>
8 #include <phosphor-logging/elog.hpp>
9 #include <sdbusplus/bus.hpp>
10 #include <sdbusplus/server/object.hpp>
11 #include <xyz/openbmc_project/Dump/Create/server.hpp>
12 
13 namespace phosphor
14 {
15 namespace dump
16 {
17 namespace faultlog
18 {
19 
20 using namespace phosphor::logging;
21 
22 using CreateIface = sdbusplus::server::object_t<
23     sdbusplus::xyz::openbmc_project::Dump::server::Create>;
24 
25 /** @class Manager
26  *  @brief FaultLog Dump manager implementation.
27  */
28 class Manager :
29     virtual public CreateIface,
30     virtual public phosphor::dump::Manager
31 {
32   public:
33     Manager() = delete;
34     Manager(const Manager&) = default;
35     Manager& operator=(const Manager&) = delete;
36     Manager(Manager&&) = delete;
37     Manager& operator=(Manager&&) = delete;
38     virtual ~Manager() = default;
39 
40     /** @brief Constructor to put object onto bus at a dbus path.
41      *  @param[in] bus - Bus to attach to.
42      *  @param[in] path - Path to attach at.
43      *  @param[in] baseEntryPath - Base path for dump entry.
44      *  @param[in] filePath - Path where the dumps are stored.
45      */
46     Manager(sdbusplus::bus_t& bus, const char* path,
47             const std::string& baseEntryPath, const char* filePath) :
48         CreateIface(bus, path),
49         phosphor::dump::Manager(bus, path, baseEntryPath), dumpDir(filePath)
50     {
51         std::error_code ec;
52 
53         std::filesystem::create_directory(FAULTLOG_DUMP_PATH, ec);
54 
55         if (ec)
56         {
57             log<level::ERR>(fmt::format("dump_manager_faultlog directory {} "
58                                         "not created. error_code = {} ({})",
59                                         FAULTLOG_DUMP_PATH, ec.value(),
60                                         ec.message())
61                                 .c_str());
62         }
63     }
64 
65     void restore() override
66     {
67         // TODO phosphor-debug-collector/issues/21: Restore fault log entries
68         // after service restart
69         log<level::INFO>("dump_manager_faultlog restore not implemented");
70     }
71 
72     /** @brief Method to create a new fault log dump entry
73      *  @param[in] params - Key-value pair input parameters
74      *
75      *  @return object_path - The path to the new dump entry.
76      */
77     sdbusplus::message::object_path
78         createDump(phosphor::dump::DumpCreateParams params) override;
79 
80   private:
81     /** @brief Path to the dump file*/
82     std::string dumpDir;
83 };
84 
85 } // namespace faultlog
86 } // namespace dump
87 } // namespace phosphor
88