blob: 229ae9f6f4ace1746235b68a77dc405836ab2d56 [file] [log] [blame]
Shawn McCarney03a25f12021-04-24 17:02:04 -05001/**
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 McCarney03a25f12021-04-24 17:02:04 -050020
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
29namespace phosphor::power::regulators
30{
31
32/**
33 * @class DBusSensors
34 *
35 * Implementation of the Sensors interface using D-Bus.
36 */
37class 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}
55 {
56 }
57
58 /** @copydoc Sensors::enable() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050059 virtual void enable() override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050060
61 /** @copydoc Sensors::endCycle() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050062 virtual void endCycle() override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050063
64 /** @copydoc Sensors::endRail() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050065 virtual void endRail(bool errorOccurred) override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050066
67 /** @copydoc Sensors::disable() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050068 virtual void disable() override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050069
70 /** @copydoc Sensors::setValue() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050071 virtual void setValue(SensorType type, double value) override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050072
73 /** @copydoc Sensors::startCycle() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050074 virtual void startCycle() override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050075
76 /** @copydoc Sensors::startRail() */
77 virtual void startRail(const std::string& rail,
78 const std::string& deviceInventoryPath,
Shawn McCarneyc9c69512021-04-27 18:00:05 -050079 const std::string& chassisInventoryPath) override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050080
81 private:
82 /**
83 * D-Bus bus object.
84 */
85 sdbusplus::bus::bus& bus;
86
87 /**
88 * D-Bus object manager.
89 *
90 * Causes this application to implement the
91 * org.freedesktop.DBus.ObjectManager interface.
92 */
93 sdbusplus::server::manager_t manager;
94
95 /**
96 * Map from sensor names to DBusSensor objects.
97 */
98 std::map<std::string, std::unique_ptr<DBusSensor>> sensors{};
99
100 /**
101 * Time that current monitoring cycle started.
102 */
103 std::chrono::system_clock::time_point cycleStartTime{};
104
105 /**
106 * Current voltage rail.
107 *
108 * This is set by startRail().
109 */
110 std::string rail{};
111
112 /**
113 * Current device inventory path.
114 *
115 * This is set by startRail().
116 */
117 std::string deviceInventoryPath{};
118
119 /**
120 * Current chassis inventory path.
121 *
122 * This is set by startRail().
123 */
124 std::string chassisInventoryPath{};
125};
126
127} // namespace phosphor::power::regulators