SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame^] | 1 | #include "reader_impl.hpp" |
| 2 | |
| 3 | #include "utils.hpp" |
| 4 | |
| 5 | #include <com/ibm/VPD/error.hpp> |
| 6 | #include <map> |
| 7 | #include <phosphor-logging/elog-errors.hpp> |
| 8 | #include <xyz/openbmc_project/Common/error.hpp> |
| 9 | |
| 10 | namespace openpower |
| 11 | { |
| 12 | namespace vpd |
| 13 | { |
| 14 | namespace manager |
| 15 | { |
| 16 | namespace reader |
| 17 | { |
| 18 | |
| 19 | using namespace phosphor::logging; |
| 20 | using namespace openpower::vpd::inventory; |
| 21 | using namespace openpower::vpd::constants; |
| 22 | |
| 23 | using InvalidArgument = |
| 24 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 25 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
| 26 | using LocationNotFound = sdbusplus::com::ibm::VPD::Error::LocationNotFound; |
| 27 | |
| 28 | std::string ReaderImpl::getExpandedLocationCode( |
| 29 | const std::string& locationCode, const uint16_t& nodeNumber, |
| 30 | const LocationCodeMap& frusLocationCode) const |
| 31 | { |
| 32 | if ((locationCode.length() < UNEXP_LOCATION_CODE_MIN_LENGTH) || |
| 33 | ((locationCode.find("fcs", 1, 3) == std::string::npos) && |
| 34 | (locationCode.find("mts", 1, 3) == std::string::npos))) |
| 35 | { |
| 36 | // argument is not valid |
| 37 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("LOCATIONCODE"), |
| 38 | Argument::ARGUMENT_VALUE(locationCode.c_str())); |
| 39 | } |
| 40 | |
| 41 | auto iterator = frusLocationCode.find(locationCode); |
| 42 | if (iterator == frusLocationCode.end()) |
| 43 | { |
| 44 | // TODO: Implementation of error logic till then throwing invalid |
| 45 | // argument |
| 46 | // the location code was not found in the system |
| 47 | // elog<LocationNotFound>(); |
| 48 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("LOCATIONCODE"), |
| 49 | Argument::ARGUMENT_VALUE(locationCode.c_str())); |
| 50 | } |
| 51 | |
| 52 | std::string expandedLocationCode = |
| 53 | readBusProperty(iterator->second, LOCATION_CODE_INF, "LocationCode"); |
| 54 | return expandedLocationCode; |
| 55 | } |
| 56 | |
| 57 | } // namespace reader |
| 58 | } // namespace manager |
| 59 | } // namespace vpd |
| 60 | } // namespace openpower |