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