blob: f00a2ea31745d3cd10ee02a448c5b5242c2fc69e [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001#pragma once
2
James Feist75eb7692019-02-25 12:50:02 -08003#include "conf.hpp"
James Feist98b704e2019-06-03 16:24:53 -07004#include "dbuspassiveredundancy.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005#include "interfaces.hpp"
James Feist0c8223b2019-05-08 15:33:33 -07006#include "util.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07007
Patrick Venture863b9242018-03-08 08:29:23 -08008#include <chrono>
9#include <cmath>
10#include <iostream>
11#include <map>
Patrick Venture0ef1faf2018-06-13 12:50:53 -070012#include <memory>
Patrick Venture863b9242018-03-08 08:29:23 -080013#include <mutex>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070014#include <sdbusplus/bus.hpp>
15#include <sdbusplus/message.hpp>
16#include <sdbusplus/server.hpp>
Patrick Venture863b9242018-03-08 08:29:23 -080017#include <set>
18#include <string>
19#include <tuple>
20#include <vector>
21
Patrick Venture7af157b2018-10-30 11:24:40 -070022int dbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err);
Patrick Venture863b9242018-03-08 08:29:23 -080023
24/*
25 * This ReadInterface will passively listen for Value updates from whomever
26 * owns the associated dbus object.
27 *
28 * This requires another modification in phosphor-dbus-interfaces that will
29 * signal a value update every time it's read instead of only when it changes
30 * to help us:
31 * - ensure we're still receiving data (since we don't control the reader)
32 * - simplify stale data detection
33 * - simplify error detection
34 */
35class DbusPassive : public ReadInterface
36{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070037 public:
James Feist98b704e2019-06-03 16:24:53 -070038 static std::unique_ptr<ReadInterface> createDbusPassive(
39 sdbusplus::bus::bus& bus, const std::string& type,
40 const std::string& id, DbusHelperInterface* helper,
41 const conf::SensorConfig* info,
42 const std::shared_ptr<DbusPassiveRedundancy>& redundancy);
Patrick Venture0ef1faf2018-06-13 12:50:53 -070043
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070044 DbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
Patrick Venturef8cb4642018-10-30 12:02:53 -070045 const std::string& id, DbusHelperInterface* helper,
James Feist98b704e2019-06-03 16:24:53 -070046 const struct SensorProperties& settings, bool failed,
47 const std::string& path,
48 const std::shared_ptr<DbusPassiveRedundancy>& redundancy);
Patrick Venture863b9242018-03-08 08:29:23 -080049
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070050 ReadReturn read(void) override;
James Feist36b7d8e2018-10-05 15:39:01 -070051 bool getFailed(void) const override;
Patrick Venture863b9242018-03-08 08:29:23 -080052
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070053 void setValue(double value);
James Feist36b7d8e2018-10-05 15:39:01 -070054 void setFailed(bool value);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070055 int64_t getScale(void);
Patrick Venture563a3562018-10-30 09:31:26 -070056 std::string getID(void);
James Feist75eb7692019-02-25 12:50:02 -080057 double getMax(void);
58 double getMin(void);
Patrick Venture863b9242018-03-08 08:29:23 -080059
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060 private:
61 sdbusplus::bus::bus& _bus;
62 sdbusplus::server::match::match _signal;
63 int64_t _scale;
64 std::string _id; // for debug identification
65 DbusHelperInterface* _helper;
Patrick Venture863b9242018-03-08 08:29:23 -080066
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070067 std::mutex _lock;
68 double _value = 0;
James Feist75eb7692019-02-25 12:50:02 -080069 double _max = 0;
70 double _min = 0;
James Feist36b7d8e2018-10-05 15:39:01 -070071 bool _failed = false;
James Feist98b704e2019-06-03 16:24:53 -070072
73 std::string path;
74 std::shared_ptr<DbusPassiveRedundancy> redundancy;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070075 /* The last time the value was refreshed, not necessarily changed. */
76 std::chrono::high_resolution_clock::time_point _updated;
Patrick Venture863b9242018-03-08 08:29:23 -080077};
78
Patrick Venture7af157b2018-10-30 11:24:40 -070079int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner);