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 <sdbusplus/bus.hpp>
19 
20 namespace phosphor::power::regulators
21 {
22 
23 /**
24  * @class ErrorLogging
25  *
26  * Abstract base class that provides an error logging interface.
27  *
28  * The interface is used to create error logs.
29  */
30 class ErrorLogging
31 {
32   public:
33     // Specify which compiler-generated methods we want
34     ErrorLogging() = default;
35     ErrorLogging(const ErrorLogging&) = delete;
36     ErrorLogging(ErrorLogging&&) = delete;
37     ErrorLogging& operator=(const ErrorLogging&) = delete;
38     ErrorLogging& operator=(ErrorLogging&&) = delete;
39     virtual ~ErrorLogging() = default;
40 
41     // TODO: The following are stubs.  Add parameters and doxygen later.
42     virtual void logConfigFileError() = 0;
43     virtual void logDBusError() = 0;
44     virtual void logI2CError() = 0;
45     virtual void logInternalError() = 0;
46     virtual void logPMBusError() = 0;
47     virtual void logWriteVerificationError() = 0;
48 };
49 
50 /**
51  * @class DBusErrorLogging
52  *
53  * Implementation of the ErrorLogging interface using D-Bus method calls.
54  */
55 class DBusErrorLogging : public ErrorLogging
56 {
57   public:
58     // Specify which compiler-generated methods we want
59     DBusErrorLogging() = delete;
60     DBusErrorLogging(const DBusErrorLogging&) = delete;
61     DBusErrorLogging(DBusErrorLogging&&) = delete;
62     DBusErrorLogging& operator=(const DBusErrorLogging&) = delete;
63     DBusErrorLogging& operator=(DBusErrorLogging&&) = delete;
64     virtual ~DBusErrorLogging() = default;
65 
66     /**
67      * Constructor.
68      *
69      * @param bus D-Bus bus object
70      */
71     explicit DBusErrorLogging(sdbusplus::bus::bus& bus) : bus{bus}
72     {
73     }
74 
75     // TODO: The following are stubs.  Add parameters, implementation, and
76     // doxygen later.
77     virtual void logConfigFileError(){};
78     virtual void logDBusError(){};
79     virtual void logI2CError(){};
80     virtual void logInternalError(){};
81     virtual void logPMBusError(){};
82     virtual void logWriteVerificationError(){};
83 
84   private:
85     /**
86      * D-Bus bus object.
87      */
88     sdbusplus::bus::bus& bus;
89 };
90 
91 } // namespace phosphor::power::regulators
92