blob: 91733e9d9d73ffc2ab0a20f02a8fcbf236208244 [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);
James Feist4b36f262020-07-07 16:56:41 -070055 void setFunctional(bool value);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070056 int64_t getScale(void);
Patrick Venture563a3562018-10-30 09:31:26 -070057 std::string getID(void);
James Feist75eb7692019-02-25 12:50:02 -080058 double getMax(void);
59 double getMin(void);
Patrick Venture863b9242018-03-08 08:29:23 -080060
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070061 private:
62 sdbusplus::bus::bus& _bus;
63 sdbusplus::server::match::match _signal;
64 int64_t _scale;
65 std::string _id; // for debug identification
66 DbusHelperInterface* _helper;
Patrick Venture863b9242018-03-08 08:29:23 -080067
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070068 std::mutex _lock;
69 double _value = 0;
James Feist75eb7692019-02-25 12:50:02 -080070 double _max = 0;
71 double _min = 0;
James Feist36b7d8e2018-10-05 15:39:01 -070072 bool _failed = false;
James Feist4b36f262020-07-07 16:56:41 -070073 bool _functional = true;
James Feist98b704e2019-06-03 16:24:53 -070074
75 std::string path;
76 std::shared_ptr<DbusPassiveRedundancy> redundancy;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070077 /* The last time the value was refreshed, not necessarily changed. */
78 std::chrono::high_resolution_clock::time_point _updated;
Patrick Venture863b9242018-03-08 08:29:23 -080079};
80
Patrick Venture7af157b2018-10-30 11:24:40 -070081int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner);