blob: 2d4a48975c92b490335a00c6ff1143b56b201bb4 [file] [log] [blame]
Matthew Barthdfd4a052020-09-02 16:31:51 -05001/**
2 * Copyright © 2020 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 "config_base.hpp"
19
20#include <nlohmann/json.hpp>
Matthew Barthdfd4a052020-09-02 16:31:51 -050021
Matt Spinlerc2c2db72022-04-07 13:59:37 -050022#include <set>
23
Matthew Barthdfd4a052020-09-02 16:31:51 -050024namespace phosphor::fan::control::json
25{
26
27using json = nlohmann::json;
28
29/**
30 * @class Group - Represents a group of dbus objects for configured events
31 *
32 * A group contains a list of dbus objects that are logically grouped together
33 * to be used within one-or-more configured fan control events. An event object
34 * is configured to apply a set of actions against a list of groups that could
Matthew Barthe47c9582021-03-09 14:24:02 -060035 * result in a fan control target change. A group may also be configured against
Matthew Barthdfd4a052020-09-02 16:31:51 -050036 * a list of profiles(OPTIONAL) and or denote a specific service(OPTIONAL) that
37 * serves the list of dbus objects in the group.
38 *
39 * (When no profile for a group is given, the group defaults to always be used
40 * within the events its included in)
41 *
42 */
43class Group : public ConfigBase
44{
45 public:
46 /* JSON file name for groups */
47 static constexpr auto confFileName = "groups.json";
48
49 Group() = delete;
Matthew Barthdfd4a052020-09-02 16:31:51 -050050 Group(Group&&) = delete;
51 Group& operator=(const Group&) = delete;
52 Group& operator=(Group&&) = delete;
53 ~Group() = default;
54
55 /**
56 * Constructor
57 * Parses and populates a configuration group from JSON object data
58 *
Matthew Barthdfd4a052020-09-02 16:31:51 -050059 * @param[in] jsonObj - JSON object
60 */
Matt Spinler9b062432023-01-26 14:38:50 -060061 explicit Group(const json& jsonObj);
Matthew Barthdfd4a052020-09-02 16:31:51 -050062
63 /**
Matthew Barthe5578602021-03-30 12:53:24 -050064 * Copy Constructor
65 * Creates a group from another group's originally parsed JSON object data
66 *
67 * @param[in] origObj - Original Group object to be created from
68 */
69 Group(const Group& origObj);
70
71 /**
Matthew Barthdfd4a052020-09-02 16:31:51 -050072 * @brief Get the members
73 *
74 * @return List of dbus paths representing the members of the group
75 */
76 inline const auto& getMembers() const
77 {
78 return _members;
79 }
80
81 /**
82 * @brief Get the service
83 *
84 * @return Service name serving the members of the group
85 */
86 inline const auto& getService() const
87 {
88 return _service;
89 }
90
Matthew Barth12cb1252021-03-08 16:47:30 -060091 /**
92 * @brief Set the dbus interface name for the group
93 */
Matthew Barth543e89e2021-04-06 11:42:33 -050094 inline void setInterface(const std::string& intf)
Matthew Barth12cb1252021-03-08 16:47:30 -060095 {
96 _interface = intf;
97 }
98
99 /**
100 * @brief Get the group's dbus interface name
101 */
102 inline const auto& getInterface() const
103 {
104 return _interface;
105 }
106
107 /**
108 * @brief Set the dbus property name for the group
109 */
Matthew Barth543e89e2021-04-06 11:42:33 -0500110 inline void setProperty(const std::string& prop)
Matthew Barth12cb1252021-03-08 16:47:30 -0600111 {
112 _property = prop;
113 }
114
115 /**
116 * @brief Get the group's dbus property name
117 */
118 inline const auto& getProperty() const
119 {
120 return _property;
121 }
122
Matthew Barthe5578602021-03-30 12:53:24 -0500123 /**
124 * @brief Set the dbus property's data type for the group
125 */
Matthew Barth543e89e2021-04-06 11:42:33 -0500126 inline void setType(const std::optional<std::string>& type)
Matthew Barthe5578602021-03-30 12:53:24 -0500127 {
128 _type = type;
129 }
130
131 /**
132 * @brief Get the group's dbus property's data type
133 */
134 inline const auto& getType() const
135 {
136 return _type;
137 }
138
139 /**
140 * @brief Set the dbus property's expected value for the group
141 */
Matthew Barth543e89e2021-04-06 11:42:33 -0500142 inline void setValue(const std::optional<PropertyVariantType>& value)
Matthew Barthe5578602021-03-30 12:53:24 -0500143 {
144 _value = value;
145 }
146
147 /**
148 * @brief Get the group's dbus property's expected value
149 */
150 inline const auto& getValue() const
151 {
152 return _value;
153 }
154
Matt Spinlerc2c2db72022-04-07 13:59:37 -0500155 /**
156 * @brief Get the set of all configured group members
157 */
158 static const std::set<std::string>& getAllMembers()
159 {
160 return _allMembers;
161 }
162
Matthew Barthdfd4a052020-09-02 16:31:51 -0500163 private:
164 /* Members of the group */
165 std::vector<std::string> _members;
166
167 /* Service name serving all the members */
168 std::string _service;
169
Matthew Barth12cb1252021-03-08 16:47:30 -0600170 /* Dbus interface name for all the members */
171 std::string _interface;
172
173 /* Dbus property name for all the members */
174 std::string _property;
175
Matthew Barthe5578602021-03-30 12:53:24 -0500176 /* Optional property's data type for all members */
177 std::optional<std::string> _type;
178
179 /* Optional property value for all the members */
180 std::optional<PropertyVariantType> _value;
181
Matt Spinlerc2c2db72022-04-07 13:59:37 -0500182 /* Single set of all group members across all groups */
183 static std::set<std::string> _allMembers;
184
Matthew Barthdfd4a052020-09-02 16:31:51 -0500185 /**
186 * @brief Parse and set the members list
187 *
188 * @param[in] jsonObj - JSON object for the group
189 *
190 * Sets the list of dbus paths making up the members of the group
191 */
192 void setMembers(const json& jsonObj);
193
194 /**
195 * @brief Parse and set the service name(OPTIONAL)
196 *
197 * @param[in] jsonObj - JSON object for the group
198 *
199 * Sets the service name serving the members. It is recommended this service
200 * name be provided for a group containing members served by the fan control
201 * application itself, otherwise they may not be mapped correctly into any
202 * configured events.
203 */
204 void setService(const json& jsonObj);
205};
206
207} // namespace phosphor::fan::control::json