blob: 07e3d5f65bd9b8de5bcbbde7b10fd6079b07440b [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}
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +0000117 {}
Shawn McCarney81095022020-07-16 14:22:26 -0500118
119 /** @copydoc Services::getBus() */
120 virtual sdbusplus::bus::bus& getBus() override
121 {
122 return bus;
123 }
124
125 /** @copydoc Services::getErrorLogging() */
126 virtual ErrorLogging& getErrorLogging() override
127 {
128 return errorLogging;
129 }
130
131 /** @copydoc Services::getJournal() */
132 virtual Journal& getJournal() override
133 {
134 return journal;
135 }
136
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600137 /** @copydoc Services::getPresenceService() */
138 virtual PresenceService& getPresenceService() override
139 {
140 return presenceService;
141 }
142
Shawn McCarney8279a112021-04-27 16:51:30 -0500143 /** @copydoc Services::getSensors() */
144 virtual Sensors& getSensors() override
145 {
146 return sensors;
147 }
148
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600149 /** @copydoc Services::getVPD() */
150 virtual VPD& getVPD() override
151 {
152 return vpd;
153 }
154
Shawn McCarney81095022020-07-16 14:22:26 -0500155 private:
156 /**
157 * D-Bus bus object.
158 */
159 sdbusplus::bus::bus& bus;
160
161 /**
162 * Implementation of the ErrorLogging interface using D-Bus method calls.
163 */
164 DBusErrorLogging errorLogging;
165
166 /**
167 * Implementation of the Journal interface that writes to the systemd
168 * journal.
169 */
170 SystemdJournal journal{};
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600171
172 /**
173 * Implementation of the PresenceService interface using D-Bus method calls.
174 */
175 DBusPresenceService presenceService;
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600176
177 /**
Shawn McCarney8279a112021-04-27 16:51:30 -0500178 * Implementation of the Sensors interface using D-Bus.
179 */
180 DBusSensors sensors;
181
182 /**
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600183 * Implementation of the VPD interface using D-Bus method calls.
184 */
185 DBusVPD vpd;
Shawn McCarney81095022020-07-16 14:22:26 -0500186};
187
188} // namespace phosphor::power::regulators