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