xref: /openbmc/phosphor-power/phosphor-regulators/src/pmbus_error.hpp (revision f54021972b91be5058b50e9046bb0dd5a3b22a80)
1a5ef5409SShawn McCarney /**
2a5ef5409SShawn McCarney  * Copyright © 2020 IBM Corporation
3a5ef5409SShawn McCarney  *
4a5ef5409SShawn McCarney  * Licensed under the Apache License, Version 2.0 (the "License");
5a5ef5409SShawn McCarney  * you may not use this file except in compliance with the License.
6a5ef5409SShawn McCarney  * You may obtain a copy of the License at
7a5ef5409SShawn McCarney  *
8a5ef5409SShawn McCarney  *     http://www.apache.org/licenses/LICENSE-2.0
9a5ef5409SShawn McCarney  *
10a5ef5409SShawn McCarney  * Unless required by applicable law or agreed to in writing, software
11a5ef5409SShawn McCarney  * distributed under the License is distributed on an "AS IS" BASIS,
12a5ef5409SShawn McCarney  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a5ef5409SShawn McCarney  * See the License for the specific language governing permissions and
14a5ef5409SShawn McCarney  * limitations under the License.
15a5ef5409SShawn McCarney  */
16a5ef5409SShawn McCarney #pragma once
17a5ef5409SShawn McCarney 
18a5ef5409SShawn McCarney #include <exception>
19a5ef5409SShawn McCarney #include <string>
20a5ef5409SShawn McCarney 
21a5ef5409SShawn McCarney namespace phosphor::power::regulators
22a5ef5409SShawn McCarney {
23a5ef5409SShawn McCarney 
24a5ef5409SShawn McCarney /**
25a5ef5409SShawn McCarney  * @class PMBusError
26a5ef5409SShawn McCarney  *
27a5ef5409SShawn McCarney  * An error that occurred while sending PMBus commands or converting data
28a5ef5409SShawn McCarney  * between PMBus formats.
29a5ef5409SShawn McCarney  */
30a5ef5409SShawn McCarney class PMBusError : public std::exception
31a5ef5409SShawn McCarney {
32a5ef5409SShawn McCarney   public:
33a5ef5409SShawn McCarney     // Specify which compiler-generated methods we want
34a5ef5409SShawn McCarney     PMBusError() = delete;
35a5ef5409SShawn McCarney     PMBusError(const PMBusError&) = default;
36a5ef5409SShawn McCarney     PMBusError(PMBusError&&) = default;
37a5ef5409SShawn McCarney     PMBusError& operator=(const PMBusError&) = default;
38a5ef5409SShawn McCarney     PMBusError& operator=(PMBusError&&) = default;
39a5ef5409SShawn McCarney     virtual ~PMBusError() = default;
40a5ef5409SShawn McCarney 
41a5ef5409SShawn McCarney     /**
42a5ef5409SShawn McCarney      * Constructor.
43a5ef5409SShawn McCarney      *
44a5ef5409SShawn McCarney      * @param error error message
455b819f44SShawn McCarney      * @param deviceID unique ID of the device where error occurred
465b819f44SShawn McCarney      * @param inventoryPath inventory path of the device where error occurred
47a5ef5409SShawn McCarney      */
PMBusError(const std::string & error,const std::string & deviceID,const std::string & inventoryPath)485b819f44SShawn McCarney     explicit PMBusError(const std::string& error, const std::string& deviceID,
495b819f44SShawn McCarney                         const std::string& inventoryPath) :
50*f5402197SPatrick Williams         error{"PMBusError: " + error}, deviceID{deviceID},
51*f5402197SPatrick Williams         inventoryPath{inventoryPath}
520c9a33d6SAdriana Kobylak     {}
53a5ef5409SShawn McCarney 
54a5ef5409SShawn McCarney     /**
555b819f44SShawn McCarney      * Returns the unique ID of the device where the error occurred.
565b819f44SShawn McCarney      *
575b819f44SShawn McCarney      * @return device ID
585b819f44SShawn McCarney      */
getDeviceID() const595b819f44SShawn McCarney     const std::string& getDeviceID() const
605b819f44SShawn McCarney     {
615b819f44SShawn McCarney         return deviceID;
625b819f44SShawn McCarney     }
635b819f44SShawn McCarney 
645b819f44SShawn McCarney     /**
655b819f44SShawn McCarney      * Returns the inventory path of the device where the error occurred.
665b819f44SShawn McCarney      *
675b819f44SShawn McCarney      * @return inventory path
685b819f44SShawn McCarney      */
getInventoryPath() const695b819f44SShawn McCarney     const std::string& getInventoryPath() const
705b819f44SShawn McCarney     {
715b819f44SShawn McCarney         return inventoryPath;
725b819f44SShawn McCarney     }
735b819f44SShawn McCarney 
745b819f44SShawn McCarney     /**
75a5ef5409SShawn McCarney      * Returns the description of this error.
76a5ef5409SShawn McCarney      *
77a5ef5409SShawn McCarney      * @return error description
78a5ef5409SShawn McCarney      */
what() const79a5ef5409SShawn McCarney     const char* what() const noexcept override
80a5ef5409SShawn McCarney     {
81a5ef5409SShawn McCarney         return error.c_str();
82a5ef5409SShawn McCarney     }
83a5ef5409SShawn McCarney 
84a5ef5409SShawn McCarney   private:
85a5ef5409SShawn McCarney     /**
86a5ef5409SShawn McCarney      * Error message.
87a5ef5409SShawn McCarney      */
88a5ef5409SShawn McCarney     const std::string error{};
895b819f44SShawn McCarney 
905b819f44SShawn McCarney     /**
915b819f44SShawn McCarney      * Unique ID of the device where the error occurred.
925b819f44SShawn McCarney      */
935b819f44SShawn McCarney     const std::string deviceID{};
945b819f44SShawn McCarney 
955b819f44SShawn McCarney     /**
965b819f44SShawn McCarney      * Inventory path of the device where the error occurred.
975b819f44SShawn McCarney      */
985b819f44SShawn McCarney     const std::string inventoryPath{};
99a5ef5409SShawn McCarney };
100a5ef5409SShawn McCarney 
101a5ef5409SShawn McCarney } // namespace phosphor::power::regulators
102