Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2021 IBM 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 | #pragma once |
| 17 | |
| 18 | #include "dbus_sensor.hpp" |
| 19 | #include "sensors.hpp" |
Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 20 | |
| 21 | #include <sdbusplus/bus.hpp> |
| 22 | #include <sdbusplus/server/manager.hpp> |
| 23 | |
| 24 | #include <chrono> |
| 25 | #include <map> |
| 26 | #include <memory> |
| 27 | #include <string> |
| 28 | |
| 29 | namespace phosphor::power::regulators |
| 30 | { |
| 31 | |
| 32 | /** |
| 33 | * @class DBusSensors |
| 34 | * |
| 35 | * Implementation of the Sensors interface using D-Bus. |
| 36 | */ |
| 37 | class DBusSensors : public Sensors |
| 38 | { |
| 39 | public: |
| 40 | // Specify which compiler-generated methods we want |
| 41 | DBusSensors() = delete; |
| 42 | DBusSensors(const DBusSensors&) = delete; |
| 43 | DBusSensors(DBusSensors&&) = delete; |
| 44 | DBusSensors& operator=(const DBusSensors&) = delete; |
| 45 | DBusSensors& operator=(DBusSensors&&) = delete; |
| 46 | virtual ~DBusSensors() = default; |
| 47 | |
| 48 | /** |
| 49 | * Constructor. |
| 50 | * |
| 51 | * @param bus D-Bus bus object |
| 52 | */ |
| 53 | explicit DBusSensors(sdbusplus::bus::bus& bus) : |
| 54 | bus{bus}, manager{bus, sensorsObjectPath} |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 55 | {} |
Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 56 | |
| 57 | /** @copydoc Sensors::enable() */ |
Shawn McCarney | c9c6951 | 2021-04-27 18:00:05 -0500 | [diff] [blame] | 58 | virtual void enable() override; |
Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 59 | |
| 60 | /** @copydoc Sensors::endCycle() */ |
Shawn McCarney | c9c6951 | 2021-04-27 18:00:05 -0500 | [diff] [blame] | 61 | virtual void endCycle() override; |
Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 62 | |
| 63 | /** @copydoc Sensors::endRail() */ |
Shawn McCarney | c9c6951 | 2021-04-27 18:00:05 -0500 | [diff] [blame] | 64 | virtual void endRail(bool errorOccurred) override; |
Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 65 | |
| 66 | /** @copydoc Sensors::disable() */ |
Shawn McCarney | c9c6951 | 2021-04-27 18:00:05 -0500 | [diff] [blame] | 67 | virtual void disable() override; |
Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 68 | |
| 69 | /** @copydoc Sensors::setValue() */ |
Shawn McCarney | c9c6951 | 2021-04-27 18:00:05 -0500 | [diff] [blame] | 70 | virtual void setValue(SensorType type, double value) override; |
Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 71 | |
| 72 | /** @copydoc Sensors::startCycle() */ |
Shawn McCarney | c9c6951 | 2021-04-27 18:00:05 -0500 | [diff] [blame] | 73 | virtual void startCycle() override; |
Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 74 | |
| 75 | /** @copydoc Sensors::startRail() */ |
| 76 | virtual void startRail(const std::string& rail, |
| 77 | const std::string& deviceInventoryPath, |
Shawn McCarney | c9c6951 | 2021-04-27 18:00:05 -0500 | [diff] [blame] | 78 | const std::string& chassisInventoryPath) override; |
Shawn McCarney | 03a25f1 | 2021-04-24 17:02:04 -0500 | [diff] [blame] | 79 | |
| 80 | private: |
| 81 | /** |
| 82 | * D-Bus bus object. |
| 83 | */ |
| 84 | sdbusplus::bus::bus& bus; |
| 85 | |
| 86 | /** |
| 87 | * D-Bus object manager. |
| 88 | * |
| 89 | * Causes this application to implement the |
| 90 | * org.freedesktop.DBus.ObjectManager interface. |
| 91 | */ |
| 92 | sdbusplus::server::manager_t manager; |
| 93 | |
| 94 | /** |
| 95 | * Map from sensor names to DBusSensor objects. |
| 96 | */ |
| 97 | std::map<std::string, std::unique_ptr<DBusSensor>> sensors{}; |
| 98 | |
| 99 | /** |
| 100 | * Time that current monitoring cycle started. |
| 101 | */ |
| 102 | std::chrono::system_clock::time_point cycleStartTime{}; |
| 103 | |
| 104 | /** |
| 105 | * Current voltage rail. |
| 106 | * |
| 107 | * This is set by startRail(). |
| 108 | */ |
| 109 | std::string rail{}; |
| 110 | |
| 111 | /** |
| 112 | * Current device inventory path. |
| 113 | * |
| 114 | * This is set by startRail(). |
| 115 | */ |
| 116 | std::string deviceInventoryPath{}; |
| 117 | |
| 118 | /** |
| 119 | * Current chassis inventory path. |
| 120 | * |
| 121 | * This is set by startRail(). |
| 122 | */ |
| 123 | std::string chassisInventoryPath{}; |
| 124 | }; |
| 125 | |
| 126 | } // namespace phosphor::power::regulators |