blob: ac2a0a562291687ca3064db33d56529ab15c5460 [file] [log] [blame]
Shawn McCarneya5ef5402020-03-01 16:29:44 -06001/**
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 <exception>
19#include <string>
20
21namespace phosphor::power::regulators
22{
23
24/**
25 * @class PMBusError
26 *
27 * An error that occurred while sending PMBus commands or converting data
28 * between PMBus formats.
29 */
30class PMBusError : public std::exception
31{
32 public:
33 // Specify which compiler-generated methods we want
34 PMBusError() = delete;
35 PMBusError(const PMBusError&) = default;
36 PMBusError(PMBusError&&) = default;
37 PMBusError& operator=(const PMBusError&) = default;
38 PMBusError& operator=(PMBusError&&) = default;
39 virtual ~PMBusError() = default;
40
41 /**
42 * Constructor.
43 *
44 * @param error error message
Shawn McCarney5b819f42021-03-16 14:41:15 -050045 * @param deviceID unique ID of the device where error occurred
46 * @param inventoryPath inventory path of the device where error occurred
Shawn McCarneya5ef5402020-03-01 16:29:44 -060047 */
Shawn McCarney5b819f42021-03-16 14:41:15 -050048 explicit PMBusError(const std::string& error, const std::string& deviceID,
49 const std::string& inventoryPath) :
50 error{"PMBusError: " + error},
51 deviceID{deviceID}, inventoryPath{inventoryPath}
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000052 {}
Shawn McCarneya5ef5402020-03-01 16:29:44 -060053
54 /**
Shawn McCarney5b819f42021-03-16 14:41:15 -050055 * Returns the unique ID of the device where the error occurred.
56 *
57 * @return device ID
58 */
59 const std::string& getDeviceID() const
60 {
61 return deviceID;
62 }
63
64 /**
65 * Returns the inventory path of the device where the error occurred.
66 *
67 * @return inventory path
68 */
69 const std::string& getInventoryPath() const
70 {
71 return inventoryPath;
72 }
73
74 /**
Shawn McCarneya5ef5402020-03-01 16:29:44 -060075 * Returns the description of this error.
76 *
77 * @return error description
78 */
79 const char* what() const noexcept override
80 {
81 return error.c_str();
82 }
83
84 private:
85 /**
86 * Error message.
87 */
88 const std::string error{};
Shawn McCarney5b819f42021-03-16 14:41:15 -050089
90 /**
91 * Unique ID of the device where the error occurred.
92 */
93 const std::string deviceID{};
94
95 /**
96 * Inventory path of the device where the error occurred.
97 */
98 const std::string inventoryPath{};
Shawn McCarneya5ef5402020-03-01 16:29:44 -060099};
100
101} // namespace phosphor::power::regulators