blob: 24dbcedf8989b9b72bf2c6c86c0c8685c8d7a3aa [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>
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -050010#include <xyz/openbmc_project/Dump/Create/server.hpp>
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050011
12#include <filesystem>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050013#include <set>
Jayanth Othayothd0f00642017-09-04 06:26:30 -050014
15namespace phosphor
16{
17namespace dump
18{
19namespace elog
20{
21
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -050022using Mgr = phosphor::dump::bmc::Manager;
Jayanth Othayoth24964822017-09-04 22:07:06 -050023using EId = uint32_t;
24using ElogList = std::set<EId>;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050025
26/** @class Watch
Jayanth Othayoth24964822017-09-04 22:07:06 -050027 * @brief Adds d-bus signal based watch for elog add and delete.
Jayanth Othayothd0f00642017-09-04 06:26:30 -050028 * @details This implements methods for watching for InternalFailure
29 * type error message and call appropriate function to initiate dump
30 */
31class Watch
32{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050033 public:
34 Watch() = delete;
35 ~Watch() = default;
36 Watch(const Watch&) = delete;
37 Watch& operator=(const Watch&) = delete;
Jayanth Othayoth4f68fc42024-11-25 10:04:07 -060038 Watch(Watch&&) = delete;
39 Watch& operator=(Watch&&) = delete;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050040
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050041 /** @brief constructs watch for elog add and delete signals.
42 * @param[in] bus - The Dbus bus object
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -050043 * @param[in] mgr - Dump Manager object
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050044 */
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -050045 Watch(sdbusplus::bus_t& bus, Mgr& mgr);
Jayanth Othayothd0f00642017-09-04 06:26:30 -050046
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050047 private:
48 friend class cereal::access;
Jayanth Othayoth24964822017-09-04 22:07:06 -050049
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050050 /** @brief Function required by Cereal to perform serialization.
51 * @tparam Archive - Cereal archive type (binary in our case).
52 * @param[in] a - reference to Cereal archive.
53 * @param[in] version - Class version that enables handling
54 * a serialized data across code levels
55 */
56 template <class Archive>
57 void serialize(Archive& a, const std::uint32_t version)
58 {
Jayanth Othayoth4f68fc42024-11-25 10:04:07 -060059 (void)version; // Mark version as unused to avoid warning
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050060 a(elogList);
Vishwanatha Subbanna31085972017-10-05 17:06:37 +053061
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050062 // TODO: openbmc/phosphor-debug-collector#1
63 // Split into load/save so that it enables
64 // version compare during serialization
65 }
Jayanth Othayoth24964822017-09-04 22:07:06 -050066
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050067 /** @brief Callback function for error log add.
68 * @details InternalError type error message initiates
69 * Internal error type dump request.
70 * @param[in] msg - Data associated with subscribed signal
71 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050072 void addCallback(sdbusplus::message_t& msg);
Jayanth Othayoth24964822017-09-04 22:07:06 -050073
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050074 /** @brief Callback function for error log delete.
75 * @param[in] msg - Data associated with subscribed signal
76 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050077 void delCallback(sdbusplus::message_t& msg);
Jayanth Othayoth24964822017-09-04 22:07:06 -050078
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050079 /** @brief get elog ID from elog entry object string.
80 * @param[in] objectPath - elog entry object path.
81 * @return - elog id.
82 */
83 inline EId getEid(const std::string& objectPath)
84 {
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050085 std::filesystem::path path(objectPath);
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050086 return std::stoul(path.filename());
87 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -050088
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -050089 /** @brief BMC Dump Manager object. */
90 Mgr& mgr;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050091
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050092 /** @brief sdbusplus signal match for elog add */
93 sdbusplus::bus::match_t addMatch;
Jayanth Othayoth24964822017-09-04 22:07:06 -050094
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050095 /** @brief sdbusplus signal match for elog delete */
96 sdbusplus::bus::match_t delMatch;
Jayanth Othayoth24964822017-09-04 22:07:06 -050097
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050098 /** @brief List of elog ids, which have associated dumps created */
99 ElogList elogList;
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500100};
101
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500102} // namespace elog
103} // namespace dump
104} // namespace phosphor