blob: 5f5454e700a0a43f3577118c20ddb3ab0ed73d53 [file] [log] [blame]
Shawn McCarney4e0402c2021-02-05 00:08:33 -06001/**
2 * Copyright © 2021 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 */
16
17#include "vpd.hpp"
18
19#include "types.hpp"
20#include "utility.hpp"
21
22namespace phosphor::power::regulators
23{
24
Matt Spinleraacc2aa2021-05-25 09:31:35 -060025std::vector<uint8_t> DBusVPD::getValue(const std::string& inventoryPath,
26 const std::string& keyword)
Shawn McCarney4e0402c2021-02-05 00:08:33 -060027{
Matt Spinleraacc2aa2021-05-25 09:31:35 -060028 std::vector<uint8_t> value{};
Shawn McCarney4e0402c2021-02-05 00:08:33 -060029
30 // Get cached keywords for the inventory path
31 KeywordMap& cachedKeywords = cache[inventoryPath];
32
33 // Check if the keyword value is already cached
34 auto it = cachedKeywords.find(keyword);
35 if (it != cachedKeywords.end())
36 {
37 value = it->second;
38 }
39 else
40 {
Matt Spinleraacc2aa2021-05-25 09:31:35 -060041 if (keyword == "HW")
42 {
43 // HW is a vector<uint8_t>, the others are a string.
44 util::getProperty("com.ibm.ipzvpd.VINI", "HW", inventoryPath,
45 INVENTORY_MGR_IFACE, bus, value);
46 }
47 else
48 {
49 // Get keyword value from D-Bus interface/property. The property
50 // name is normally the same as the VPD keyword name. However, the
51 // CCIN keyword is stored in the Model property.
52 std::string property{(keyword == "CCIN") ? "Model" : keyword};
53 std::string stringValue;
54 util::getProperty(ASSET_IFACE, property, inventoryPath,
55 INVENTORY_MGR_IFACE, bus, stringValue);
56
57 if (!stringValue.empty())
58 {
59 value.insert(value.begin(), stringValue.begin(),
60 stringValue.end());
61 }
62 }
Shawn McCarney4e0402c2021-02-05 00:08:33 -060063
64 // Cache keyword value
65 cachedKeywords[keyword] = value;
66 }
67
68 return value;
69}
70
71} // namespace phosphor::power::regulators