xref: /openbmc/phosphor-debug-collector/elog_watch.hpp (revision 4f68fc460adc4327711e7adb7a81b30ed5dd67c0)
1d0f0064eSJayanth Othayoth #pragma once
2d0f0064eSJayanth Othayoth 
3cb65ffceSJayanth Othayoth #include "config.h"
42496482aSJayanth Othayoth 
5fef66a95SDhruvaraj Subhashchandran #include "dump_manager_bmc.hpp"
6cb65ffceSJayanth Othayoth 
7cb65ffceSJayanth Othayoth #include <cereal/access.hpp>
8d0f0064eSJayanth Othayoth #include <sdbusplus/bus.hpp>
9d0f0064eSJayanth Othayoth #include <sdbusplus/server.hpp>
10e4350f93SDhruvaraj Subhashchandran #include <xyz/openbmc_project/Dump/Create/server.hpp>
110af74a5eSJayanth Othayoth 
120af74a5eSJayanth Othayoth #include <filesystem>
13cb65ffceSJayanth Othayoth #include <set>
14d0f0064eSJayanth Othayoth 
15d0f0064eSJayanth Othayoth namespace phosphor
16d0f0064eSJayanth Othayoth {
17d0f0064eSJayanth Othayoth namespace dump
18d0f0064eSJayanth Othayoth {
19d0f0064eSJayanth Othayoth namespace elog
20d0f0064eSJayanth Othayoth {
21d0f0064eSJayanth Othayoth 
22e4350f93SDhruvaraj Subhashchandran using Mgr = phosphor::dump::bmc::Manager;
232496482aSJayanth Othayoth using EId = uint32_t;
242496482aSJayanth Othayoth using ElogList = std::set<EId>;
25d0f0064eSJayanth Othayoth 
26d0f0064eSJayanth Othayoth /** @class Watch
272496482aSJayanth Othayoth  *  @brief Adds d-bus signal based watch for elog add and delete.
28d0f0064eSJayanth Othayoth  *  @details This implements methods for watching for InternalFailure
29d0f0064eSJayanth Othayoth  *  type error message and call appropriate function to initiate dump
30d0f0064eSJayanth Othayoth  */
31d0f0064eSJayanth Othayoth class Watch
32d0f0064eSJayanth Othayoth {
33d0f0064eSJayanth Othayoth   public:
34d0f0064eSJayanth Othayoth     Watch() = delete;
35d0f0064eSJayanth Othayoth     ~Watch() = default;
36d0f0064eSJayanth Othayoth     Watch(const Watch&) = delete;
37d0f0064eSJayanth Othayoth     Watch& operator=(const Watch&) = delete;
38*4f68fc46SJayanth Othayoth     Watch(Watch&&) = delete;
39*4f68fc46SJayanth Othayoth     Watch& operator=(Watch&&) = delete;
40d0f0064eSJayanth Othayoth 
412496482aSJayanth Othayoth     /** @brief constructs watch for elog add and delete signals.
42d0f0064eSJayanth Othayoth      *  @param[in] bus -  The Dbus bus object
43e4350f93SDhruvaraj Subhashchandran      *  @param[in] mgr - Dump Manager object
44d0f0064eSJayanth Othayoth      */
45e4350f93SDhruvaraj Subhashchandran     Watch(sdbusplus::bus_t& bus, Mgr& mgr);
46d0f0064eSJayanth Othayoth 
47cb65ffceSJayanth Othayoth   private:
482496482aSJayanth Othayoth     friend class cereal::access;
492496482aSJayanth Othayoth 
502496482aSJayanth Othayoth     /** @brief Function required by Cereal to perform serialization.
512496482aSJayanth Othayoth      *  @tparam Archive - Cereal archive type (binary in our case).
522496482aSJayanth Othayoth      *  @param[in] a - reference to Cereal archive.
5331085974SVishwanatha Subbanna      *  @param[in] version - Class version that enables handling
5431085974SVishwanatha Subbanna      *                       a serialized data across code levels
552496482aSJayanth Othayoth      */
562496482aSJayanth Othayoth     template <class Archive>
serialize(Archive & a,const std::uint32_t version)5731085974SVishwanatha Subbanna     void serialize(Archive& a, const std::uint32_t version)
582496482aSJayanth Othayoth     {
59*4f68fc46SJayanth Othayoth         (void)version; // Mark version as unused to avoid warning
602496482aSJayanth Othayoth         a(elogList);
6131085974SVishwanatha Subbanna 
6231085974SVishwanatha Subbanna         // TODO: openbmc/phosphor-debug-collector#1
6331085974SVishwanatha Subbanna         //      Split into load/save so that it enables
6431085974SVishwanatha Subbanna         //      version compare during serialization
652496482aSJayanth Othayoth     }
662496482aSJayanth Othayoth 
672496482aSJayanth Othayoth     /** @brief Callback function for error log add.
68d0f0064eSJayanth Othayoth      *  @details InternalError type error message initiates
69d0f0064eSJayanth Othayoth      *           Internal error type dump request.
70d0f0064eSJayanth Othayoth      *  @param[in] msg  - Data associated with subscribed signal
71d0f0064eSJayanth Othayoth      */
729b18bf2dSPatrick Williams     void addCallback(sdbusplus::message_t& msg);
732496482aSJayanth Othayoth 
742496482aSJayanth Othayoth     /** @brief Callback function for error log delete.
752496482aSJayanth Othayoth      *  @param[in] msg  - Data associated with subscribed signal
762496482aSJayanth Othayoth      */
779b18bf2dSPatrick Williams     void delCallback(sdbusplus::message_t& msg);
782496482aSJayanth Othayoth 
792496482aSJayanth Othayoth     /** @brief get elog ID from elog entry object string.
802496482aSJayanth Othayoth      *  @param[in] objectPath  - elog entry object path.
812496482aSJayanth Othayoth      *  @return - elog id.
822496482aSJayanth Othayoth      */
getEid(const std::string & objectPath)832496482aSJayanth Othayoth     inline EId getEid(const std::string& objectPath)
842496482aSJayanth Othayoth     {
853fc6df48SJayanth Othayoth         std::filesystem::path path(objectPath);
862496482aSJayanth Othayoth         return std::stoul(path.filename());
872496482aSJayanth Othayoth     }
88d0f0064eSJayanth Othayoth 
89e4350f93SDhruvaraj Subhashchandran     /**  @brief BMC Dump Manager object. */
90e4350f93SDhruvaraj Subhashchandran     Mgr& mgr;
91d0f0064eSJayanth Othayoth 
922496482aSJayanth Othayoth     /** @brief sdbusplus signal match for elog add */
932496482aSJayanth Othayoth     sdbusplus::bus::match_t addMatch;
942496482aSJayanth Othayoth 
952496482aSJayanth Othayoth     /** @brief sdbusplus signal match for elog delete */
962496482aSJayanth Othayoth     sdbusplus::bus::match_t delMatch;
972496482aSJayanth Othayoth 
982496482aSJayanth Othayoth     /** @brief List of elog ids, which have associated dumps created */
992496482aSJayanth Othayoth     ElogList elogList;
100d0f0064eSJayanth Othayoth };
101d0f0064eSJayanth Othayoth 
102d0f0064eSJayanth Othayoth } // namespace elog
103d0f0064eSJayanth Othayoth } // namespace dump
104d0f0064eSJayanth Othayoth } // namespace phosphor
105