blob: ee126907b650cf700436e2dfddcb76fa25008dd5 [file] [log] [blame]
Shawn McCarney6a957f62024-01-10 16:15:19 -06001/**
2 * Copyright © 2024 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#pragma once
17
18#include "rail.hpp"
19
20#include <nlohmann/json.hpp>
21
Shawn McCarney6a957f62024-01-10 16:15:19 -060022#include <filesystem>
Shawn McCarney906cc3f2024-02-01 13:33:06 -060023#include <memory>
Shawn McCarney6a957f62024-01-10 16:15:19 -060024#include <string>
25#include <vector>
26
27namespace phosphor::power::sequencer::config_file_parser
28{
29
30/**
Shawn McCarneye9144ab2024-05-22 12:34:18 -050031 * Standard JSON configuration file directory on the BMC.
32 */
33extern const std::filesystem::path standardConfigFileDirectory;
34
35/**
36 * Finds the JSON configuration file for the current system based on the
37 * specified compatible system types.
38 *
39 * This is required when a single BMC firmware image supports multiple system
40 * types and some system types require different configuration files.
41 *
42 * The compatible system types must be ordered from most to least specific.
43 * Example:
44 * - com.acme.Hardware.Chassis.Model.MegaServer4CPU
45 * - com.acme.Hardware.Chassis.Model.MegaServer
46 * - com.acme.Hardware.Chassis.Model.Server
47 *
48 * Throws an exception if an error occurs.
49 *
50 * @param compatibleSystemTypes compatible system types for the current system
51 * ordered from most to least specific
52 * @param configFileDir directory containing configuration files
53 * @return path to the JSON configuration file, or an empty path if none was
54 * found
55 */
56std::filesystem::path find(
57 const std::vector<std::string>& compatibleSystemTypes,
58 const std::filesystem::path& configFileDir = standardConfigFileDirectory);
59
60/**
Shawn McCarney6a957f62024-01-10 16:15:19 -060061 * Parses the specified JSON configuration file.
62 *
63 * Returns the corresponding C++ Rail objects.
64 *
65 * Throws a ConfigFileParserError if an error occurs.
66 *
67 * @param pathName configuration file path name
68 * @return vector of Rail objects
69 */
70std::vector<std::unique_ptr<Rail>> parse(const std::filesystem::path& pathName);
71
72/*
73 * Internal implementation details for parse()
74 */
75namespace internal
76{
77
78/**
Shawn McCarney6a957f62024-01-10 16:15:19 -060079 * Parses a JSON element containing a GPIO.
80 *
81 * Returns the corresponding C++ GPIO object.
82 *
83 * Throws an exception if parsing fails.
84 *
85 * @param element JSON element
86 * @return GPIO object
87 */
88GPIO parseGPIO(const nlohmann::json& element);
89
90/**
91 * Parses a JSON element containing a rail.
92 *
93 * Returns the corresponding C++ Rail object.
94 *
95 * Throws an exception if parsing fails.
96 *
97 * @param element JSON element
98 * @return Rail object
99 */
100std::unique_ptr<Rail> parseRail(const nlohmann::json& element);
101
102/**
103 * Parses a JSON element containing an array of rails.
104 *
105 * Returns the corresponding C++ Rail objects.
106 *
107 * Throws an exception if parsing fails.
108 *
109 * @param element JSON element
110 * @return vector of Rail objects
111 */
Patrick Williams92261f82025-02-01 08:22:34 -0500112std::vector<std::unique_ptr<Rail>> parseRailArray(
113 const nlohmann::json& element);
Shawn McCarney6a957f62024-01-10 16:15:19 -0600114
115/**
116 * Parses the JSON root element of the entire configuration file.
117 *
118 * Returns the corresponding C++ Rail objects.
119 *
120 * Throws an exception if parsing fails.
121 *
122 * @param element JSON element
123 * @return vector of Rail objects
124 */
125std::vector<std::unique_ptr<Rail>> parseRoot(const nlohmann::json& element);
126
Shawn McCarney6a957f62024-01-10 16:15:19 -0600127} // namespace internal
128
129} // namespace phosphor::power::sequencer::config_file_parser