diff options
-rw-r--r-- | presence/Makefile.am | 1 | ||||
-rw-r--r-- | presence/psensor.cpp | 28 | ||||
-rw-r--r-- | presence/psensor.hpp | 20 |
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 |