xref: /openbmc/phosphor-power/cold-redundancy/cold_redundancy.hpp (revision 5ed2eb4c375c7037c95a4a635c180af60eac28e5)
1e83604beSCheng C Yang /*
2e83604beSCheng C Yang // Copyright (c) 2019 Intel Corporation
3e83604beSCheng C Yang //
4e83604beSCheng C Yang // Licensed under the Apache License, Version 2.0 (the "License");
5e83604beSCheng C Yang // you may not use this file except in compliance with the License.
6e83604beSCheng C Yang // You may obtain a copy of the License at
7e83604beSCheng C Yang //
8e83604beSCheng C Yang //      http://www.apache.org/licenses/LICENSE-2.0
9e83604beSCheng C Yang //
10e83604beSCheng C Yang // Unless required by applicable law or agreed to in writing, software
11e83604beSCheng C Yang // distributed under the License is distributed on an "AS IS" BASIS,
12e83604beSCheng C Yang // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e83604beSCheng C Yang // See the License for the specific language governing permissions and
14e83604beSCheng C Yang // limitations under the License.
15e83604beSCheng C Yang */
16e83604beSCheng C Yang 
1713e03339SShawn McCarney #include <boost/asio.hpp>
18e83604beSCheng C Yang #include <sdbusplus/asio/object_server.hpp>
19e83604beSCheng C Yang #include <util.hpp>
20e83604beSCheng C Yang 
21e83604beSCheng C Yang /**
22e83604beSCheng C Yang  * @class ColdRedundancy
23e83604beSCheng C Yang  *
24e83604beSCheng C Yang  */
25e83604beSCheng C Yang class ColdRedundancy
26e83604beSCheng C Yang {
27e83604beSCheng C Yang   public:
28e83604beSCheng C Yang     /**
29e83604beSCheng C Yang      * Constructor
30e83604beSCheng C Yang      *
31e83604beSCheng C Yang      * @param[in] io - boost asio context
32e83604beSCheng C Yang      * @param[in] dbusConnection - D-Bus connection
33e83604beSCheng C Yang      */
34e83604beSCheng C Yang     ColdRedundancy(
35e83604beSCheng C Yang         boost::asio::io_service& io,
36e83604beSCheng C Yang         std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
37e83604beSCheng C Yang 
38e83604beSCheng C Yang     /**
39e83604beSCheng C Yang      * Checking PSU information, adding matches, starting rotation
40e83604beSCheng C Yang      * and creating PSU objects
41e83604beSCheng C Yang      *
42e83604beSCheng C Yang      * @param[in] dbusConnection - D-Bus connection
43e83604beSCheng C Yang      */
44e83604beSCheng C Yang     void
45e83604beSCheng C Yang         createPSU(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
46e83604beSCheng C Yang 
47e83604beSCheng C Yang   private:
48e83604beSCheng C Yang     /**
49e83604beSCheng C Yang      * @brief Indicates the count of PSUs
50e83604beSCheng C Yang      *
51e83604beSCheng C Yang      * @details Indicates how many PSUs are there on the system.
52e83604beSCheng C Yang      */
53e83604beSCheng C Yang     uint8_t numberOfPSU = 0;
54e83604beSCheng C Yang 
55e83604beSCheng C Yang     /**
56e83604beSCheng C Yang      * @brief Indicates the delay timer
57e83604beSCheng C Yang      *
58e83604beSCheng C Yang      * @details Each time this daemon start, need a delay to avoid
59e83604beSCheng C Yang      *          different PSUs calling createPSU function for
60e83604beSCheng C Yang      *          several times at same time
61e83604beSCheng C Yang      */
62e83604beSCheng C Yang     boost::asio::steady_timer filterTimer;
63e83604beSCheng C Yang 
64e83604beSCheng C Yang     /**
65e83604beSCheng C Yang      * @brief Indicates the dbus connction
66e83604beSCheng C Yang      */
67e83604beSCheng C Yang     std::shared_ptr<sdbusplus::asio::connection>& systemBus;
68e83604beSCheng C Yang 
69e83604beSCheng C Yang     /**
70e83604beSCheng C Yang      * @brief Indicates the D-Bus matches
71e83604beSCheng C Yang      *
72e83604beSCheng C Yang      * @details This matches contain all matches in this daemon such
73e83604beSCheng C Yang      *          as PSU event match, PSU information match. The target
74e83604beSCheng C Yang      *          D-Bus properties change will trigger callback function
75e83604beSCheng C Yang      *          by these matches
76e83604beSCheng C Yang      */
77*7354ce62SPatrick Williams     std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches;
78e83604beSCheng C Yang };
79e83604beSCheng C Yang 
80e83604beSCheng C Yang /**
81e83604beSCheng C Yang  * @class PowerSupply
82e83604beSCheng C Yang  * Represents a power supply device.
83e83604beSCheng C Yang  */
84e83604beSCheng C Yang class PowerSupply
85e83604beSCheng C Yang {
86e83604beSCheng C Yang   public:
87e83604beSCheng C Yang     /**
88e83604beSCheng C Yang      * Constructor
89e83604beSCheng C Yang      *
90e83604beSCheng C Yang      * @param[in] name - the device name
91e83604beSCheng C Yang      * @param[in] bus - smbus number
92e83604beSCheng C Yang      * @param[in] address - device address on smbus
93e83604beSCheng C Yang      * @param[in] order - ranking order of redundancy
94e83604beSCheng C Yang      * @param[in] dbusConnection - D-Bus connection
95e83604beSCheng C Yang      */
96e83604beSCheng C Yang     PowerSupply(
97e83604beSCheng C Yang         std::string& name, uint8_t bus, uint8_t address, uint8_t order,
98e83604beSCheng C Yang         const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
99e83604beSCheng C Yang     ~PowerSupply() = default;
100e83604beSCheng C Yang 
101e83604beSCheng C Yang     /**
102e83604beSCheng C Yang      * @brief Indicates the name of the device
103e83604beSCheng C Yang      *
104e83604beSCheng C Yang      * @details The PSU name such as PSU1
105e83604beSCheng C Yang      */
106e83604beSCheng C Yang     std::string name;
107e83604beSCheng C Yang 
108e83604beSCheng C Yang     /**
109e83604beSCheng C Yang      * @brief Indicates the smbus number
110e83604beSCheng C Yang      *
111e83604beSCheng C Yang      * @details The smbus number on the system
112e83604beSCheng C Yang      */
113e83604beSCheng C Yang     uint8_t bus;
114e83604beSCheng C Yang 
115e83604beSCheng C Yang     /**
116e83604beSCheng C Yang      * @brief Indicates the smbus address of the device
117e83604beSCheng C Yang      *
118e83604beSCheng C Yang      * @details The 7-bit smbus address of the PSU on smbus
119e83604beSCheng C Yang      */
120e83604beSCheng C Yang     uint8_t address;
121e83604beSCheng C Yang 
122e83604beSCheng C Yang     /**
123e83604beSCheng C Yang      * @brief Indicates the ranking order
124e83604beSCheng C Yang      *
125e83604beSCheng C Yang      * @details The order indicates the sequence entering standby mode.
126e83604beSCheng C Yang      *          the PSU with lower order will enter standby mode first.
127e83604beSCheng C Yang      */
128e83604beSCheng C Yang     uint8_t order = 0;
129e83604beSCheng C Yang 
130e83604beSCheng C Yang     /**
131e83604beSCheng C Yang      * @brief Indicates the status of the PSU
132e83604beSCheng C Yang      *
133e83604beSCheng C Yang      * @details If the PSU has no any problem, the status of it will be
134e83604beSCheng C Yang      *          normal otherwise acLost.
135e83604beSCheng C Yang      */
136e83604beSCheng C Yang     CR::PSUState state = CR::PSUState::normal;
137e83604beSCheng C Yang };
138