Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 1 | #include "user_header.hpp" |
| 2 | |
| 3 | #include <phosphor-logging/log.hpp> |
| 4 | |
| 5 | namespace openpower |
| 6 | { |
| 7 | namespace pels |
| 8 | { |
| 9 | |
| 10 | using namespace phosphor::logging; |
| 11 | |
| 12 | Stream& operator>>(Stream& s, UserHeader& uh) |
| 13 | { |
| 14 | s >> uh._header >> uh._eventSubsystem >> uh._eventScope >> |
| 15 | uh._eventSeverity >> uh._eventType >> uh._reserved4Byte1 >> |
| 16 | uh._problemDomain >> uh._problemVector >> uh._actionFlags >> |
| 17 | uh._reserved4Byte2; |
| 18 | return s; |
| 19 | } |
| 20 | |
| 21 | Stream& operator<<(Stream& s, UserHeader& uh) |
| 22 | { |
| 23 | s << uh._header << uh._eventSubsystem << uh._eventScope << uh._eventSeverity |
| 24 | << uh._eventType << uh._reserved4Byte1 << uh._problemDomain |
| 25 | << uh._problemVector << uh._actionFlags << uh._reserved4Byte2; |
| 26 | return s; |
| 27 | } |
| 28 | |
| 29 | UserHeader::UserHeader(Stream& pel) |
| 30 | { |
| 31 | try |
| 32 | { |
| 33 | pel >> *this; |
| 34 | validate(); |
| 35 | } |
| 36 | catch (const std::exception& e) |
| 37 | { |
| 38 | log<level::ERR>("Cannot unflatten user header", |
| 39 | entry("ERROR=%s", e.what())); |
| 40 | _valid = false; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void UserHeader::validate() |
| 45 | { |
| 46 | bool failed = false; |
| 47 | if (header().id != userHeaderSectionID) |
| 48 | { |
| 49 | log<level::ERR>("Invalid user header section ID", |
| 50 | entry("ID=0x%X", header().id)); |
| 51 | failed = true; |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if (header().version != userHeaderVersion) |
| 56 | { |
| 57 | log<level::ERR>("Invalid user header version", |
| 58 | entry("VERSION=0x%X", header().version)); |
| 59 | failed = true; |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | _valid = (failed) ? false : true; |
| 64 | } |
| 65 | |
| 66 | } // namespace pels |
| 67 | } // namespace openpower |