blob: 1a5446244ab8fceb8b2ea8efbc3bc18300a38885 [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
Cheng C Yange83604b2020-01-09 09:41:47 +080032 * @param[in] dbusConnection - D-Bus connection
33 */
34 ColdRedundancy(
35 boost::asio::io_service& io,
Cheng C Yange83604b2020-01-09 09:41:47 +080036 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 */
Patrick Williams92261f82025-02-01 08:22:34 -050044 void createPSU(
45 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
Cheng C Yange83604b2020-01-09 09:41:47 +080046
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 */
Patrick Williams7354ce62022-07-22 19:26:56 -050077 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches;
Cheng C Yange83604b2020-01-09 09:41:47 +080078};
79
80/**
81 * @class PowerSupply
82 * Represents a power supply device.
83 */
84class 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};