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