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 #include <xyz/openbmc_project/Dump/Create/server.hpp> 11 12 #include <filesystem> 13 #include <set> 14 15 namespace phosphor 16 { 17 namespace dump 18 { 19 namespace elog 20 { 21 22 using Mgr = phosphor::dump::bmc::Manager; 23 using EId = uint32_t; 24 using ElogList = std::set<EId>; 25 26 /** @class Watch 27 * @brief Adds d-bus signal based watch for elog add and delete. 28 * @details This implements methods for watching for InternalFailure 29 * type error message and call appropriate function to initiate dump 30 */ 31 class Watch 32 { 33 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; 40 41 /** @brief constructs watch for elog add and delete signals. 42 * @param[in] bus - The Dbus bus object 43 * @param[in] mgr - Dump Manager object 44 */ 45 Watch(sdbusplus::bus_t& bus, Mgr& mgr); 46 47 private: 48 friend class cereal::access; 49 50 /** @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); 60 61 // TODO: openbmc/phosphor-debug-collector#1 62 // Split into load/save so that it enables 63 // version compare during serialization 64 } 65 66 /** @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 */ 71 void addCallback(sdbusplus::message_t& msg); 72 73 /** @brief Callback function for error log delete. 74 * @param[in] msg - Data associated with subscribed signal 75 */ 76 void delCallback(sdbusplus::message_t& msg); 77 78 /** @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 { 84 std::filesystem::path path(objectPath); 85 return std::stoul(path.filename()); 86 } 87 88 /** @brief BMC Dump Manager object. */ 89 Mgr& mgr; 90 91 /** @brief sdbusplus signal match for elog add */ 92 sdbusplus::bus::match_t addMatch; 93 94 /** @brief sdbusplus signal match for elog delete */ 95 sdbusplus::bus::match_t delMatch; 96 97 /** @brief List of elog ids, which have associated dumps created */ 98 ElogList elogList; 99 }; 100 101 } // namespace elog 102 } // namespace dump 103 } // namespace phosphor 104