blob: dd5c6a08b2a2e770a0eac57abe6a1c22501b633a [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
22namespace phosphor::fan::control::json
23{
24
25using json = nlohmann::json;
26
27/**
28 * @class Group - Represents a group of dbus objects for configured events
29 *
30 * A group contains a list of dbus objects that are logically grouped together
31 * to be used within one-or-more configured fan control events. An event object
32 * is configured to apply a set of actions against a list of groups that could
Matthew Barthe47c9582021-03-09 14:24:02 -060033 * result in a fan control target change. A group may also be configured against
Matthew Barthdfd4a052020-09-02 16:31:51 -050034 * a list of profiles(OPTIONAL) and or denote a specific service(OPTIONAL) that
35 * serves the list of dbus objects in the group.
36 *
37 * (When no profile for a group is given, the group defaults to always be used
38 * within the events its included in)
39 *
40 */
41class Group : public ConfigBase
42{
43 public:
44 /* JSON file name for groups */
45 static constexpr auto confFileName = "groups.json";
46
47 Group() = delete;
Matthew Barthdfd4a052020-09-02 16:31:51 -050048 Group(Group&&) = delete;
49 Group& operator=(const Group&) = delete;
50 Group& operator=(Group&&) = delete;
51 ~Group() = default;
52
53 /**
54 * Constructor
55 * Parses and populates a configuration group from JSON object data
56 *
Matthew Barthdfd4a052020-09-02 16:31:51 -050057 * @param[in] jsonObj - JSON object
58 */
Matthew Barth9403a212021-05-17 09:31:50 -050059 Group(const json& jsonObj);
Matthew Barthdfd4a052020-09-02 16:31:51 -050060
61 /**
Matthew Barthe5578602021-03-30 12:53:24 -050062 * Copy Constructor
63 * Creates a group from another group's originally parsed JSON object data
64 *
65 * @param[in] origObj - Original Group object to be created from
66 */
67 Group(const Group& origObj);
68
69 /**
Matthew Barthdfd4a052020-09-02 16:31:51 -050070 * @brief Get the members
71 *
72 * @return List of dbus paths representing the members of the group
73 */
74 inline const auto& getMembers() const
75 {
76 return _members;
77 }
78
79 /**
80 * @brief Get the service
81 *
82 * @return Service name serving the members of the group
83 */
84 inline const auto& getService() const
85 {
86 return _service;
87 }
88
Matthew Barth12cb1252021-03-08 16:47:30 -060089 /**
90 * @brief Set the dbus interface name for the group
91 */
Matthew Barth543e89e2021-04-06 11:42:33 -050092 inline void setInterface(const std::string& intf)
Matthew Barth12cb1252021-03-08 16:47:30 -060093 {
94 _interface = intf;
95 }
96
97 /**
98 * @brief Get the group's dbus interface name
99 */
100 inline const auto& getInterface() const
101 {
102 return _interface;
103 }
104
105 /**
106 * @brief Set the dbus property name for the group
107 */
Matthew Barth543e89e2021-04-06 11:42:33 -0500108 inline void setProperty(const std::string& prop)
Matthew Barth12cb1252021-03-08 16:47:30 -0600109 {
110 _property = prop;
111 }
112
113 /**
114 * @brief Get the group's dbus property name
115 */
116 inline const auto& getProperty() const
117 {
118 return _property;
119 }
120
Matthew Barthe5578602021-03-30 12:53:24 -0500121 /**
122 * @brief Set the dbus property's data type for the group
123 */
Matthew Barth543e89e2021-04-06 11:42:33 -0500124 inline void setType(const std::optional<std::string>& type)
Matthew Barthe5578602021-03-30 12:53:24 -0500125 {
126 _type = type;
127 }
128
129 /**
130 * @brief Get the group's dbus property's data type
131 */
132 inline const auto& getType() const
133 {
134 return _type;
135 }
136
137 /**
138 * @brief Set the dbus property's expected value for the group
139 */
Matthew Barth543e89e2021-04-06 11:42:33 -0500140 inline void setValue(const std::optional<PropertyVariantType>& value)
Matthew Barthe5578602021-03-30 12:53:24 -0500141 {
142 _value = value;
143 }
144
145 /**
146 * @brief Get the group's dbus property's expected value
147 */
148 inline const auto& getValue() const
149 {
150 return _value;
151 }
152
Matthew Barthdfd4a052020-09-02 16:31:51 -0500153 private:
154 /* Members of the group */
155 std::vector<std::string> _members;
156
157 /* Service name serving all the members */
158 std::string _service;
159
Matthew Barth12cb1252021-03-08 16:47:30 -0600160 /* Dbus interface name for all the members */
161 std::string _interface;
162
163 /* Dbus property name for all the members */
164 std::string _property;
165
Matthew Barthe5578602021-03-30 12:53:24 -0500166 /* Optional property's data type for all members */
167 std::optional<std::string> _type;
168
169 /* Optional property value for all the members */
170 std::optional<PropertyVariantType> _value;
171
Matthew Barthdfd4a052020-09-02 16:31:51 -0500172 /**
173 * @brief Parse and set the members list
174 *
175 * @param[in] jsonObj - JSON object for the group
176 *
177 * Sets the list of dbus paths making up the members of the group
178 */
179 void setMembers(const json& jsonObj);
180
181 /**
182 * @brief Parse and set the service name(OPTIONAL)
183 *
184 * @param[in] jsonObj - JSON object for the group
185 *
186 * Sets the service name serving the members. It is recommended this service
187 * name be provided for a group containing members served by the fan control
188 * application itself, otherwise they may not be mapped correctly into any
189 * configured events.
190 */
191 void setService(const json& jsonObj);
192};
193
194} // namespace phosphor::fan::control::json