blob: bd92ce5073d5487386cd0b70c80ad121d2da373d [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 WriteVerificationError
26 *
27 * An error that occurred when performing a read after a write to ensure the
28 * write was successful.
29 *
30 * This exception is thrown when the value read is different than the value
31 * written. This is also known as a readback error.
32 */
33class WriteVerificationError : public std::exception
34{
35 public:
36 // Specify which compiler-generated methods we want
37 WriteVerificationError() = delete;
38 WriteVerificationError(const WriteVerificationError&) = default;
39 WriteVerificationError(WriteVerificationError&&) = default;
40 WriteVerificationError& operator=(const WriteVerificationError&) = default;
41 WriteVerificationError& operator=(WriteVerificationError&&) = default;
42 virtual ~WriteVerificationError() = default;
43
44 /**
45 * Constructor.
46 *
47 * @param error error message
Shawn McCarney36fc2612021-03-16 15:44:26 -050048 * @param deviceID unique ID of the device where error occurred
49 * @param inventoryPath inventory path of the device where error occurred
Shawn McCarneya5ef5402020-03-01 16:29:44 -060050 */
Shawn McCarney36fc2612021-03-16 15:44:26 -050051 explicit WriteVerificationError(const std::string& error,
52 const std::string& deviceID,
53 const std::string& inventoryPath) :
54 error{"WriteVerificationError: " + error},
55 deviceID{deviceID}, inventoryPath{inventoryPath}
Shawn McCarneya5ef5402020-03-01 16:29:44 -060056 {
57 }
58
59 /**
Shawn McCarney36fc2612021-03-16 15:44:26 -050060 * Returns the unique ID of the device where the error occurred.
61 *
62 * @return device ID
63 */
64 const std::string& getDeviceID() const
65 {
66 return deviceID;
67 }
68
69 /**
70 * Returns the inventory path of the device where the error occurred.
71 *
72 * @return inventory path
73 */
74 const std::string& getInventoryPath() const
75 {
76 return inventoryPath;
77 }
78
79 /**
Shawn McCarneya5ef5402020-03-01 16:29:44 -060080 * Returns the description of this error.
81 *
82 * @return error description
83 */
84 const char* what() const noexcept override
85 {
86 return error.c_str();
87 }
88
89 private:
90 /**
91 * Error message.
92 */
93 const std::string error{};
Shawn McCarney36fc2612021-03-16 15:44:26 -050094
95 /**
96 * Unique ID of the device where the error occurred.
97 */
98 const std::string deviceID{};
99
100 /**
101 * Inventory path of the device where the error occurred.
102 */
103 const std::string inventoryPath{};
Shawn McCarneya5ef5402020-03-01 16:29:44 -0600104};
105
106} // namespace phosphor::power::regulators