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