blob: 3bbcf3eb080020fa2fdeef5cef66229a937155e3 [file] [log] [blame]
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/server/object.hpp>
5#include <xyz/openbmc_project/Dump/Create/server.hpp>
6#include <experimental/filesystem>
7
8#include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
9#include "dump_entry.hpp"
10
11namespace phosphor
12{
13namespace dump
14{
15namespace internal
16{
17
18class Manager;
19
20} // namespace internal
21
22namespace fs = std::experimental::filesystem;
23using Type =
24 sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type;
25
26using CreateIface = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Dump::server::Create>;
28
29/* Need a custom deleter for freeing up sd_event */
30struct EventDeleter
31{
32 void operator()(sd_event* event) const
33 {
34 event = sd_event_unref(event);
35 }
36};
37using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
38
39/** @class Manager
40 * @brief OpenBMC Dump manager implementation.
41 * @details A concrete implementation for the
42 * xyz.openbmc_project.Dump.Create DBus API.
43 */
44class Manager : public CreateIface
45{
46 friend class internal::Manager;
47 friend class Entry;
48
49 public:
50 Manager() = delete;
51 Manager(const Manager&) = default;
52 Manager& operator=(const Manager&) = delete;
53 Manager(Manager&&) = delete;
54 Manager& operator=(Manager&&) = delete;
55 virtual ~Manager() = default;
56
57 /** @brief Constructor to put object onto bus at a dbus path.
58 * @param[in] bus - Bus to attach to.
59 * @param[in] event - Dump manager sd_event loop.
60 * @param[in] path - Path to attach at.
61 */
62 Manager(sdbusplus::bus::bus& bus,
63 const EventPtr& event, const char* path) :
64 CreateIface(bus, path),
65 bus(bus),
66 eventLoop(event.get()),
67 lastEntryId(0)
68 {}
69
70 /** @brief Implementation for CreateDump
71 * Method to create Dump.
72 *
73 * @return id - The Dump entry id number.
74 */
75 uint32_t createDump() override;
76
77 private:
78 /** @brief Create Dump entry d-bus object
79 * @param[in] fullPath - Full path of the Dump file name
80 */
81 void createEntry(const fs::path& fullPath);
82
83 /** @brief Capture BMC Dump based on the Dump type.
84 * @param[in] type - Type of the Dump.
85 * @param[in] fullPaths - List of absolute paths to the files
86 * to be included as part of Dump package.
87 * @return id - The Dump entry id number.
88 */
89 uint32_t captureDump(
90 Type type,
91 const std::vector<std::string>& fullPaths);
92
93 /** @brief Erase specified entry d-bus object
94 *
95 * @param[in] entryId - unique identifier of the entry
96 */
97 void erase(uint32_t entryId);
98
99 /** @brief sd_event_add_child callback
100 *
101 * @param[in] s - event source
102 * @param[in] si - signal info
103 * @param[in] userdata - pointer to Watch object
104 *
105 * @returns 0 on success, -1 on fail
106 */
107 static int callback(sd_event_source* s,
108 const siginfo_t* si,
109 void* userdata)
110 {
111 //No specific action required in
112 //the sd_event_add_child callback.
113 return 0;
114 }
115
116 /** @brief sdbusplus DBus bus connection. */
117 sdbusplus::bus::bus& bus;
118
119 /** @brief sdbusplus Dump event loop */
120 EventPtr eventLoop;
121
122 /** @brief Dump Entry dbus objects map based on entry id */
123 std::map<uint32_t, std::unique_ptr<Entry>> entries;
124
125 /** @brief Id of the last Dump entry */
126 uint32_t lastEntryId;
127};
128
129} // namespace dump
130} // namespace phosphor