blob: 7b8671f3138c8a7faa72e505adb181ee957bc638 [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;
38 Watch(Watch&&) = default;
39 Watch& operator=(Watch&&) = default;
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 {
59 a(elogList);
Vishwanatha Subbanna31085972017-10-05 17:06:37 +053060
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050061 // TODO: openbmc/phosphor-debug-collector#1
62 // Split into load/save so that it enables
63 // version compare during serialization
64 }
Jayanth Othayoth24964822017-09-04 22:07:06 -050065
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050066 /** @brief Callback function for error log add.
67 * @details InternalError type error message initiates
68 * Internal error type dump request.
69 * @param[in] msg - Data associated with subscribed signal
70 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050071 void addCallback(sdbusplus::message_t& msg);
Jayanth Othayoth24964822017-09-04 22:07:06 -050072
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050073 /** @brief Callback function for error log delete.
74 * @param[in] msg - Data associated with subscribed signal
75 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050076 void delCallback(sdbusplus::message_t& msg);
Jayanth Othayoth24964822017-09-04 22:07:06 -050077
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050078 /** @brief get elog ID from elog entry object string.
79 * @param[in] objectPath - elog entry object path.
80 * @return - elog id.
81 */
82 inline EId getEid(const std::string& objectPath)
83 {
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050084 std::filesystem::path path(objectPath);
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050085 return std::stoul(path.filename());
86 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -050087
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -050088 /** @brief BMC Dump Manager object. */
89 Mgr& mgr;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050090
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050091 /** @brief sdbusplus signal match for elog add */
92 sdbusplus::bus::match_t addMatch;
Jayanth Othayoth24964822017-09-04 22:07:06 -050093
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050094 /** @brief sdbusplus signal match for elog delete */
95 sdbusplus::bus::match_t delMatch;
Jayanth Othayoth24964822017-09-04 22:07:06 -050096
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050097 /** @brief List of elog ids, which have associated dumps created */
98 ElogList elogList;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050099};
100
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500101} // namespace elog
102} // namespace dump
103} // namespace phosphor