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&&) = delete; 39 Watch& operator=(Watch&&) = delete; 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> serialize(Archive & a,const std::uint32_t version)57 void serialize(Archive& a, const std::uint32_t version) 58 { 59 (void)version; // Mark version as unused to avoid warning 60 a(elogList); 61 62 // TODO: openbmc/phosphor-debug-collector#1 63 // Split into load/save so that it enables 64 // version compare during serialization 65 } 66 67 /** @brief Callback function for error log add. 68 * @details InternalError type error message initiates 69 * Internal error type dump request. 70 * @param[in] msg - Data associated with subscribed signal 71 */ 72 void addCallback(sdbusplus::message_t& msg); 73 74 /** @brief Callback function for error log delete. 75 * @param[in] msg - Data associated with subscribed signal 76 */ 77 void delCallback(sdbusplus::message_t& msg); 78 79 /** @brief get elog ID from elog entry object string. 80 * @param[in] objectPath - elog entry object path. 81 * @return - elog id. 82 */ getEid(const std::string & objectPath)83 inline EId getEid(const std::string& objectPath) 84 { 85 std::filesystem::path path(objectPath); 86 return std::stoul(path.filename()); 87 } 88 89 /** @brief BMC Dump Manager object. */ 90 Mgr& mgr; 91 92 /** @brief sdbusplus signal match for elog add */ 93 sdbusplus::bus::match_t addMatch; 94 95 /** @brief sdbusplus signal match for elog delete */ 96 sdbusplus::bus::match_t delMatch; 97 98 /** @brief List of elog ids, which have associated dumps created */ 99 ElogList elogList; 100 }; 101 102 } // namespace elog 103 } // namespace dump 104 } // namespace phosphor 105