summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-07-25 19:02:15 -0400
committerPatrick Williams <patrick@stwcx.xyz>2017-08-02 20:18:19 +0000
commit617495111eae22fe82f1e430ad69697675635595 (patch)
tree1df7e49a013b05871168e93ad64ea781ab2dbf9b
parentd516c61b6fa55edc6ed55bd685686b12d5c876ac (diff)
downloadphosphor-fan-presence-617495111eae22fe82f1e430ad69697675635595.tar.gz
phosphor-fan-presence-617495111eae22fe82f1e430ad69697675635595.zip
presence: Add sensor comparison
Add a basic comparison operator for presence sensors. Change-Id: Ib147fd24f6e9ea1daf5f2b0b71943e0b4c96a8b7 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--presence/Makefile.am1
-rw-r--r--presence/psensor.cpp28
-rw-r--r--presence/psensor.hpp20
3 files changed, 48 insertions, 1 deletions
diff --git a/presence/Makefile.am b/presence/Makefile.am
index db7e459..e144858 100644
--- a/presence/Makefile.am
+++ b/presence/Makefile.am
@@ -8,6 +8,7 @@ phosphor_fan_presence_tach_SOURCES = \
fallback.cpp \
fan.cpp \
gpio.cpp \
+ psensor.cpp \
tach.cpp \
tach_detect.cpp
diff --git a/presence/psensor.cpp b/presence/psensor.cpp
new file mode 100644
index 0000000..9294dcd
--- /dev/null
+++ b/presence/psensor.cpp
@@ -0,0 +1,28 @@
+/**
+ * Copyright © 2017 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "psensor.hpp"
+
+namespace phosphor
+{
+namespace fan
+{
+namespace presence
+{
+std::size_t PresenceSensor::nextId = 1;
+
+} // namespace presence
+} // namespace fan
+} // namespace phosphor
diff --git a/presence/psensor.hpp b/presence/psensor.hpp
index 096c96c..7afbd75 100644
--- a/presence/psensor.hpp
+++ b/presence/psensor.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include <cstdint>
namespace phosphor
{
@@ -26,7 +27,10 @@ class PresenceSensor
PresenceSensor(PresenceSensor&&) = default;
PresenceSensor& operator=(PresenceSensor&&) = default;
virtual ~PresenceSensor() = default;
- PresenceSensor() = default;
+ PresenceSensor() : id(nextId)
+ {
+ nextId++;
+ }
/**
* @brief start
@@ -70,8 +74,22 @@ class PresenceSensor
* Provide a default noop implementation.
*/
virtual void fail() {}
+
+ friend bool operator==(const PresenceSensor& l, const PresenceSensor& r);
+
+ private:
+ /** @brief Unique sensor ID. */
+ std::size_t id;
+
+ /** @brief The next unique sensor ID. */
+ static std::size_t nextId;
};
+inline bool operator==(const PresenceSensor& l, const PresenceSensor &r)
+{
+ return l.id == r.id;
+}
+
} // namespace presence
} // namespace fan
} // namespace phosphor
OpenPOWER on IntegriCloud