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