blob: 003d9e42de0f7387308f20c981bcd6ced2cd9548 [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
Jayanth Othayoth764d1b22017-07-12 19:14:02 -050036using Watch = phosphor::dump::inotify::Watch;
37
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050038/** @class Manager
39 * @brief OpenBMC Dump manager implementation.
40 * @details A concrete implementation for the
41 * xyz.openbmc_project.Dump.Create DBus API.
42 */
43class Manager : public CreateIface
44{
45 friend class internal::Manager;
46 friend class Entry;
47
48 public:
49 Manager() = delete;
50 Manager(const Manager&) = default;
51 Manager& operator=(const Manager&) = delete;
52 Manager(Manager&&) = delete;
53 Manager& operator=(Manager&&) = delete;
54 virtual ~Manager() = default;
55
56 /** @brief Constructor to put object onto bus at a dbus path.
57 * @param[in] bus - Bus to attach to.
58 * @param[in] event - Dump manager sd_event loop.
59 * @param[in] path - Path to attach at.
60 */
61 Manager(sdbusplus::bus::bus& bus,
62 const EventPtr& event, const char* path) :
63 CreateIface(bus, path),
64 bus(bus),
65 eventLoop(event.get()),
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050066 lastEntryId(0),
67 dumpWatch(eventLoop,
68 IN_NONBLOCK,
69 IN_CLOSE_WRITE,
70 EPOLLIN,
Jayanth Othayoth2dccfe42017-07-12 18:20:40 -050071 BMC_DUMP_PATH,
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050072 std::bind(
73 std::mem_fn(
74 &phosphor::dump::Manager::watchCallback),
75 this, std::placeholders::_1))
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050076 {}
77
78 /** @brief Implementation for CreateDump
79 * Method to create Dump.
80 *
81 * @return id - The Dump entry id number.
82 */
83 uint32_t createDump() override;
84
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050085 /** @brief Implementation of dump watch call back
86 * @param [in] fileInfo - map of file info path:event
87 */
88 void watchCallback(const UserMap& fileInfo);
89
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050090 private:
91 /** @brief Create Dump entry d-bus object
92 * @param[in] fullPath - Full path of the Dump file name
93 */
94 void createEntry(const fs::path& fullPath);
95
96 /** @brief Capture BMC Dump based on the Dump type.
97 * @param[in] type - Type of the Dump.
98 * @param[in] fullPaths - List of absolute paths to the files
99 * to be included as part of Dump package.
100 * @return id - The Dump entry id number.
101 */
102 uint32_t captureDump(
103 Type type,
104 const std::vector<std::string>& fullPaths);
105
106 /** @brief Erase specified entry d-bus object
107 *
108 * @param[in] entryId - unique identifier of the entry
109 */
110 void erase(uint32_t entryId);
111
112 /** @brief sd_event_add_child callback
113 *
114 * @param[in] s - event source
115 * @param[in] si - signal info
116 * @param[in] userdata - pointer to Watch object
117 *
118 * @returns 0 on success, -1 on fail
119 */
120 static int callback(sd_event_source* s,
121 const siginfo_t* si,
122 void* userdata)
123 {
124 //No specific action required in
125 //the sd_event_add_child callback.
126 return 0;
127 }
Jayanth Othayoth764d1b22017-07-12 19:14:02 -0500128 /** @brief Remove specified watch object pointer from the
129 * watch map and associated entry from the map.
130 * @param[in] path - unique identifier of the map
131 */
132 void removeWatch(const fs::path& path);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500133
134 /** @brief sdbusplus DBus bus connection. */
135 sdbusplus::bus::bus& bus;
136
137 /** @brief sdbusplus Dump event loop */
138 EventPtr eventLoop;
139
140 /** @brief Dump Entry dbus objects map based on entry id */
141 std::map<uint32_t, std::unique_ptr<Entry>> entries;
142
143 /** @brief Id of the last Dump entry */
144 uint32_t lastEntryId;
Jayanth Othayothbcb174b2017-07-02 06:29:24 -0500145
Jayanth Othayoth764d1b22017-07-12 19:14:02 -0500146 /** @brief Dump main watch object */
147 Watch dumpWatch;
148
149 /** @brief Child directory path and its associated watch object map
150 * [path:watch object]
151 */
152 std::map<fs::path, std::unique_ptr<Watch>> childWatchMap;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500153};
154
155} // namespace dump
156} // namespace phosphor