Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 17 | #include <NVMeSensor.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 18 | |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 19 | #include <iostream> |
| 20 | |
| 21 | static constexpr double maxReading = 127; |
| 22 | static constexpr double minReading = 0; |
| 23 | |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 24 | NVMeSensor::NVMeSensor(sdbusplus::asio::object_server& objectServer, |
James Feist | 7d7579f | 2020-09-02 14:13:08 -0700 | [diff] [blame] | 25 | boost::asio::io_service&, |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 26 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 27 | const std::string& sensorName, |
Jeff Lin | 7b7a9de | 2021-02-22 11:16:27 +0800 | [diff] [blame] | 28 | std::vector<thresholds::Threshold>&& thresholdsIn, |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 29 | const std::string& sensorConfiguration, |
| 30 | const int busNumber) : |
Zhikui Ren | da98f09 | 2021-11-01 09:41:08 -0700 | [diff] [blame] | 31 | Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration, |
Andrew Jeffery | 0c23fc3 | 2021-12-08 16:48:30 +1030 | [diff] [blame] | 32 | NVMeSensor::CONFIG_TYPE, false, false, maxReading, minReading, conn, |
| 33 | PowerState::on), |
Andrew Jeffery | 18fffd3 | 2021-06-09 16:56:53 +0930 | [diff] [blame] | 34 | bus(busNumber), objServer(objectServer) |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 35 | { |
| 36 | sensorInterface = objectServer.add_interface( |
| 37 | "/xyz/openbmc_project/sensors/temperature/" + name, |
| 38 | "xyz.openbmc_project.Sensor.Value"); |
| 39 | |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame^] | 40 | for (const auto& threshold : thresholds) |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 41 | { |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame^] | 42 | std::string interface = thresholds::getInterface(threshold.level); |
| 43 | thresholdInterfaces[static_cast<size_t>(threshold.level)] = |
| 44 | objectServer.add_interface( |
| 45 | "/xyz/openbmc_project/sensors/temperature/" + name, interface); |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 46 | } |
| 47 | association = objectServer.add_interface( |
| 48 | "/xyz/openbmc_project/sensors/temperature/" + name, |
| 49 | association::interface); |
| 50 | |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 51 | setInitialProperties(conn, sensor_paths::unitDegreesC); |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | NVMeSensor::~NVMeSensor() |
| 55 | { |
| 56 | // close the input dev to cancel async operations |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame^] | 57 | for (const auto& iface : thresholdInterfaces) |
| 58 | { |
| 59 | objServer.remove_interface(iface); |
| 60 | } |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 61 | objServer.remove_interface(sensorInterface); |
| 62 | objServer.remove_interface(association); |
| 63 | } |
| 64 | |
| 65 | void NVMeSensor::checkThresholds(void) |
| 66 | { |
Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 67 | thresholds::checkThresholds(this); |
| 68 | } |