summaryrefslogtreecommitdiffstats
path: root/elog_watch.hpp
blob: 47303110a1a220850cc9ec27e2ff849ba3182144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once

#include <set>
#include <cereal/access.hpp>

#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>

#include "config.h"
#include "dump_manager.hpp"

namespace phosphor
{
namespace dump
{
namespace elog
{

using IMgr = phosphor::dump::internal::Manager;
using EId = uint32_t;
using ElogList = std::set<EId>;

/** @class Watch
 *  @brief Adds d-bus signal based watch for elog add and delete.
 *  @details This implements methods for watching for InternalFailure
 *  type error message and call appropriate function to initiate dump
 */
class Watch
{
    public:
        Watch() = delete;
        ~Watch() = default;
        Watch(const Watch&) = delete;
        Watch& operator=(const Watch&) = delete;
        Watch(Watch&&) = default;
        Watch& operator=(Watch&&) = default;

        /** @brief constructs watch for elog add and delete signals.
         *  @param[in] bus -  The Dbus bus object
         *  @param[in] intMgr - Dump internal Manager object
         */
        Watch(sdbusplus::bus::bus& bus, IMgr& iMgr);
    private:

        friend class cereal::access;

        /** @brief Function required by Cereal to perform serialization.
         *  @tparam Archive - Cereal archive type (binary in our case).
         *  @param[in] a - reference to Cereal archive.
         *  @param[in] version - Class version that enables handling
         *                       a serialized data across code levels
         */
        template<class Archive>
        void serialize(Archive& a, const std::uint32_t version)
        {
            a(elogList);

            //TODO: openbmc/phosphor-debug-collector#1
            //      Split into load/save so that it enables
            //      version compare during serialization
        }

        /** @brief Callback function for error log add.
         *  @details InternalError type error message initiates
         *           Internal error type dump request.
         *  @param[in] msg  - Data associated with subscribed signal
         */
        void addCallback(sdbusplus::message::message& msg);

        /** @brief Callback function for error log delete.
         *  @param[in] msg  - Data associated with subscribed signal
         */
        void delCallback(sdbusplus::message::message& msg);

        /** @brief get elog ID from elog entry object string.
         *  @param[in] objectPath  - elog entry object path.
         *  @return - elog id.
         */
        inline EId getEid(const std::string& objectPath)
        {
            fs::path path(objectPath);
            return std::stoul(path.filename());
        }

        /**  @brief Dump internal Manager object. */
        IMgr& iMgr;

        /** @brief sdbusplus signal match for elog add */
        sdbusplus::bus::match_t addMatch;

        /** @brief sdbusplus signal match for elog delete */
        sdbusplus::bus::match_t delMatch;

        /** @brief List of elog ids, which have associated dumps created */
        ElogList elogList;
};

}//namespace elog
}//namespace dump
}//namespace phosphor
OpenPOWER on IntegriCloud