1 #pragma once 2 3 #include "config.h" 4 5 #include "dump_manager_bmc.hpp" 6 7 #include <cereal/access.hpp> 8 #include <filesystem> 9 #include <sdbusplus/bus.hpp> 10 #include <sdbusplus/server.hpp> 11 #include <set> 12 13 namespace phosphor 14 { 15 namespace dump 16 { 17 namespace elog 18 { 19 20 using IMgr = phosphor::dump::bmc::internal::Manager; 21 using EId = uint32_t; 22 using ElogList = std::set<EId>; 23 24 /** @class Watch 25 * @brief Adds d-bus signal based watch for elog add and delete. 26 * @details This implements methods for watching for InternalFailure 27 * type error message and call appropriate function to initiate dump 28 */ 29 class Watch 30 { 31 public: 32 Watch() = delete; 33 ~Watch() = default; 34 Watch(const Watch&) = delete; 35 Watch& operator=(const Watch&) = delete; 36 Watch(Watch&&) = default; 37 Watch& operator=(Watch&&) = default; 38 39 /** @brief constructs watch for elog add and delete signals. 40 * @param[in] bus - The Dbus bus object 41 * @param[in] intMgr - Dump internal Manager object 42 */ 43 Watch(sdbusplus::bus::bus& bus, IMgr& iMgr); 44 45 private: 46 friend class cereal::access; 47 48 /** @brief Function required by Cereal to perform serialization. 49 * @tparam Archive - Cereal archive type (binary in our case). 50 * @param[in] a - reference to Cereal archive. 51 * @param[in] version - Class version that enables handling 52 * a serialized data across code levels 53 */ 54 template <class Archive> 55 void serialize(Archive& a, const std::uint32_t version) 56 { 57 a(elogList); 58 59 // TODO: openbmc/phosphor-debug-collector#1 60 // Split into load/save so that it enables 61 // version compare during serialization 62 } 63 64 /** @brief Callback function for error log add. 65 * @details InternalError type error message initiates 66 * Internal error type dump request. 67 * @param[in] msg - Data associated with subscribed signal 68 */ 69 void addCallback(sdbusplus::message::message& msg); 70 71 /** @brief Callback function for error log delete. 72 * @param[in] msg - Data associated with subscribed signal 73 */ 74 void delCallback(sdbusplus::message::message& msg); 75 76 /** @brief get elog ID from elog entry object string. 77 * @param[in] objectPath - elog entry object path. 78 * @return - elog id. 79 */ 80 inline EId getEid(const std::string& objectPath) 81 { 82 std::filesystem::path path(objectPath); 83 return std::stoul(path.filename()); 84 } 85 86 /** @brief Dump internal Manager object. */ 87 IMgr& iMgr; 88 89 /** @brief sdbusplus signal match for elog add */ 90 sdbusplus::bus::match_t addMatch; 91 92 /** @brief sdbusplus signal match for elog delete */ 93 sdbusplus::bus::match_t delMatch; 94 95 /** @brief List of elog ids, which have associated dumps created */ 96 ElogList elogList; 97 }; 98 99 } // namespace elog 100 } // namespace dump 101 } // namespace phosphor 102