blob: 16cf8560d9619d7ccd1630fb7be5b9a244e5c02c [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 Venturea83a3ec2020-08-04 09:52:05 -07008#include <sdbusplus/bus.hpp>
9#include <sdbusplus/message.hpp>
10#include <sdbusplus/server.hpp>
11
Patrick Venture863b9242018-03-08 08:29:23 -080012#include <chrono>
13#include <cmath>
14#include <iostream>
15#include <map>
Patrick Venture0ef1faf2018-06-13 12:50:53 -070016#include <memory>
Patrick Venture863b9242018-03-08 08:29:23 -080017#include <mutex>
18#include <set>
19#include <string>
20#include <tuple>
21#include <vector>
22
Patrick Venture7af157b2018-10-30 11:24:40 -070023int dbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err);
Patrick Venture863b9242018-03-08 08:29:23 -080024
25/*
26 * This ReadInterface will passively listen for Value updates from whomever
27 * owns the associated dbus object.
28 *
29 * This requires another modification in phosphor-dbus-interfaces that will
30 * signal a value update every time it's read instead of only when it changes
31 * to help us:
32 * - ensure we're still receiving data (since we don't control the reader)
33 * - simplify stale data detection
34 * - simplify error detection
35 */
36class DbusPassive : public ReadInterface
37{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070038 public:
James Feist98b704e2019-06-03 16:24:53 -070039 static std::unique_ptr<ReadInterface> createDbusPassive(
40 sdbusplus::bus::bus& bus, const std::string& type,
41 const std::string& id, DbusHelperInterface* helper,
42 const conf::SensorConfig* info,
43 const std::shared_ptr<DbusPassiveRedundancy>& redundancy);
Patrick Venture0ef1faf2018-06-13 12:50:53 -070044
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070045 DbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
Patrick Venturef8cb4642018-10-30 12:02:53 -070046 const std::string& id, DbusHelperInterface* helper,
James Feist98b704e2019-06-03 16:24:53 -070047 const struct SensorProperties& settings, bool failed,
48 const std::string& path,
49 const std::shared_ptr<DbusPassiveRedundancy>& redundancy);
Patrick Venture863b9242018-03-08 08:29:23 -080050
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070051 ReadReturn read(void) override;
James Feist36b7d8e2018-10-05 15:39:01 -070052 bool getFailed(void) const override;
Patrick Venture863b9242018-03-08 08:29:23 -080053
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070054 void setValue(double value);
James Feist36b7d8e2018-10-05 15:39:01 -070055 void setFailed(bool value);
James Feist4b36f262020-07-07 16:56:41 -070056 void setFunctional(bool value);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070057 int64_t getScale(void);
Patrick Venture563a3562018-10-30 09:31:26 -070058 std::string getID(void);
James Feist75eb7692019-02-25 12:50:02 -080059 double getMax(void);
60 double getMin(void);
Patrick Venture863b9242018-03-08 08:29:23 -080061
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070062 private:
63 sdbusplus::bus::bus& _bus;
64 sdbusplus::server::match::match _signal;
65 int64_t _scale;
66 std::string _id; // for debug identification
67 DbusHelperInterface* _helper;
Patrick Venture863b9242018-03-08 08:29:23 -080068
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070069 std::mutex _lock;
70 double _value = 0;
James Feist75eb7692019-02-25 12:50:02 -080071 double _max = 0;
72 double _min = 0;
James Feist36b7d8e2018-10-05 15:39:01 -070073 bool _failed = false;
James Feist4b36f262020-07-07 16:56:41 -070074 bool _functional = true;
James Feist98b704e2019-06-03 16:24:53 -070075
76 std::string path;
77 std::shared_ptr<DbusPassiveRedundancy> redundancy;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070078 /* The last time the value was refreshed, not necessarily changed. */
79 std::chrono::high_resolution_clock::time_point _updated;
Patrick Venture863b9242018-03-08 08:29:23 -080080};
81
Patrick Venture7af157b2018-10-30 11:24:40 -070082int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner);