1a2056e9cSWilly Tu // Copyright 2021 Google LLC 2a2056e9cSWilly Tu // 3a2056e9cSWilly Tu // Licensed under the Apache License, Version 2.0 (the "License"); 4a2056e9cSWilly Tu // you may not use this file except in compliance with the License. 5a2056e9cSWilly Tu // You may obtain a copy of the License at 6a2056e9cSWilly Tu // 7a2056e9cSWilly Tu // http://www.apache.org/licenses/LICENSE-2.0 8a2056e9cSWilly Tu // 9a2056e9cSWilly Tu // Unless required by applicable law or agreed to in writing, software 10a2056e9cSWilly Tu // distributed under the License is distributed on an "AS IS" BASIS, 11a2056e9cSWilly Tu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a2056e9cSWilly Tu // See the License for the specific language governing permissions and 13a2056e9cSWilly Tu // limitations under the License. 14a2056e9cSWilly Tu 15d2037c6aSPatrick Venture #pragma once 16d2037c6aSPatrick Venture 17d2037c6aSPatrick Venture #include <exception> 18d2037c6aSPatrick Venture #include <string> 19d2037c6aSPatrick Venture 20d2037c6aSPatrick Venture namespace google 21d2037c6aSPatrick Venture { 22d2037c6aSPatrick Venture namespace ipmi 23d2037c6aSPatrick Venture { 24d2037c6aSPatrick Venture 25d2037c6aSPatrick Venture /** 26d2037c6aSPatrick Venture * This can be used by the Handler object to throw an exception and suggest an 27d2037c6aSPatrick Venture * IPMI return code to use for the error. 28d2037c6aSPatrick Venture */ 29d2037c6aSPatrick Venture class IpmiException : public std::exception 30d2037c6aSPatrick Venture { 31d2037c6aSPatrick Venture public: IpmiException(int ipmicc)32d2037c6aSPatrick Venture explicit IpmiException(int ipmicc) : 33d2037c6aSPatrick Venture _message("IPMI Code Received: " + std::to_string(ipmicc)), 34d2037c6aSPatrick Venture _ipmicc(ipmicc) 35*444b5ea4SPatrick Williams {} 36d2037c6aSPatrick Venture what() const37d2037c6aSPatrick Venture virtual const char* what() const noexcept override 38d2037c6aSPatrick Venture { 39d2037c6aSPatrick Venture return _message.c_str(); 40d2037c6aSPatrick Venture } 41d2037c6aSPatrick Venture getIpmiError() const42d2037c6aSPatrick Venture int getIpmiError() const 43d2037c6aSPatrick Venture { 44d2037c6aSPatrick Venture return _ipmicc; 45d2037c6aSPatrick Venture } 46d2037c6aSPatrick Venture 47d2037c6aSPatrick Venture private: 48d2037c6aSPatrick Venture std::string _message; 49d2037c6aSPatrick Venture int _ipmicc; 50d2037c6aSPatrick Venture }; 51d2037c6aSPatrick Venture 52d2037c6aSPatrick Venture } // namespace ipmi 53d2037c6aSPatrick Venture } // namespace google 54