Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <chrono> |
| 4 | #include <cmath> |
| 5 | #include <iostream> |
| 6 | #include <map> |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame^] | 7 | #include <memory> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 8 | #include <mutex> |
| 9 | #include <set> |
| 10 | #include <string> |
| 11 | #include <tuple> |
| 12 | #include <vector> |
| 13 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 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: |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame^] | 37 | static std::unique_ptr<ReadInterface> CreateDbusPassive( |
| 38 | sdbusplus::bus::bus& bus, const std::string& type, |
| 39 | const std::string& id, DbusHelperInterface *helper); |
| 40 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 41 | DbusPassive(sdbusplus::bus::bus& bus, |
| 42 | const std::string& type, |
Patrick Venture | 0df7c0f | 2018-06-13 09:02:13 -0700 | [diff] [blame] | 43 | const std::string& id, |
| 44 | DbusHelperInterface *helper); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 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 |
Patrick Venture | 0df7c0f | 2018-06-13 09:02:13 -0700 | [diff] [blame] | 57 | DbusHelperInterface *_helper; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 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 | |
Patrick Venture | 0df7c0f | 2018-06-13 09:02:13 -0700 | [diff] [blame] | 65 | int HandleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner); |