blob: 545b928b92b51ae6a68a2faf0b87cc37af1e3723 [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>
Patrick Venture0ef1faf2018-06-13 12:50:53 -07007#include <memory>
Patrick Venture863b9242018-03-08 08:29:23 -08008#include <mutex>
9#include <set>
10#include <string>
11#include <tuple>
12#include <vector>
13
Patrick Venture863b9242018-03-08 08:29:23 -080014#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
21int 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 */
34class DbusPassive : public ReadInterface
35{
36 public:
Patrick Venture0ef1faf2018-06-13 12:50:53 -070037 static std::unique_ptr<ReadInterface> CreateDbusPassive(
38 sdbusplus::bus::bus& bus, const std::string& type,
39 const std::string& id, DbusHelperInterface *helper);
40
Patrick Venture863b9242018-03-08 08:29:23 -080041 DbusPassive(sdbusplus::bus::bus& bus,
42 const std::string& type,
Patrick Venture0df7c0f2018-06-13 09:02:13 -070043 const std::string& id,
44 DbusHelperInterface *helper);
Patrick Venture863b9242018-03-08 08:29:23 -080045
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 Venture0df7c0f2018-06-13 09:02:13 -070057 DbusHelperInterface *_helper;
Patrick Venture863b9242018-03-08 08:29:23 -080058
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 Venture0df7c0f2018-06-13 09:02:13 -070065int HandleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner);