1 #pragma once 2 3 #include <chrono> 4 #include <cmath> 5 #include <iostream> 6 #include <map> 7 #include <memory> 8 #include <mutex> 9 #include <set> 10 #include <string> 11 #include <tuple> 12 #include <vector> 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 static std::unique_ptr<ReadInterface> CreateDbusPassive( 38 sdbusplus::bus::bus& bus, const std::string& type, 39 const std::string& id, DbusHelperInterface *helper); 40 41 DbusPassive(sdbusplus::bus::bus& bus, 42 const std::string& type, 43 const std::string& id, 44 DbusHelperInterface *helper); 45 46 ReadReturn read(void) override; 47 48 void setValue(double value); 49 int64_t getScale(void); 50 std::string getId(void); 51 52 private: 53 sdbusplus::bus::bus& _bus; 54 sdbusplus::server::match::match _signal; 55 int64_t _scale; 56 std::string _id; // for debug identification 57 DbusHelperInterface *_helper; 58 59 std::mutex _lock; 60 double _value = 0; 61 /* The last time the value was refreshed, not necessarily changed. */ 62 std::chrono::high_resolution_clock::time_point _updated; 63 }; 64 65 int HandleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner); 66