blob: 588ac34ac2b2a3b87ea25017c1835853240f2049 [file] [log] [blame]
Jayanth Othayothd0f00642017-09-04 06:26:30 -05001#pragma once
2
Jayanth Othayoth24964822017-09-04 22:07:06 -05003#include <set>
4#include <cereal/access.hpp>
5
Jayanth Othayothd0f00642017-09-04 06:26:30 -05006#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server.hpp>
Jayanth Othayothd0f00642017-09-04 06:26:30 -05008
Jayanth Othayoth24964822017-09-04 22:07:06 -05009#include "config.h"
Jayanth Othayothd0f00642017-09-04 06:26:30 -050010#include "dump_manager.hpp"
11
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{
30 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;
37
Jayanth Othayoth24964822017-09-04 22:07:06 -050038 /** @brief constructs watch for elog add and delete signals.
Jayanth Othayothd0f00642017-09-04 06:26:30 -050039 * @param[in] bus - The Dbus bus object
40 * @param[in] intMgr - Dump internal Manager object
41 */
Jayanth Othayoth24964822017-09-04 22:07:06 -050042 Watch(sdbusplus::bus::bus& bus, IMgr& iMgr);
Jayanth Othayothd0f00642017-09-04 06:26:30 -050043 private:
44
Jayanth Othayoth24964822017-09-04 22:07:06 -050045 friend class cereal::access;
46
47 /** @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 */
51 template<class Archive>
52 void serialize(Archive& a)
53 {
54 a(elogList);
55 }
56
57 /** @brief Callback function for error log add.
Jayanth Othayothd0f00642017-09-04 06:26:30 -050058 * @details InternalError type error message initiates
59 * Internal error type dump request.
60 * @param[in] msg - Data associated with subscribed signal
61 */
Jayanth Othayoth24964822017-09-04 22:07:06 -050062 void addCallback(sdbusplus::message::message& msg);
63
64 /** @brief Callback function for error log delete.
65 * @param[in] msg - Data associated with subscribed signal
66 */
67 void delCallback(sdbusplus::message::message& msg);
68
69 /** @brief get elog ID from elog entry object string.
70 * @param[in] objectPath - elog entry object path.
71 * @return - elog id.
72 */
73 inline EId getEid(const std::string& objectPath)
74 {
75 fs::path path(objectPath);
76 return std::stoul(path.filename());
77 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -050078
79 /** @brief Dump internal Manager object. */
80 IMgr& iMgr;
81
Jayanth Othayoth24964822017-09-04 22:07:06 -050082 /** @brief sdbusplus signal match for elog add */
83 sdbusplus::bus::match_t addMatch;
84
85 /** @brief sdbusplus signal match for elog delete */
86 sdbusplus::bus::match_t delMatch;
87
88 /** @brief List of elog ids, which have associated dumps created */
89 ElogList elogList;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050090};
91
92}//namespace elog
93}//namespace dump
94}//namespace phosphor