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 14 #include <sdbusplus/bus.hpp> 15 #include <sdbusplus/message.hpp> 16 #include <sdbusplus/server.hpp> 17 18 #include "interfaces.hpp" 19 #include "dbus/util.hpp" 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 DbusPassive(sdbusplus::bus::bus& bus, 38 const std::string& type, 39 const std::string& id); 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 53 std::mutex _lock; 54 double _value = 0; 55 /* The last time the value was refreshed, not necessarily changed. */ 56 std::chrono::high_resolution_clock::time_point _updated; 57 }; 58 59