| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |||||
| 3 | #include <exception> | ||||
| 4 | #include <map> | ||||
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 5 | #include <string> |
| 6 | |||||
| Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 7 | namespace ipmiblob |
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 8 | { |
| 9 | |||||
| 10 | class IpmiException : public std::exception | ||||
| 11 | { | ||||
| 12 | public: | ||||
| Patrick Venture | 0ba794d | 2019-03-15 21:07:09 -0700 | [diff] [blame^] | 13 | explicit IpmiException(const std::string& message) : _message(message){}; |
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 14 | |
| Patrick Venture | 0ba794d | 2019-03-15 21:07:09 -0700 | [diff] [blame^] | 15 | static std::string messageFromIpmi(int cc) |
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 16 | { |
| Patrick Venture | 0ba794d | 2019-03-15 21:07:09 -0700 | [diff] [blame^] | 17 | const std::map<int, std::string> commonFailures = { |
| 18 | {0xc0, "busy"}, | ||||
| 19 | {0xc1, "invalid"}, | ||||
| 20 | {0xc3, "timeout"}, | ||||
| 21 | }; | ||||
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 22 | |
| 23 | auto search = commonFailures.find(cc); | ||||
| 24 | if (search != commonFailures.end()) | ||||
| 25 | { | ||||
| Patrick Venture | 0ba794d | 2019-03-15 21:07:09 -0700 | [diff] [blame^] | 26 | return "Received IPMI_CC: " + search->second; |
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 27 | } |
| 28 | else | ||||
| 29 | { | ||||
| Patrick Venture | 0ba794d | 2019-03-15 21:07:09 -0700 | [diff] [blame^] | 30 | return "Received IPMI_CC: " + std::to_string(cc); |
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 31 | } |
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 32 | } |
| Patrick Venture | 0ba794d | 2019-03-15 21:07:09 -0700 | [diff] [blame^] | 33 | |
| 34 | explicit IpmiException(int cc) : IpmiException(messageFromIpmi(cc)) | ||||
| 35 | { | ||||
| 36 | } | ||||
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 37 | |
| 38 | virtual const char* what() const noexcept override | ||||
| 39 | { | ||||
| Patrick Venture | 0ba794d | 2019-03-15 21:07:09 -0700 | [diff] [blame^] | 40 | return _message.c_str(); |
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 41 | } |
| 42 | |||||
| 43 | private: | ||||
| Patrick Venture | 0ba794d | 2019-03-15 21:07:09 -0700 | [diff] [blame^] | 44 | std::string _message; |
| Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 45 | }; |
| 46 | |||||
| Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 47 | } // namespace ipmiblob |