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