blob: 756b5cbc78fa61c3ff872360f83744929293a5d9 [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001#pragma once
2
Patrick Venture863b9242018-03-08 08:29:23 -08003#include "interfaces.hpp"
4#include "sensor.hpp"
5
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07006#include <sdbusplus/bus.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -07007
8#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07009#include <string>
Patrick Venture863b9242018-03-08 08:29:23 -080010
11/*
12 * A Sensor that can use any reader or writer you provide.
13 */
14class PluggableSensor : public Sensor
15{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070016 public:
17 PluggableSensor(const std::string& name, int64_t timeout,
18 std::unique_ptr<ReadInterface> reader,
19 std::unique_ptr<WriteInterface> writer) :
20 Sensor(name, timeout),
21 _reader(std::move(reader)), _writer(std::move(writer))
Patrick Venturea83a3ec2020-08-04 09:52:05 -070022 {}
Patrick Venture863b9242018-03-08 08:29:23 -080023
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070024 ReadReturn read(void) override;
25 void write(double value) override;
James Feist36b7d8e2018-10-05 15:39:01 -070026 bool getFailed(void) override;
Patrick Venture863b9242018-03-08 08:29:23 -080027
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070028 private:
29 std::unique_ptr<ReadInterface> _reader;
30 std::unique_ptr<WriteInterface> _writer;
Patrick Venture863b9242018-03-08 08:29:23 -080031};