xref: /openbmc/google-ipmi-sys/util.hpp (revision 444b5ea4)
1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <nlohmann/json.hpp>
18 
19 #include <cstdint>
20 #include <string>
21 #include <tuple>
22 #include <vector>
23 
24 namespace google
25 {
26 namespace ipmi
27 {
28 
29 /**
30  * Parse a file and return the json object.
31  *
32  * @param[in] file - the path to the file to parse.
33  * @return the json object if valid.
34  * @throw elog<InternalFailure> on failures.
35  */
36 nlohmann::json parseConfig(const std::string& file);
37 
38 /**
39  * Read a dts property file and return the contents.
40  *
41  * @param[in] file - the path to the file to parse.
42  * @return the property value or an empty string on failure.
43  */
44 std::string readPropertyFile(const std::string& fileName);
45 
46 /**
47  * Build a map of the i2c bus numbers to their PCIe slot names.
48  *
49  * @return list of pairs of i2c bus with their corresponding slot names.
50  */
51 std::vector<std::tuple<std::uint32_t, std::string>> buildPcieMap();
52 
53 } // namespace ipmi
54 } // namespace google
55