xref: /openbmc/phosphor-debug-collector/dump_manager_faultlog.hpp (revision 4207adcd7d82406294abf6a3dc6b635a3e23668e)
1 #pragma once
2 
3 #include "config.h"
4 
5 #include "dump_manager.hpp"
6 
7 #include <phosphor-logging/elog-errors.hpp>
8 #include <phosphor-logging/elog.hpp>
9 #include <phosphor-logging/lg2.hpp>
10 #include <sdbusplus/bus.hpp>
11 #include <sdbusplus/server/object.hpp>
12 #include <xyz/openbmc_project/Dump/Create/server.hpp>
13 
14 namespace phosphor
15 {
16 namespace dump
17 {
18 namespace faultlog
19 {
20 
21 using CreateIface = sdbusplus::server::object_t<
22     sdbusplus::xyz::openbmc_project::Dump::server::Create>;
23 
24 /** @class Manager
25  *  @brief FaultLog Dump manager implementation.
26  */
27 class Manager :
28     virtual public CreateIface,
29     virtual public phosphor::dump::Manager
30 {
31   public:
32     Manager() = delete;
33     Manager(const Manager&) = delete;
34     Manager& operator=(const Manager&) = delete;
35     Manager(Manager&&) = delete;
36     Manager& operator=(Manager&&) = delete;
37     virtual ~Manager() = default;
38 
39     /** @brief Constructor to put object onto bus at a dbus path.
40      *  @param[in] bus - Bus to attach to.
41      *  @param[in] path - Path to attach at.
42      *  @param[in] baseEntryPath - Base path for dump entry.
43      *  @param[in] filePath - Path where the dumps are stored.
44      */
Manager(sdbusplus::bus_t & bus,const char * path,const std::string & baseEntryPath,const char * filePath)45     Manager(sdbusplus::bus_t& bus, const char* path,
46             const std::string& baseEntryPath, const char* filePath) :
47         CreateIface(bus, path),
48         phosphor::dump::Manager(bus, path, baseEntryPath), dumpDir(filePath)
49     {
50         std::error_code ec;
51 
52         std::filesystem::create_directory(FAULTLOG_DUMP_PATH, ec);
53 
54         if (ec)
55         {
56             auto dir = FAULTLOG_DUMP_PATH;
57             lg2::error(
58                 "dump_manager_faultlog directory {DIRECTORY} not created. "
59                 "error_code = {ERRNO} ({ERROR_MESSAGE})",
60                 "DIRECTORY", dir, "ERRNO", ec.value(), "ERROR_MESSAGE",
61                 ec.message());
62         }
63     }
64 
restore()65     void restore() override
66     {
67         // TODO phosphor-debug-collector/issues/21: Restore fault log entries
68         // after service restart
69         lg2::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 createDump(
78         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