1 #pragma once 2 3 #include "conf.hpp" 4 #include "dbushelper_interface.hpp" 5 #include "dbuspassiveredundancy.hpp" 6 #include "interfaces.hpp" 7 #include "util.hpp" 8 9 #include <sdbusplus/bus.hpp> 10 #include <sdbusplus/bus/match.hpp> 11 #include <sdbusplus/message.hpp> 12 13 #include <chrono> 14 #include <cmath> 15 #include <iostream> 16 #include <map> 17 #include <memory> 18 #include <mutex> 19 #include <set> 20 #include <string> 21 #include <tuple> 22 #include <vector> 23 24 namespace pid_control 25 { 26 27 int dbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err); 28 29 /* 30 * This ReadInterface will passively listen for Value updates from whomever 31 * owns the associated dbus object. 32 * 33 * This requires another modification in phosphor-dbus-interfaces that will 34 * signal a value update every time it's read instead of only when it changes 35 * to help us: 36 * - ensure we're still receiving data (since we don't control the reader) 37 * - simplify stale data detection 38 * - simplify error detection 39 */ 40 class DbusPassive : public ReadInterface 41 { 42 public: 43 static std::unique_ptr<ReadInterface> createDbusPassive( 44 sdbusplus::bus_t& bus, const std::string& type, const std::string& id, 45 std::unique_ptr<DbusHelperInterface> helper, 46 const conf::SensorConfig* info, 47 const std::shared_ptr<DbusPassiveRedundancy>& redundancy); 48 49 DbusPassive(sdbusplus::bus_t& bus, const std::string& type, 50 const std::string& id, 51 std::unique_ptr<DbusHelperInterface> helper, 52 const SensorProperties& settings, bool failed, 53 const std::string& path, 54 const std::shared_ptr<DbusPassiveRedundancy>& redundancy); 55 56 ReadReturn read(void) override; 57 bool getFailed(void) const override; 58 59 void updateValue(double value, bool force); 60 void setValue(double value, double unscaled); 61 void setValue(double value); 62 63 void setFailed(bool value); 64 void setFunctional(bool value); 65 void setAvailable(bool value); 66 67 int64_t getScale(void); 68 std::string getID(void); 69 double getMax(void); 70 double getMin(void); 71 72 private: 73 sdbusplus::bus::match_t _signal; 74 int64_t _scale; 75 std::string _id; // for debug identification 76 std::unique_ptr<DbusHelperInterface> _helper; 77 78 std::mutex _lock; 79 double _value = 0; 80 double _unscaled = 0; 81 double _max = 0; 82 double _min = 0; 83 bool _failed = false; 84 bool _functional = true; 85 bool _available = true; 86 bool _unavailableAsFailed = true; 87 88 bool _typeMargin = false; 89 bool _typeFan = false; 90 bool _badReading = false; 91 bool _marginHot = false; 92 93 std::string path; 94 std::shared_ptr<DbusPassiveRedundancy> redundancy; 95 /* The last time the value was refreshed, not necessarily changed. */ 96 std::chrono::high_resolution_clock::time_point _updated; 97 }; 98 99 int handleSensorValue(sdbusplus::message_t& msg, DbusPassive* owner); 100 101 } // namespace pid_control 102