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