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] 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 */ 79 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches; 80 }; 81 82 /** 83 * @class PowerSupply 84 * Represents a power supply device. 85 */ 86 class 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 }; 140