blob: 55947b2a407d16d9caeb04281c7adfd48b33ce01 [file] [log] [blame]
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05001#pragma once
2
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -05003#include <experimental/filesystem>
4
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05005#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server/object.hpp>
7#include <xyz/openbmc_project/Dump/Create/server.hpp>
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05008
9#include "xyz/openbmc_project/Dump/Internal/Create/server.hpp"
10#include "dump_entry.hpp"
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050011#include "dump_utils.hpp"
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050012#include "watch.hpp"
13#include "config.h"
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050014
15namespace phosphor
16{
17namespace dump
18{
19namespace internal
20{
21
22class Manager;
23
24} // namespace internal
25
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050026using UserMap = phosphor::dump::inotify::UserMap;
27
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050028using Type =
29 sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type;
30
31using CreateIface = sdbusplus::server::object::object<
32 sdbusplus::xyz::openbmc_project::Dump::server::Create>;
33
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050034namespace fs = std::experimental::filesystem;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050035
36/** @class Manager
37 * @brief OpenBMC Dump manager implementation.
38 * @details A concrete implementation for the
39 * xyz.openbmc_project.Dump.Create DBus API.
40 */
41class Manager : public CreateIface
42{
43 friend class internal::Manager;
44 friend class Entry;
45
46 public:
47 Manager() = delete;
48 Manager(const Manager&) = default;
49 Manager& operator=(const Manager&) = delete;
50 Manager(Manager&&) = delete;
51 Manager& operator=(Manager&&) = delete;
52 virtual ~Manager() = default;
53
54 /** @brief Constructor to put object onto bus at a dbus path.
55 * @param[in] bus - Bus to attach to.
56 * @param[in] event - Dump manager sd_event loop.
57 * @param[in] path - Path to attach at.
58 */
59 Manager(sdbusplus::bus::bus& bus,
60 const EventPtr& event, const char* path) :
61 CreateIface(bus, path),
62 bus(bus),
63 eventLoop(event.get()),
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050064 lastEntryId(0),
65 dumpWatch(eventLoop,
66 IN_NONBLOCK,
67 IN_CLOSE_WRITE,
68 EPOLLIN,
69 BMC_DUMP_FILE_DIR,
70 std::bind(
71 std::mem_fn(
72 &phosphor::dump::Manager::watchCallback),
73 this, std::placeholders::_1))
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050074 {}
75
76 /** @brief Implementation for CreateDump
77 * Method to create Dump.
78 *
79 * @return id - The Dump entry id number.
80 */
81 uint32_t createDump() override;
82
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050083 /** @brief Implementation of dump watch call back
84 * @param [in] fileInfo - map of file info path:event
85 */
86 void watchCallback(const UserMap& fileInfo);
87
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050088 private:
89 /** @brief Create Dump entry d-bus object
90 * @param[in] fullPath - Full path of the Dump file name
91 */
92 void createEntry(const fs::path& fullPath);
93
94 /** @brief Capture BMC Dump based on the Dump type.
95 * @param[in] type - Type of the Dump.
96 * @param[in] fullPaths - List of absolute paths to the files
97 * to be included as part of Dump package.
98 * @return id - The Dump entry id number.
99 */
100 uint32_t captureDump(
101 Type type,
102 const std::vector<std::string>& fullPaths);
103
104 /** @brief Erase specified entry d-bus object
105 *
106 * @param[in] entryId - unique identifier of the entry
107 */
108 void erase(uint32_t entryId);
109
110 /** @brief sd_event_add_child callback
111 *
112 * @param[in] s - event source
113 * @param[in] si - signal info
114 * @param[in] userdata - pointer to Watch object
115 *
116 * @returns 0 on success, -1 on fail
117 */
118 static int callback(sd_event_source* s,
119 const siginfo_t* si,
120 void* userdata)
121 {
122 //No specific action required in
123 //the sd_event_add_child callback.
124 return 0;
125 }
126
127 /** @brief sdbusplus DBus bus connection. */
128 sdbusplus::bus::bus& bus;
129
130 /** @brief sdbusplus Dump event loop */
131 EventPtr eventLoop;
132
133 /** @brief Dump Entry dbus objects map based on entry id */
134 std::map<uint32_t, std::unique_ptr<Entry>> entries;
135
136 /** @brief Id of the last Dump entry */
137 uint32_t lastEntryId;
Jayanth Othayothbcb174b2017-07-02 06:29:24 -0500138
139 /** @brief Dump watch object */
140 phosphor::dump::inotify::Watch dumpWatch;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500141};
142
143} // namespace dump
144} // namespace phosphor