blob: 3806ed87005321ede1e04ba7f7c33bff818c0134 [file] [log] [blame]
Jayanth Othayothd0f00642017-09-04 06:26:30 -05001#pragma once
2
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05003#include "config.h"
Jayanth Othayoth24964822017-09-04 22:07:06 -05004
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05005#include "dump_manager_bmc.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05006
7#include <cereal/access.hpp>
Jayanth Othayothd0f00642017-09-04 06:26:30 -05008#include <sdbusplus/bus.hpp>
9#include <sdbusplus/server.hpp>
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050010
11#include <filesystem>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050012#include <set>
Jayanth Othayothd0f00642017-09-04 06:26:30 -050013
14namespace phosphor
15{
16namespace dump
17{
18namespace elog
19{
20
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050021using IMgr = phosphor::dump::bmc::internal::Manager;
Jayanth Othayoth24964822017-09-04 22:07:06 -050022using EId = uint32_t;
23using ElogList = std::set<EId>;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050024
25/** @class Watch
Jayanth Othayoth24964822017-09-04 22:07:06 -050026 * @brief Adds d-bus signal based watch for elog add and delete.
Jayanth Othayothd0f00642017-09-04 06:26:30 -050027 * @details This implements methods for watching for InternalFailure
28 * type error message and call appropriate function to initiate dump
29 */
30class Watch
31{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050032 public:
33 Watch() = delete;
34 ~Watch() = default;
35 Watch(const Watch&) = delete;
36 Watch& operator=(const Watch&) = delete;
37 Watch(Watch&&) = default;
38 Watch& operator=(Watch&&) = default;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050039
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050040 /** @brief constructs watch for elog add and delete signals.
41 * @param[in] bus - The Dbus bus object
42 * @param[in] intMgr - Dump internal Manager object
43 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050044 Watch(sdbusplus::bus_t& bus, IMgr& iMgr);
Jayanth Othayothd0f00642017-09-04 06:26:30 -050045
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050046 private:
47 friend class cereal::access;
Jayanth Othayoth24964822017-09-04 22:07:06 -050048
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050049 /** @brief Function required by Cereal to perform serialization.
50 * @tparam Archive - Cereal archive type (binary in our case).
51 * @param[in] a - reference to Cereal archive.
52 * @param[in] version - Class version that enables handling
53 * a serialized data across code levels
54 */
55 template <class Archive>
56 void serialize(Archive& a, const std::uint32_t version)
57 {
58 a(elogList);
Vishwanatha Subbanna31085972017-10-05 17:06:37 +053059
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050060 // TODO: openbmc/phosphor-debug-collector#1
61 // Split into load/save so that it enables
62 // version compare during serialization
63 }
Jayanth Othayoth24964822017-09-04 22:07:06 -050064
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050065 /** @brief Callback function for error log add.
66 * @details InternalError type error message initiates
67 * Internal error type dump request.
68 * @param[in] msg - Data associated with subscribed signal
69 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050070 void addCallback(sdbusplus::message_t& msg);
Jayanth Othayoth24964822017-09-04 22:07:06 -050071
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050072 /** @brief Callback function for error log delete.
73 * @param[in] msg - Data associated with subscribed signal
74 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050075 void delCallback(sdbusplus::message_t& msg);
Jayanth Othayoth24964822017-09-04 22:07:06 -050076
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050077 /** @brief get elog ID from elog entry object string.
78 * @param[in] objectPath - elog entry object path.
79 * @return - elog id.
80 */
81 inline EId getEid(const std::string& objectPath)
82 {
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050083 std::filesystem::path path(objectPath);
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050084 return std::stoul(path.filename());
85 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -050086
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050087 /** @brief Dump internal Manager object. */
88 IMgr& iMgr;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050089
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050090 /** @brief sdbusplus signal match for elog add */
91 sdbusplus::bus::match_t addMatch;
Jayanth Othayoth24964822017-09-04 22:07:06 -050092
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050093 /** @brief sdbusplus signal match for elog delete */
94 sdbusplus::bus::match_t delMatch;
Jayanth Othayoth24964822017-09-04 22:07:06 -050095
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050096 /** @brief List of elog ids, which have associated dumps created */
97 ElogList elogList;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050098};
99
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500100} // namespace elog
101} // namespace dump
102} // namespace phosphor