blob: 7a4d6ca6dc1b07c31c1f3deb43f1436760e4f2d7 [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 */
Patrick Williams7354ce62022-07-22 19:26:56 -050053 explicit DBusSensors(sdbusplus::bus_t& bus) :
Shawn McCarney03a25f12021-04-24 17:02:04 -050054 bus{bus}, manager{bus, sensorsObjectPath}
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000055 {}
Shawn McCarney03a25f12021-04-24 17:02:04 -050056
57 /** @copydoc Sensors::enable() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050058 virtual void enable() override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050059
60 /** @copydoc Sensors::endCycle() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050061 virtual void endCycle() override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050062
63 /** @copydoc Sensors::endRail() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050064 virtual void endRail(bool errorOccurred) override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050065
66 /** @copydoc Sensors::disable() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050067 virtual void disable() override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050068
69 /** @copydoc Sensors::setValue() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050070 virtual void setValue(SensorType type, double value) override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050071
72 /** @copydoc Sensors::startCycle() */
Shawn McCarneyc9c69512021-04-27 18:00:05 -050073 virtual void startCycle() override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050074
75 /** @copydoc Sensors::startRail() */
76 virtual void startRail(const std::string& rail,
77 const std::string& deviceInventoryPath,
Shawn McCarneyc9c69512021-04-27 18:00:05 -050078 const std::string& chassisInventoryPath) override;
Shawn McCarney03a25f12021-04-24 17:02:04 -050079
80 private:
81 /**
82 * D-Bus bus object.
83 */
Patrick Williams7354ce62022-07-22 19:26:56 -050084 sdbusplus::bus_t& bus;
Shawn McCarney03a25f12021-04-24 17:02:04 -050085
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