xref: /openbmc/phosphor-power/tools/power-utils/validator.hpp (revision 2ae582185602511620aca1dd1c0256171b7547bb)
1 /**
2  * Copyright © 2025 IBM 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 #pragma once
18 
19 #include "types.hpp"
20 #include "utility.hpp"
21 
22 #include <sdbusplus/bus.hpp>
23 
24 #include <string>
25 
26 namespace validator
27 {
28 using namespace phosphor::power::util;
29 /**
30  * @class PSUUpdateValidator
31  * @brief This class validates PSU configurations in OpenBMC.
32  */
33 class PSUUpdateValidator
34 {
35   public:
36     /**
37      * @brief Constructor - Initializes D-Bus connection.
38      *
39      * @param bus The sdbusplus DBus bus connection
40      * @param psuPath PSU inventory path
41      */
PSUUpdateValidator(sdbusplus::bus_t & bus,const std::string & psuPath)42     PSUUpdateValidator(sdbusplus::bus_t& bus, const std::string& psuPath) :
43         bus(bus), psuPath(psuPath)
44     {}
45 
46     /**
47      * @brief Checks if all PSUs are of the same model.
48      *
49      * @return true if all PSUs have the same model.
50      * @return false if any PSU has a different model.
51      */
52     bool areAllPsuSameModel();
53 
54     /**
55      * @brief Counts the number of PSUs that are physically present and
56      * operational
57      *
58      * @return true if successfully counted present PSUs.
59      * @return false on failure.
60      */
61     bool countPresentPsus();
62 
63     /**
64      * @brief Retrieves the required number of PSUs for redundancy.
65      *
66      * @return true if successfully retrieved redundancy count.
67      * @return false on failure.
68      */
69     bool getRequiredPsus();
70 
71     /**
72      * @brief Ensure all PSUs have same model, validate all PSUs present
73      * and functional meet or exceed the number of PSUs required for this
74      * system
75      *
76      * @return true if all configuration requirement are met.
77      * @return otherwise false
78      */
79     bool validToUpdate();
80 
81     /**
82      * @brief Retrieves the operational PSU status.
83      *
84      * @return true if operational
85      * @return false on operational failure.
86      */
87     bool isItFunctional(const std::string& path);
88 
89   private:
90     sdbusplus::bus_t& bus;             // D-Bus connection instance
91     std::vector<std::string> psuPaths; // List of PSU object paths
92     std::string targetPsuModel;        // Model name of the reference PSU
93     std::string psuPath;               // Path  of the referenced PSU
94     DbusSubtree supportedObjects;      // D-Bus PSU supported objects
95     DbusPropertyMap properties;        // D-Bus PSU properties
96     int presentPsuCount = 0;           // Count of physically present PSUs
97     int redundantCount = 0;            // Total number of PSUs required to be
98                                        // in this system configuration.
99 };
100 
101 } // namespace validator
102