1 /** 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 18 #include "error_logging.hpp" 19 #include "journal.hpp" 20 #include "presence_service.hpp" 21 22 #include <sdbusplus/bus.hpp> 23 24 namespace phosphor::power::regulators 25 { 26 27 /** 28 * @class Services 29 * 30 * Abstract base class that provides an interface to system services like error 31 * logging and the journal. 32 * 33 * This interface is a container for a set of system services. It can be passed 34 * as a single parameter to the rest of the application. 35 */ 36 class Services 37 { 38 public: 39 // Specify which compiler-generated methods we want 40 Services() = default; 41 Services(const Services&) = delete; 42 Services(Services&&) = delete; 43 Services& operator=(const Services&) = delete; 44 Services& operator=(Services&&) = delete; 45 virtual ~Services() = default; 46 47 /** 48 * Returns the D-Bus bus object. 49 * 50 * @return D-Bus bus 51 */ 52 virtual sdbusplus::bus::bus& getBus() = 0; 53 54 /** 55 * Returns the error logging interface. 56 * 57 * @return error logging interface 58 */ 59 virtual ErrorLogging& getErrorLogging() = 0; 60 61 /** 62 * Returns the journal interface. 63 * 64 * @return journal interface 65 */ 66 virtual Journal& getJournal() = 0; 67 68 /** 69 * Returns the interface to hardware presence data. 70 * 71 * @return hardware presence interface 72 */ 73 virtual PresenceService& getPresenceService() = 0; 74 }; 75 76 /** 77 * @class BMCServices 78 * 79 * Implementation of the Services interface using standard BMC system services. 80 */ 81 class BMCServices : public Services 82 { 83 public: 84 // Specify which compiler-generated methods we want 85 BMCServices() = delete; 86 BMCServices(const BMCServices&) = delete; 87 BMCServices(BMCServices&&) = delete; 88 BMCServices& operator=(const BMCServices&) = delete; 89 BMCServices& operator=(BMCServices&&) = delete; 90 virtual ~BMCServices() = default; 91 92 /** 93 * Constructor. 94 * 95 * @param bus D-Bus bus object 96 */ 97 explicit BMCServices(sdbusplus::bus::bus& bus) : 98 bus{bus}, errorLogging{bus}, presenceService{bus} 99 { 100 } 101 102 /** @copydoc Services::getBus() */ 103 virtual sdbusplus::bus::bus& getBus() override 104 { 105 return bus; 106 } 107 108 /** @copydoc Services::getErrorLogging() */ 109 virtual ErrorLogging& getErrorLogging() override 110 { 111 return errorLogging; 112 } 113 114 /** @copydoc Services::getJournal() */ 115 virtual Journal& getJournal() override 116 { 117 return journal; 118 } 119 120 /** @copydoc Services::getPresenceService() */ 121 virtual PresenceService& getPresenceService() override 122 { 123 return presenceService; 124 } 125 126 private: 127 /** 128 * D-Bus bus object. 129 */ 130 sdbusplus::bus::bus& bus; 131 132 /** 133 * Implementation of the ErrorLogging interface using D-Bus method calls. 134 */ 135 DBusErrorLogging errorLogging; 136 137 /** 138 * Implementation of the Journal interface that writes to the systemd 139 * journal. 140 */ 141 SystemdJournal journal{}; 142 143 /** 144 * Implementation of the PresenceService interface using D-Bus method calls. 145 */ 146 DBusPresenceService presenceService; 147 }; 148 149 } // namespace phosphor::power::regulators 150