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