blob: 2002a619d5b07fc37fc16ae9ded37a784c6f4de9 [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001#pragma once
2
3#include <chrono>
4
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005struct ReadReturn
6{
Patrick Venturee6206562018-03-08 15:36:53 -08007 double value;
8 std::chrono::high_resolution_clock::time_point updated;
Patrick Venturebd6b4762018-06-14 09:24:42 -07009
Patrick Venturee2ec0f62018-09-04 12:30:27 -070010 bool operator==(const ReadReturn& rhs) const
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070011 {
Patrick Venturebd6b4762018-06-14 09:24:42 -070012 return (this->value == rhs.value && this->updated == rhs.updated);
13 }
Patrick Venturee6206562018-03-08 15:36:53 -080014};
15
Patrick Venturee6206562018-03-08 15:36:53 -080016/*
17 * A ReadInterface is a plug-in for the PluggableSensor and anyone implementing
18 * this basically is providing a way to read a sensor.
19 */
20class ReadInterface
21{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070022 public:
23 ReadInterface()
Patrick Venturea83a3ec2020-08-04 09:52:05 -070024 {}
Patrick Venturee6206562018-03-08 15:36:53 -080025
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070026 virtual ~ReadInterface()
Patrick Venturea83a3ec2020-08-04 09:52:05 -070027 {}
Patrick Venturee6206562018-03-08 15:36:53 -080028
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070029 virtual ReadReturn read(void) = 0;
James Feist36b7d8e2018-10-05 15:39:01 -070030
31 virtual bool getFailed(void) const
32 {
33 return false;
34 }
Patrick Venturee6206562018-03-08 15:36:53 -080035};
36
37/*
38 * A WriteInterface is a plug-in for the PluggableSensor and anyone implementing
39 * this basically is providing a way to write a sensor.
40 */
41class WriteInterface
42{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070043 public:
44 WriteInterface(int64_t min, int64_t max) : _min(min), _max(max)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070045 {}
Patrick Venturee6206562018-03-08 15:36:53 -080046
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070047 virtual ~WriteInterface()
Patrick Venturea83a3ec2020-08-04 09:52:05 -070048 {}
Patrick Venturee6206562018-03-08 15:36:53 -080049
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070050 virtual void write(double value) = 0;
Patrick Venturee6206562018-03-08 15:36:53 -080051
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070052 /*
53 * All WriteInterfaces have min/max available in case they want to error
54 * check.
55 */
56 int64_t getMin(void)
57 {
58 return _min;
59 }
60 int64_t getMax(void)
61 {
62 return _max;
63 }
64
65 private:
66 int64_t _min;
67 int64_t _max;
Patrick Venturee6206562018-03-08 15:36:53 -080068};