Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 16 | #include "fru_identity.hpp" |
| 17 | |
| 18 | namespace openpower |
| 19 | { |
| 20 | namespace pels |
| 21 | { |
| 22 | namespace src |
| 23 | { |
| 24 | |
| 25 | FRUIdentity::FRUIdentity(Stream& pel) |
| 26 | { |
| 27 | pel >> _type >> _size >> _flags; |
| 28 | |
| 29 | if (_flags & (pnSupplied | maintProcSupplied)) |
| 30 | { |
| 31 | pel.read(_pnOrProcedureID.data(), _pnOrProcedureID.size()); |
| 32 | } |
| 33 | |
| 34 | if (_flags & ccinSupplied) |
| 35 | { |
| 36 | pel.read(_ccin.data(), _ccin.size()); |
| 37 | } |
| 38 | |
| 39 | if (_flags & snSupplied) |
| 40 | { |
| 41 | pel.read(_sn.data(), _sn.size()); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | std::optional<std::string> FRUIdentity::getPN() const |
| 46 | { |
| 47 | if (hasPN()) |
| 48 | { |
| 49 | // NULL terminated |
| 50 | std::string pn{_pnOrProcedureID.data()}; |
| 51 | return pn; |
| 52 | } |
| 53 | |
| 54 | return std::nullopt; |
| 55 | } |
| 56 | |
| 57 | std::optional<std::string> FRUIdentity::getMaintProc() const |
| 58 | { |
| 59 | if (hasMP()) |
| 60 | { |
| 61 | // NULL terminated |
| 62 | std::string mp{_pnOrProcedureID.data()}; |
| 63 | return mp; |
| 64 | } |
| 65 | |
| 66 | return std::nullopt; |
| 67 | } |
| 68 | |
| 69 | std::optional<std::string> FRUIdentity::getCCIN() const |
| 70 | { |
| 71 | if (hasCCIN()) |
| 72 | { |
| 73 | std::string ccin{_ccin.begin(), _ccin.begin() + _ccin.size()}; |
| 74 | return ccin; |
| 75 | } |
| 76 | |
| 77 | return std::nullopt; |
| 78 | } |
| 79 | |
| 80 | std::optional<std::string> FRUIdentity::getSN() const |
| 81 | { |
| 82 | if (hasSN()) |
| 83 | { |
| 84 | std::string sn{_sn.begin(), _sn.begin() + _sn.size()}; |
| 85 | return sn; |
| 86 | } |
| 87 | |
| 88 | return std::nullopt; |
| 89 | } |
| 90 | |
Matt Spinler | 724d0d8 | 2019-11-06 10:05:36 -0600 | [diff] [blame] | 91 | void FRUIdentity::flatten(Stream& pel) const |
Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 92 | { |
| 93 | pel << _type << _size << _flags; |
| 94 | |
| 95 | if (hasPN() || hasMP()) |
| 96 | { |
| 97 | pel.write(_pnOrProcedureID.data(), _pnOrProcedureID.size()); |
| 98 | } |
| 99 | |
| 100 | if (hasCCIN()) |
| 101 | { |
| 102 | pel.write(_ccin.data(), _ccin.size()); |
| 103 | } |
| 104 | |
| 105 | if (hasSN()) |
| 106 | { |
| 107 | pel.write(_sn.data(), _sn.size()); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | } // namespace src |
| 112 | } // namespace pels |
| 113 | } // namespace openpower |