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