1 #pragma once 2 3 #include <memory> 4 #include "evdevpp/evdev.hpp" 5 #include "sdevent/io.hpp" 6 #include "sdevent/source.hpp" 7 #include "psensor.hpp" 8 #include "utility.hpp" 9 10 namespace phosphor 11 { 12 namespace fan 13 { 14 namespace presence 15 { 16 class RedundancyPolicy; 17 18 /** 19 * @class Gpio 20 * @brief Gpio presence sensor implementation. 21 * 22 * The Gpio class uses a gpio wire to determine presence state. 23 */ 24 class Gpio : public PresenceSensor 25 { 26 public: 27 /** 28 * @brief 29 * 30 * Cannot move or copy due to this ptr as context 31 * for sdevent callbacks. 32 */ 33 Gpio() = delete; 34 Gpio(const Gpio&) = delete; 35 Gpio& operator=(const Gpio&) = delete; 36 Gpio(Gpio&&) = delete; 37 Gpio& operator=(Gpio&&) = delete; 38 ~Gpio() = default; 39 40 /** 41 * @brief Construct a gpio sensor. 42 * 43 * @param[in] physDevice - The physical gpio device path. 44 * @param[in] physPin - The physical gpio pin number. 45 */ 46 Gpio(const std::string& physDevice, unsigned int physPin); 47 48 /** 49 * @brief start 50 * 51 * Register for an sdevent io callback on the gpio. 52 * Query the initial state of the gpio. 53 * 54 * @return The current sensor state. 55 */ 56 bool start() override; 57 58 /** 59 * @brief stop 60 * 61 * De-register sdevent io callback. 62 */ 63 void stop() override; 64 65 /** 66 * @brief fail 67 * 68 * Call the gpio out. 69 */ 70 void fail() override; 71 72 /** 73 * @brief Check the sensor. 74 * 75 * Query the gpio. 76 */ 77 bool present() override; 78 79 private : 80 /** @brief Get the policy associated with this sensor. */ 81 virtual RedundancyPolicy& getPolicy() = 0; 82 83 /** @brief sdevent io callback. */ 84 void ioCallback(sdevent::source::Source& source); 85 86 /** The current state of the sensor. */ 87 bool currentState; 88 89 /** Gpio event device file descriptor. */ 90 util::FileDescriptor evdevfd; 91 92 /** Gpio event device. */ 93 evdevpp::evdev::EvDev evdev; 94 95 /** Physical gpio device. */ 96 std::string phys; 97 98 /** Gpio pin number. */ 99 unsigned int pin; 100 101 /** sdevent io callback handle. */ 102 std::unique_ptr<sdevent::event::io::IO> callback; 103 }; 104 105 } // namespace presence 106 } // namespace fan 107 } // namespace phosphor 108