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