1 /** 2 * Copyright © 2020 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 #pragma once 17 18 #include "action.hpp" 19 20 #include <memory> 21 #include <utility> 22 #include <vector> 23 24 namespace phosphor::power::regulators 25 { 26 27 /** 28 * @class PresenceDetection 29 * 30 * Specifies how to detect whether a device is present. 31 * 32 * Some devices are only present in certain system configurations. For example: 33 * - A regulator is only present when a related processor or memory module is 34 * present. 35 * - A system supports multiple storage backplane types, and the device only 36 * exists on one of the backplanes. 37 * 38 * Device presence is detected by executing actions, such as 39 * ComparePresenceAction and CompareVPDAction. 40 * 41 * Device operations like configuration and sensor monitoring will only be 42 * performed if the actions indicate the device is present. 43 * 44 * Device presence will only be detected once per boot of the system. Presence 45 * will be determined prior to the first device operation (such as 46 * configuration). When the system is re-booted, presence will be re-detected. 47 * As a result, presence detection is not supported for devices that can be 48 * removed or added (hot-plugged) while the system is booted and running. 49 */ 50 class PresenceDetection 51 { 52 public: 53 // Specify which compiler-generated methods we want 54 PresenceDetection() = delete; 55 PresenceDetection(const PresenceDetection&) = delete; 56 PresenceDetection(PresenceDetection&&) = delete; 57 PresenceDetection& operator=(const PresenceDetection&) = delete; 58 PresenceDetection& operator=(PresenceDetection&&) = delete; 59 ~PresenceDetection() = default; 60 61 /** 62 * Constructor. 63 * 64 * @param actions actions that detect whether the device is present 65 */ 66 explicit PresenceDetection(std::vector<std::unique_ptr<Action>> actions) : 67 actions{std::move(actions)} 68 { 69 } 70 71 /** 72 * Executes the actions to detect whether the device is present. 73 * 74 * The return value of the last action indicates whether the device is 75 * present. A return value of true means the device is present; false means 76 * the device is missing. 77 * 78 * @return true if device is present, false otherwise 79 */ 80 bool execute() 81 { 82 // TODO: Create ActionEnvironment, execute actions, catch and handle any 83 // exceptions 84 return true; 85 } 86 87 /** 88 * Returns the actions that detect whether the device is present. 89 * 90 * @return actions 91 */ 92 const std::vector<std::unique_ptr<Action>>& getActions() const 93 { 94 return actions; 95 } 96 97 private: 98 /** 99 * Actions that detect whether the device is present. 100 */ 101 std::vector<std::unique_ptr<Action>> actions{}; 102 }; 103 104 } // namespace phosphor::power::regulators 105