blob: 8ecfe7123b4b3497dae8cf6579617c2abb1c00cf [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001#pragma once
2
3#include <chrono>
4#include <cmath>
5#include <iostream>
6#include <map>
7#include <mutex>
8#include <set>
9#include <string>
10#include <tuple>
11#include <vector>
12
Patrick Venture863b9242018-03-08 08:29:23 -080013#include <sdbusplus/bus.hpp>
14#include <sdbusplus/message.hpp>
15#include <sdbusplus/server.hpp>
16
17#include "interfaces.hpp"
18#include "dbus/util.hpp"
19
20int 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 */
33class DbusPassive : public ReadInterface
34{
35 public:
36 DbusPassive(sdbusplus::bus::bus& bus,
37 const std::string& type,
Patrick Venture0df7c0f2018-06-13 09:02:13 -070038 const std::string& id,
39 DbusHelperInterface *helper);
Patrick Venture863b9242018-03-08 08:29:23 -080040
41 ReadReturn read(void) override;
42
43 void setValue(double value);
44 int64_t getScale(void);
45 std::string getId(void);
46
47 private:
48 sdbusplus::bus::bus& _bus;
49 sdbusplus::server::match::match _signal;
50 int64_t _scale;
51 std::string _id; // for debug identification
Patrick Venture0df7c0f2018-06-13 09:02:13 -070052 DbusHelperInterface *_helper;
Patrick Venture863b9242018-03-08 08:29:23 -080053
54 std::mutex _lock;
55 double _value = 0;
56 /* The last time the value was refreshed, not necessarily changed. */
57 std::chrono::high_resolution_clock::time_point _updated;
58};
59
Patrick Venture0df7c0f2018-06-13 09:02:13 -070060int HandleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner);