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" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 4 | #include "dbus/util.hpp" |
| 5 | #include "interfaces.hpp" |
| 6 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 7 | #include <chrono> |
| 8 | #include <cmath> |
| 9 | #include <iostream> |
| 10 | #include <map> |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame] | 11 | #include <memory> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 12 | #include <mutex> |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 13 | #include <sdbusplus/bus.hpp> |
| 14 | #include <sdbusplus/message.hpp> |
| 15 | #include <sdbusplus/server.hpp> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 16 | #include <set> |
| 17 | #include <string> |
| 18 | #include <tuple> |
| 19 | #include <vector> |
| 20 | |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 21 | int dbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 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 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 36 | public: |
| 37 | static std::unique_ptr<ReadInterface> |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 38 | createDbusPassive(sdbusplus::bus::bus& bus, const std::string& type, |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 39 | const std::string& id, DbusHelperInterface* helper, |
James Feist | f81f288 | 2019-02-26 11:26:36 -0800 | [diff] [blame] | 40 | const conf::SensorConfig* info); |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame] | 41 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 42 | DbusPassive(sdbusplus::bus::bus& bus, const std::string& type, |
Patrick Venture | f8cb464 | 2018-10-30 12:02:53 -0700 | [diff] [blame] | 43 | const std::string& id, DbusHelperInterface* helper, |
| 44 | const struct SensorProperties& settings, bool failed); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 45 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 46 | ReadReturn read(void) override; |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 47 | bool getFailed(void) const override; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 48 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 49 | void setValue(double value); |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 50 | void setFailed(bool value); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 51 | int64_t getScale(void); |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 52 | std::string getID(void); |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 53 | double getMax(void); |
| 54 | double getMin(void); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 55 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 56 | private: |
| 57 | sdbusplus::bus::bus& _bus; |
| 58 | sdbusplus::server::match::match _signal; |
| 59 | int64_t _scale; |
| 60 | std::string _id; // for debug identification |
| 61 | DbusHelperInterface* _helper; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 62 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 63 | std::mutex _lock; |
| 64 | double _value = 0; |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 65 | double _max = 0; |
| 66 | double _min = 0; |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 67 | bool _failed = false; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 68 | /* The last time the value was refreshed, not necessarily changed. */ |
| 69 | std::chrono::high_resolution_clock::time_point _updated; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 72 | int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner); |