blob: 42701c3f06754806358fac5cf711925bc9a0bcae [file] [log] [blame]
Shawn McCarney81095022020-07-16 14:22:26 -05001/**
2 * Copyright © 2020 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
Shawn McCarney8279a112021-04-27 16:51:30 -050018#include "dbus_sensors.hpp"
Shawn McCarney81095022020-07-16 14:22:26 -050019#include "error_logging.hpp"
20#include "journal.hpp"
Shawn McCarneyd58858c2020-11-04 18:28:01 -060021#include "presence_service.hpp"
Shawn McCarney8279a112021-04-27 16:51:30 -050022#include "sensors.hpp"
Shawn McCarney4e0402c2021-02-05 00:08:33 -060023#include "vpd.hpp"
Shawn McCarney81095022020-07-16 14:22:26 -050024
25#include <sdbusplus/bus.hpp>
26
27namespace phosphor::power::regulators
28{
29
30/**
31 * @class Services
32 *
33 * Abstract base class that provides an interface to system services like error
34 * logging and the journal.
35 *
36 * This interface is a container for a set of system services. It can be passed
37 * as a single parameter to the rest of the application.
38 */
39class Services
40{
41 public:
42 // Specify which compiler-generated methods we want
43 Services() = default;
44 Services(const Services&) = delete;
45 Services(Services&&) = delete;
46 Services& operator=(const Services&) = delete;
47 Services& operator=(Services&&) = delete;
48 virtual ~Services() = default;
49
50 /**
51 * Returns the D-Bus bus object.
52 *
53 * @return D-Bus bus
54 */
55 virtual sdbusplus::bus::bus& getBus() = 0;
56
57 /**
58 * Returns the error logging interface.
59 *
60 * @return error logging interface
61 */
62 virtual ErrorLogging& getErrorLogging() = 0;
63
64 /**
65 * Returns the journal interface.
66 *
67 * @return journal interface
68 */
69 virtual Journal& getJournal() = 0;
Shawn McCarneyd58858c2020-11-04 18:28:01 -060070
71 /**
72 * Returns the interface to hardware presence data.
73 *
74 * @return hardware presence interface
75 */
76 virtual PresenceService& getPresenceService() = 0;
Shawn McCarney4e0402c2021-02-05 00:08:33 -060077
78 /**
Shawn McCarney8279a112021-04-27 16:51:30 -050079 * Returns the sensors interface.
80 *
81 * @return sensors interface
82 */
83 virtual Sensors& getSensors() = 0;
84
85 /**
Shawn McCarney4e0402c2021-02-05 00:08:33 -060086 * Returns the interface to hardware VPD (Vital Product Data).
87 *
88 * @return hardware VPD interface
89 */
90 virtual VPD& getVPD() = 0;
Shawn McCarney81095022020-07-16 14:22:26 -050091};
92
93/**
94 * @class BMCServices
95 *
96 * Implementation of the Services interface using standard BMC system services.
97 */
98class BMCServices : public Services
99{
100 public:
101 // Specify which compiler-generated methods we want
102 BMCServices() = delete;
103 BMCServices(const BMCServices&) = delete;
104 BMCServices(BMCServices&&) = delete;
105 BMCServices& operator=(const BMCServices&) = delete;
106 BMCServices& operator=(BMCServices&&) = delete;
107 virtual ~BMCServices() = default;
108
109 /**
110 * Constructor.
111 *
112 * @param bus D-Bus bus object
113 */
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600114 explicit BMCServices(sdbusplus::bus::bus& bus) :
Shawn McCarney8279a112021-04-27 16:51:30 -0500115 bus{bus}, errorLogging{bus},
116 presenceService{bus}, sensors{bus}, vpd{bus}
Shawn McCarney81095022020-07-16 14:22:26 -0500117 {
118 }
119
120 /** @copydoc Services::getBus() */
121 virtual sdbusplus::bus::bus& getBus() override
122 {
123 return bus;
124 }
125
126 /** @copydoc Services::getErrorLogging() */
127 virtual ErrorLogging& getErrorLogging() override
128 {
129 return errorLogging;
130 }
131
132 /** @copydoc Services::getJournal() */
133 virtual Journal& getJournal() override
134 {
135 return journal;
136 }
137
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600138 /** @copydoc Services::getPresenceService() */
139 virtual PresenceService& getPresenceService() override
140 {
141 return presenceService;
142 }
143
Shawn McCarney8279a112021-04-27 16:51:30 -0500144 /** @copydoc Services::getSensors() */
145 virtual Sensors& getSensors() override
146 {
147 return sensors;
148 }
149
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600150 /** @copydoc Services::getVPD() */
151 virtual VPD& getVPD() override
152 {
153 return vpd;
154 }
155
Shawn McCarney81095022020-07-16 14:22:26 -0500156 private:
157 /**
158 * D-Bus bus object.
159 */
160 sdbusplus::bus::bus& bus;
161
162 /**
163 * Implementation of the ErrorLogging interface using D-Bus method calls.
164 */
165 DBusErrorLogging errorLogging;
166
167 /**
168 * Implementation of the Journal interface that writes to the systemd
169 * journal.
170 */
171 SystemdJournal journal{};
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600172
173 /**
174 * Implementation of the PresenceService interface using D-Bus method calls.
175 */
176 DBusPresenceService presenceService;
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600177
178 /**
Shawn McCarney8279a112021-04-27 16:51:30 -0500179 * Implementation of the Sensors interface using D-Bus.
180 */
181 DBusSensors sensors;
182
183 /**
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600184 * Implementation of the VPD interface using D-Bus method calls.
185 */
186 DBusVPD vpd;
Shawn McCarney81095022020-07-16 14:22:26 -0500187};
188
189} // namespace phosphor::power::regulators