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