blob: 21660d9e6ddf67f69ce9ca6ff5c2f88bd383a200 [file] [log] [blame]
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -05001#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
10namespace openpower
11{
12namespace vpd
13{
14namespace manager
15{
16namespace reader
17{
18
19using namespace phosphor::logging;
20using namespace openpower::vpd::inventory;
21using namespace openpower::vpd::constants;
22
23using InvalidArgument =
24 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
25using Argument = xyz::openbmc_project::Common::InvalidArgument;
26using LocationNotFound = sdbusplus::com::ibm::VPD::Error::LocationNotFound;
27
28std::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