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 <sdbusplus/asio/object_server.hpp>
18 #include <util.hpp>
19 
20 /**
21  * @class ColdRedundancy
22  *
23  */
24 class ColdRedundancy
25 {
26   public:
27     /**
28      * Constructor
29      *
30      * @param[in] io - boost asio context
31      * @param[in] objectServer - D-Bus object
32      * @param[in] dbusConnection - D-Bus connection
33      */
34     ColdRedundancy(
35         boost::asio::io_service& io,
36         sdbusplus::asio::object_server& objectServer,
37         std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
38 
39     /**
40      * Checking PSU information, adding matches, starting rotation
41      * and creating PSU objects
42      *
43      * @param[in] dbusConnection - D-Bus connection
44      */
45     void
46         createPSU(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
47 
48   private:
49     /**
50      * @brief Indicates the count of PSUs
51      *
52      * @details Indicates how many PSUs are there on the system.
53      */
54     uint8_t numberOfPSU = 0;
55 
56     /**
57      * @brief Indicates the delay timer
58      *
59      * @details Each time this daemon start, need a delay to avoid
60      *          different PSUs calling createPSU function for
61      *          several times at same time
62      */
63     boost::asio::steady_timer filterTimer;
64 
65     /**
66      * @brief Indicates the dbus connction
67      */
68     std::shared_ptr<sdbusplus::asio::connection>& systemBus;
69 
70     /**
71      * @brief Indicates the D-Bus matches
72      *
73      * @details This matches contain all matches in this daemon such
74      *          as PSU event match, PSU information match. The target
75      *          D-Bus properties change will trigger callback function
76      *          by these matches
77      */
78     std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
79 };
80 
81 /**
82  * @class PowerSupply
83  * Represents a power supply device.
84  */
85 class PowerSupply
86 {
87   public:
88     /**
89      * Constructor
90      *
91      * @param[in] name - the device name
92      * @param[in] bus - smbus number
93      * @param[in] address - device address on smbus
94      * @param[in] order - ranking order of redundancy
95      * @param[in] dbusConnection - D-Bus connection
96      */
97     PowerSupply(
98         std::string& name, uint8_t bus, uint8_t address, uint8_t order,
99         const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
100     ~PowerSupply() = default;
101 
102     /**
103      * @brief Indicates the name of the device
104      *
105      * @details The PSU name such as PSU1
106      */
107     std::string name;
108 
109     /**
110      * @brief Indicates the smbus number
111      *
112      * @details The smbus number on the system
113      */
114     uint8_t bus;
115 
116     /**
117      * @brief Indicates the smbus address of the device
118      *
119      * @details The 7-bit smbus address of the PSU on smbus
120      */
121     uint8_t address;
122 
123     /**
124      * @brief Indicates the ranking order
125      *
126      * @details The order indicates the sequence entering standby mode.
127      *          the PSU with lower order will enter standby mode first.
128      */
129     uint8_t order = 0;
130 
131     /**
132      * @brief Indicates the status of the PSU
133      *
134      * @details If the PSU has no any problem, the status of it will be
135      *          normal otherwise acLost.
136      */
137     CR::PSUState state = CR::PSUState::normal;
138 };
139