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