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