summaryrefslogtreecommitdiffstats
path: root/bmc_state_manager.hpp
blob: 0e52a25ebeae3a2c76d9f7942e3791e30e3b2449 (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
101
102
103
104
105
#pragma once

#include <sdbusplus/bus.hpp>
#include "xyz/openbmc_project/State/BMC/server.hpp"

namespace phosphor
{
namespace state
{
namespace manager
{

/** @class BMC
 *  @brief OpenBMC BMC state management implementation.
 *  @details A concrete implementation for xyz.openbmc_project.State.BMC
 *  DBus API.
 */
class BMC : public sdbusplus::server::object::object<
                       sdbusplus::xyz::openbmc_project::State::server::BMC>
{
    public:
        /** @brief Constructs BMC State Manager
         *
         * @param[in] bus       - The Dbus bus object
         * @param[in] busName   - The Dbus name to own
         * @param[in] objPath   - The Dbus object path
         */
        BMC(sdbusplus::bus::bus& bus,
            const char* objPath) :
                sdbusplus::server::object::object<
                    sdbusplus::xyz::openbmc_project::State::server::BMC>(
                        bus, objPath, true),
                            bus(bus),
                            stateSignal(
                                std::make_unique<
                                decltype(stateSignal)::element_type>(
                                bus,
                                "type='signal',"
                                "member='JobRemoved',"
                                "path='/org/freedesktop/systemd1',"
                                "interface='org.freedesktop.systemd1.Manager'",
                                bmcStateChangeSignal,
                                this))
        {
            subscribeToSystemdSignals();
            discoverInitialState();
            this->emit_object_added();
        };

        /** @brief Set value of BMCTransition **/
        Transition requestedBMCTransition(Transition value) override;

        /** @brief Set value of CurrentBMCState **/
        BMCState currentBMCState(BMCState value) override;

    private:
        /**
         * @brief discover the state of the bmc
         **/
        void discoverInitialState();

        /**
         * @brief subscribe to the systemd signals
         **/
        void subscribeToSystemdSignals();

        /** @brief Execute the transition request
         *
         *  @param[in] tranReq   - Transition requested
         */
        void executeTransition(Transition tranReq);

        /** @brief Callback used to direct you into the class
         *
         * @param[in]  msg       - Data associated with subscribed signal
         * @param[in]  userData  - Pointer to this object instance
         * @param[out] retError  - return error data if any
         *
         */
        static int bmcStateChangeSignal(sd_bus_message* msg,
                                        void* userData,
                                        sd_bus_error* retError);

        /** @brief Callback function on bmc state change
         *
         * Check if the state is relevant to the BMC and if so, update
         * corresponding BMC object's state
         *
         * @param[in]  msg       - Data associated with subscribed signal
         * @param[out] retError  - return error data if any
         *
         */
        int bmcStateChange(sd_bus_message* msg,
                           sd_bus_error* retError);

        /** @brief Persistent sdbusplus DBus bus connection. **/
        sdbusplus::bus::bus& bus;

        /** @brief Used to subscribe to dbus system state changes **/
        std::unique_ptr<sdbusplus::server::match::match> stateSignal;
};

} // namespace manager
} // namespace state
} // namespace phosphor
OpenPOWER on IntegriCloud