blob: 02bfe0b299df0dd6dad393574e98511d4bd6d807 [file] [log] [blame]
Patrick Venture123b5c02019-03-05 14:01:00 -08001#pragma once
2
3#include <exception>
4#include <map>
5#include <sstream>
6#include <string>
7
Patrick Venture1470bec2019-03-06 07:33:12 -08008namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -08009{
10
11class 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 Venture1470bec2019-03-06 07:33:12 -080047} // namespace ipmiblob