blob: 2c808cf62ed3f7cecd2818c55010f0cb45a71ed1 [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
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05005#include "dump_manager.hpp"
6
7#include <cereal/access.hpp>
Jayanth Othayothd0f00642017-09-04 06:26:30 -05008#include <sdbusplus/bus.hpp>
9#include <sdbusplus/server.hpp>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050010#include <set>
Jayanth Othayothd0f00642017-09-04 06:26:30 -050011
12namespace phosphor
13{
14namespace dump
15{
16namespace elog
17{
18
19using IMgr = phosphor::dump::internal::Manager;
Jayanth Othayoth24964822017-09-04 22:07:06 -050020using EId = uint32_t;
21using ElogList = std::set<EId>;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050022
23/** @class Watch
Jayanth Othayoth24964822017-09-04 22:07:06 -050024 * @brief Adds d-bus signal based watch for elog add and delete.
Jayanth Othayothd0f00642017-09-04 06:26:30 -050025 * @details This implements methods for watching for InternalFailure
26 * type error message and call appropriate function to initiate dump
27 */
28class Watch
29{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050030 public:
31 Watch() = delete;
32 ~Watch() = default;
33 Watch(const Watch&) = delete;
34 Watch& operator=(const Watch&) = delete;
35 Watch(Watch&&) = default;
36 Watch& operator=(Watch&&) = default;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050037
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050038 /** @brief constructs watch for elog add and delete signals.
39 * @param[in] bus - The Dbus bus object
40 * @param[in] intMgr - Dump internal Manager object
41 */
42 Watch(sdbusplus::bus::bus& bus, IMgr& iMgr);
Jayanth Othayothd0f00642017-09-04 06:26:30 -050043
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050044 private:
45 friend class cereal::access;
Jayanth Othayoth24964822017-09-04 22:07:06 -050046
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050047 /** @brief Function required by Cereal to perform serialization.
48 * @tparam Archive - Cereal archive type (binary in our case).
49 * @param[in] a - reference to Cereal archive.
50 * @param[in] version - Class version that enables handling
51 * a serialized data across code levels
52 */
53 template <class Archive>
54 void serialize(Archive& a, const std::uint32_t version)
55 {
56 a(elogList);
Vishwanatha Subbanna31085972017-10-05 17:06:37 +053057
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050058 // TODO: openbmc/phosphor-debug-collector#1
59 // Split into load/save so that it enables
60 // version compare during serialization
61 }
Jayanth Othayoth24964822017-09-04 22:07:06 -050062
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050063 /** @brief Callback function for error log add.
64 * @details InternalError type error message initiates
65 * Internal error type dump request.
66 * @param[in] msg - Data associated with subscribed signal
67 */
68 void addCallback(sdbusplus::message::message& msg);
Jayanth Othayoth24964822017-09-04 22:07:06 -050069
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050070 /** @brief Callback function for error log delete.
71 * @param[in] msg - Data associated with subscribed signal
72 */
73 void delCallback(sdbusplus::message::message& msg);
Jayanth Othayoth24964822017-09-04 22:07:06 -050074
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050075 /** @brief get elog ID from elog entry object string.
76 * @param[in] objectPath - elog entry object path.
77 * @return - elog id.
78 */
79 inline EId getEid(const std::string& objectPath)
80 {
81 fs::path path(objectPath);
82 return std::stoul(path.filename());
83 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -050084
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050085 /** @brief Dump internal Manager object. */
86 IMgr& iMgr;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050087
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050088 /** @brief sdbusplus signal match for elog add */
89 sdbusplus::bus::match_t addMatch;
Jayanth Othayoth24964822017-09-04 22:07:06 -050090
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050091 /** @brief sdbusplus signal match for elog delete */
92 sdbusplus::bus::match_t delMatch;
Jayanth Othayoth24964822017-09-04 22:07:06 -050093
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050094 /** @brief List of elog ids, which have associated dumps created */
95 ElogList elogList;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050096};
97
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050098} // namespace elog
99} // namespace dump
100} // namespace phosphor