103a25f1bSShawn McCarney /** 203a25f1bSShawn McCarney * Copyright © 2021 IBM Corporation 303a25f1bSShawn McCarney * 403a25f1bSShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License"); 503a25f1bSShawn McCarney * you may not use this file except in compliance with the License. 603a25f1bSShawn McCarney * You may obtain a copy of the License at 703a25f1bSShawn McCarney * 803a25f1bSShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0 903a25f1bSShawn McCarney * 1003a25f1bSShawn McCarney * Unless required by applicable law or agreed to in writing, software 1103a25f1bSShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS, 1203a25f1bSShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1303a25f1bSShawn McCarney * See the License for the specific language governing permissions and 1403a25f1bSShawn McCarney * limitations under the License. 1503a25f1bSShawn McCarney */ 1603a25f1bSShawn McCarney #pragma once 1703a25f1bSShawn McCarney 1803a25f1bSShawn McCarney #include "dbus_sensor.hpp" 1903a25f1bSShawn McCarney #include "sensors.hpp" 2003a25f1bSShawn McCarney 2103a25f1bSShawn McCarney #include <sdbusplus/bus.hpp> 2203a25f1bSShawn McCarney #include <sdbusplus/server/manager.hpp> 2303a25f1bSShawn McCarney 2403a25f1bSShawn McCarney #include <chrono> 2503a25f1bSShawn McCarney #include <map> 2603a25f1bSShawn McCarney #include <memory> 2703a25f1bSShawn McCarney #include <string> 2803a25f1bSShawn McCarney 2903a25f1bSShawn McCarney namespace phosphor::power::regulators 3003a25f1bSShawn McCarney { 3103a25f1bSShawn McCarney 3203a25f1bSShawn McCarney /** 3303a25f1bSShawn McCarney * @class DBusSensors 3403a25f1bSShawn McCarney * 3503a25f1bSShawn McCarney * Implementation of the Sensors interface using D-Bus. 3603a25f1bSShawn McCarney */ 3703a25f1bSShawn McCarney class DBusSensors : public Sensors 3803a25f1bSShawn McCarney { 3903a25f1bSShawn McCarney public: 4003a25f1bSShawn McCarney // Specify which compiler-generated methods we want 4103a25f1bSShawn McCarney DBusSensors() = delete; 4203a25f1bSShawn McCarney DBusSensors(const DBusSensors&) = delete; 4303a25f1bSShawn McCarney DBusSensors(DBusSensors&&) = delete; 4403a25f1bSShawn McCarney DBusSensors& operator=(const DBusSensors&) = delete; 4503a25f1bSShawn McCarney DBusSensors& operator=(DBusSensors&&) = delete; 4603a25f1bSShawn McCarney virtual ~DBusSensors() = default; 4703a25f1bSShawn McCarney 4803a25f1bSShawn McCarney /** 4903a25f1bSShawn McCarney * Constructor. 5003a25f1bSShawn McCarney * 5103a25f1bSShawn McCarney * @param bus D-Bus bus object 5203a25f1bSShawn McCarney */ DBusSensors(sdbusplus::bus_t & bus)53*7354ce62SPatrick Williams explicit DBusSensors(sdbusplus::bus_t& bus) : 5403a25f1bSShawn McCarney bus{bus}, manager{bus, sensorsObjectPath} 550c9a33d6SAdriana Kobylak {} 5603a25f1bSShawn McCarney 5703a25f1bSShawn McCarney /** @copydoc Sensors::enable() */ 58c9c69518SShawn McCarney virtual void enable() override; 5903a25f1bSShawn McCarney 6003a25f1bSShawn McCarney /** @copydoc Sensors::endCycle() */ 61c9c69518SShawn McCarney virtual void endCycle() override; 6203a25f1bSShawn McCarney 6303a25f1bSShawn McCarney /** @copydoc Sensors::endRail() */ 64c9c69518SShawn McCarney virtual void endRail(bool errorOccurred) override; 6503a25f1bSShawn McCarney 6603a25f1bSShawn McCarney /** @copydoc Sensors::disable() */ 67c9c69518SShawn McCarney virtual void disable() override; 6803a25f1bSShawn McCarney 6903a25f1bSShawn McCarney /** @copydoc Sensors::setValue() */ 70c9c69518SShawn McCarney virtual void setValue(SensorType type, double value) override; 7103a25f1bSShawn McCarney 7203a25f1bSShawn McCarney /** @copydoc Sensors::startCycle() */ 73c9c69518SShawn McCarney virtual void startCycle() override; 7403a25f1bSShawn McCarney 7503a25f1bSShawn McCarney /** @copydoc Sensors::startRail() */ 7603a25f1bSShawn McCarney virtual void startRail(const std::string& rail, 7703a25f1bSShawn McCarney const std::string& deviceInventoryPath, 78c9c69518SShawn McCarney const std::string& chassisInventoryPath) override; 7903a25f1bSShawn McCarney 8003a25f1bSShawn McCarney private: 8103a25f1bSShawn McCarney /** 8203a25f1bSShawn McCarney * D-Bus bus object. 8303a25f1bSShawn McCarney */ 84*7354ce62SPatrick Williams sdbusplus::bus_t& bus; 8503a25f1bSShawn McCarney 8603a25f1bSShawn McCarney /** 8703a25f1bSShawn McCarney * D-Bus object manager. 8803a25f1bSShawn McCarney * 8903a25f1bSShawn McCarney * Causes this application to implement the 9003a25f1bSShawn McCarney * org.freedesktop.DBus.ObjectManager interface. 9103a25f1bSShawn McCarney */ 9203a25f1bSShawn McCarney sdbusplus::server::manager_t manager; 9303a25f1bSShawn McCarney 9403a25f1bSShawn McCarney /** 9503a25f1bSShawn McCarney * Map from sensor names to DBusSensor objects. 9603a25f1bSShawn McCarney */ 9703a25f1bSShawn McCarney std::map<std::string, std::unique_ptr<DBusSensor>> sensors{}; 9803a25f1bSShawn McCarney 9903a25f1bSShawn McCarney /** 10003a25f1bSShawn McCarney * Time that current monitoring cycle started. 10103a25f1bSShawn McCarney */ 10203a25f1bSShawn McCarney std::chrono::system_clock::time_point cycleStartTime{}; 10303a25f1bSShawn McCarney 10403a25f1bSShawn McCarney /** 10503a25f1bSShawn McCarney * Current voltage rail. 10603a25f1bSShawn McCarney * 10703a25f1bSShawn McCarney * This is set by startRail(). 10803a25f1bSShawn McCarney */ 10903a25f1bSShawn McCarney std::string rail{}; 11003a25f1bSShawn McCarney 11103a25f1bSShawn McCarney /** 11203a25f1bSShawn McCarney * Current device inventory path. 11303a25f1bSShawn McCarney * 11403a25f1bSShawn McCarney * This is set by startRail(). 11503a25f1bSShawn McCarney */ 11603a25f1bSShawn McCarney std::string deviceInventoryPath{}; 11703a25f1bSShawn McCarney 11803a25f1bSShawn McCarney /** 11903a25f1bSShawn McCarney * Current chassis inventory path. 12003a25f1bSShawn McCarney * 12103a25f1bSShawn McCarney * This is set by startRail(). 12203a25f1bSShawn McCarney */ 12303a25f1bSShawn McCarney std::string chassisInventoryPath{}; 12403a25f1bSShawn McCarney }; 12503a25f1bSShawn McCarney 12603a25f1bSShawn McCarney } // namespace phosphor::power::regulators 127