blob: 57ba04b4a51d947491052d4385e5a91610880f5b [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"
Patrick Ventureaadb30d2020-08-10 09:17:11 -07004#include "dbushelper_interface.hpp"
James Feist98b704e2019-06-03 16:24:53 -07005#include "dbuspassiveredundancy.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07006#include "interfaces.hpp"
James Feist0c8223b2019-05-08 15:33:33 -07007#include "util.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07008
Patrick Venturea83a3ec2020-08-04 09:52:05 -07009#include <sdbusplus/bus.hpp>
10#include <sdbusplus/message.hpp>
11#include <sdbusplus/server.hpp>
12
Patrick Venture863b9242018-03-08 08:29:23 -080013#include <chrono>
14#include <cmath>
15#include <iostream>
16#include <map>
Patrick Venture0ef1faf2018-06-13 12:50:53 -070017#include <memory>
Patrick Venture863b9242018-03-08 08:29:23 -080018#include <mutex>
19#include <set>
20#include <string>
21#include <tuple>
22#include <vector>
23
Patrick Venturea0764872020-08-08 07:48:43 -070024namespace pid_control
25{
26
Patrick Venture7af157b2018-10-30 11:24:40 -070027int dbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err);
Patrick Venture863b9242018-03-08 08:29:23 -080028
29/*
30 * This ReadInterface will passively listen for Value updates from whomever
31 * owns the associated dbus object.
32 *
33 * This requires another modification in phosphor-dbus-interfaces that will
34 * signal a value update every time it's read instead of only when it changes
35 * to help us:
36 * - ensure we're still receiving data (since we don't control the reader)
37 * - simplify stale data detection
38 * - simplify error detection
39 */
40class DbusPassive : public ReadInterface
41{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070042 public:
James Feist98b704e2019-06-03 16:24:53 -070043 static std::unique_ptr<ReadInterface> createDbusPassive(
44 sdbusplus::bus::bus& bus, const std::string& type,
Patrick Venture8729eb92020-08-10 10:38:44 -070045 const std::string& id, std::unique_ptr<DbusHelperInterface> helper,
James Feist98b704e2019-06-03 16:24:53 -070046 const conf::SensorConfig* info,
47 const std::shared_ptr<DbusPassiveRedundancy>& redundancy);
Patrick Venture0ef1faf2018-06-13 12:50:53 -070048
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070049 DbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
Patrick Venture8729eb92020-08-10 10:38:44 -070050 const std::string& id,
51 std::unique_ptr<DbusHelperInterface> helper,
James Feist98b704e2019-06-03 16:24:53 -070052 const struct SensorProperties& settings, bool failed,
53 const std::string& path,
54 const std::shared_ptr<DbusPassiveRedundancy>& redundancy);
Patrick Venture863b9242018-03-08 08:29:23 -080055
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070056 ReadReturn read(void) override;
James Feist36b7d8e2018-10-05 15:39:01 -070057 bool getFailed(void) const override;
Patrick Venture863b9242018-03-08 08:29:23 -080058
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070059 void setValue(double value);
James Feist36b7d8e2018-10-05 15:39:01 -070060 void setFailed(bool value);
James Feist4b36f262020-07-07 16:56:41 -070061 void setFunctional(bool value);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070062 int64_t getScale(void);
Patrick Venture563a3562018-10-30 09:31:26 -070063 std::string getID(void);
James Feist75eb7692019-02-25 12:50:02 -080064 double getMax(void);
65 double getMin(void);
Patrick Venture863b9242018-03-08 08:29:23 -080066
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070067 private:
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070068 sdbusplus::server::match::match _signal;
69 int64_t _scale;
70 std::string _id; // for debug identification
Patrick Venture8729eb92020-08-10 10:38:44 -070071 std::unique_ptr<DbusHelperInterface> _helper;
Patrick Venture863b9242018-03-08 08:29:23 -080072
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070073 std::mutex _lock;
74 double _value = 0;
James Feist75eb7692019-02-25 12:50:02 -080075 double _max = 0;
76 double _min = 0;
James Feist36b7d8e2018-10-05 15:39:01 -070077 bool _failed = false;
James Feist4b36f262020-07-07 16:56:41 -070078 bool _functional = true;
James Feist98b704e2019-06-03 16:24:53 -070079
80 std::string path;
81 std::shared_ptr<DbusPassiveRedundancy> redundancy;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070082 /* The last time the value was refreshed, not necessarily changed. */
83 std::chrono::high_resolution_clock::time_point _updated;
Patrick Venture863b9242018-03-08 08:29:23 -080084};
85
Patrick Venture7af157b2018-10-30 11:24:40 -070086int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner);
Patrick Venturea0764872020-08-08 07:48:43 -070087
88} // namespace pid_control