presence: Add sensor comparison

Add a basic comparison operator for presence sensors.

Change-Id: Ib147fd24f6e9ea1daf5f2b0b71943e0b4c96a8b7
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
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 @@
 	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 @@
         PresenceSensor(PresenceSensor&&) = default;
         PresenceSensor& operator=(PresenceSensor&&) = default;
         virtual ~PresenceSensor() = default;
-        PresenceSensor() = default;
+        PresenceSensor() : id(nextId)
+        {
+            nextId++;
+        }
 
         /**
          * @brief start
@@ -70,8 +74,22 @@
          * 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