Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 1 | #include <atomic> |
| 2 | #include <condition_variable> |
| 3 | #include <mutex> |
| 4 | #include <thread> |
| 5 | #include "IETFHardware.h" |
| 6 | #include "ietf-hardware/sysfs/HWMon.h" |
| 7 | |
| 8 | namespace velia::ietf_hardware { |
| 9 | class TransientI2C { |
| 10 | public: |
| 11 | TransientI2C(const uint8_t bus, const uint8_t address, const std::string& driverName); |
| 12 | virtual ~TransientI2C(); |
| 13 | virtual bool isPresent() const; |
| 14 | virtual void bind() const; |
| 15 | virtual void unbind() const; |
| 16 | private: |
| 17 | uint8_t m_address; |
| 18 | std::string m_driverName; |
| 19 | std::string m_isPresentPath; |
| 20 | std::string m_bindPath; |
| 21 | std::string m_unbindPath; |
| 22 | std::string m_addressString; |
| 23 | }; |
| 24 | |
| 25 | /** |
| 26 | * This class manages two things: |
| 27 | * 1) dynamic loading/unloading of the driver for the PSUs |
| 28 | * 2) reading of hwmon values for the PSUs |
| 29 | */ |
| 30 | struct FspYhPsu { |
| 31 | public: |
| 32 | FspYhPsu(const std::filesystem::path& hwmonDir, const std::string& psuName, std::shared_ptr<TransientI2C> i2c); |
| 33 | ~FspYhPsu(); |
| 34 | velia::ietf_hardware::DataTree readValues(); |
| 35 | private: |
| 36 | std::mutex m_mtx; |
| 37 | std::mutex m_condMtx; |
| 38 | std::condition_variable m_cond; |
| 39 | std::thread m_psuWatcher; |
| 40 | std::atomic<bool> m_exit; |
| 41 | std::shared_ptr<TransientI2C> m_i2c; |
| 42 | |
| 43 | std::filesystem::path m_hwmonDir; |
| 44 | std::string m_psuName; |
| 45 | |
| 46 | std::shared_ptr<velia::ietf_hardware::sysfs::HWMon> m_hwmon; |
Tomáš Pecka | 23536bf | 2023-04-27 18:30:55 +0200 | [diff] [blame] | 47 | |
| 48 | std::string m_namePrefix; |
| 49 | velia::ietf_hardware::DataTree m_staticData; |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 50 | std::vector<std::function<velia::ietf_hardware::DataTree()>> m_properties; |
| 51 | |
| 52 | void createPower(); |
| 53 | }; |
| 54 | } |