blob: ce8d12c47916d15b9c08c2ee5daff40eb0c4ae4b [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
Matthew Barthe6d1f782021-05-14 12:52:20 -050058 * @param[in] sdbusplus bus object not used
Matthew Barthdfd4a052020-09-02 16:31:51 -050059 */
Matthew Barthe6d1f782021-05-14 12:52:20 -050060 Group(const json& jsonObj, sdbusplus::bus::bus&);
Matthew Barthdfd4a052020-09-02 16:31:51 -050061
62 /**
Matthew Barthe5578602021-03-30 12:53:24 -050063 * Copy Constructor
64 * Creates a group from another group's originally parsed JSON object data
65 *
66 * @param[in] origObj - Original Group object to be created from
67 */
68 Group(const Group& origObj);
69
70 /**
Matthew Barthdfd4a052020-09-02 16:31:51 -050071 * @brief Get the members
72 *
73 * @return List of dbus paths representing the members of the group
74 */
75 inline const auto& getMembers() const
76 {
77 return _members;
78 }
79
80 /**
81 * @brief Get the service
82 *
83 * @return Service name serving the members of the group
84 */
85 inline const auto& getService() const
86 {
87 return _service;
88 }
89
Matthew Barth12cb1252021-03-08 16:47:30 -060090 /**
91 * @brief Set the dbus interface name for the group
92 */
Matthew Barth543e89e2021-04-06 11:42:33 -050093 inline void setInterface(const std::string& intf)
Matthew Barth12cb1252021-03-08 16:47:30 -060094 {
95 _interface = intf;
96 }
97
98 /**
99 * @brief Get the group's dbus interface name
100 */
101 inline const auto& getInterface() const
102 {
103 return _interface;
104 }
105
106 /**
107 * @brief Set the dbus property name for the group
108 */
Matthew Barth543e89e2021-04-06 11:42:33 -0500109 inline void setProperty(const std::string& prop)
Matthew Barth12cb1252021-03-08 16:47:30 -0600110 {
111 _property = prop;
112 }
113
114 /**
115 * @brief Get the group's dbus property name
116 */
117 inline const auto& getProperty() const
118 {
119 return _property;
120 }
121
Matthew Barthe5578602021-03-30 12:53:24 -0500122 /**
123 * @brief Set the dbus property's data type for the group
124 */
Matthew Barth543e89e2021-04-06 11:42:33 -0500125 inline void setType(const std::optional<std::string>& type)
Matthew Barthe5578602021-03-30 12:53:24 -0500126 {
127 _type = type;
128 }
129
130 /**
131 * @brief Get the group's dbus property's data type
132 */
133 inline const auto& getType() const
134 {
135 return _type;
136 }
137
138 /**
139 * @brief Set the dbus property's expected value for the group
140 */
Matthew Barth543e89e2021-04-06 11:42:33 -0500141 inline void setValue(const std::optional<PropertyVariantType>& value)
Matthew Barthe5578602021-03-30 12:53:24 -0500142 {
143 _value = value;
144 }
145
146 /**
147 * @brief Get the group's dbus property's expected value
148 */
149 inline const auto& getValue() const
150 {
151 return _value;
152 }
153
Matthew Barthdfd4a052020-09-02 16:31:51 -0500154 private:
155 /* Members of the group */
156 std::vector<std::string> _members;
157
158 /* Service name serving all the members */
159 std::string _service;
160
Matthew Barth12cb1252021-03-08 16:47:30 -0600161 /* Dbus interface name for all the members */
162 std::string _interface;
163
164 /* Dbus property name for all the members */
165 std::string _property;
166
Matthew Barthe5578602021-03-30 12:53:24 -0500167 /* Optional property's data type for all members */
168 std::optional<std::string> _type;
169
170 /* Optional property value for all the members */
171 std::optional<PropertyVariantType> _value;
172
Matthew Barthdfd4a052020-09-02 16:31:51 -0500173 /**
174 * @brief Parse and set the members list
175 *
176 * @param[in] jsonObj - JSON object for the group
177 *
178 * Sets the list of dbus paths making up the members of the group
179 */
180 void setMembers(const json& jsonObj);
181
182 /**
183 * @brief Parse and set the service name(OPTIONAL)
184 *
185 * @param[in] jsonObj - JSON object for the group
186 *
187 * Sets the service name serving the members. It is recommended this service
188 * name be provided for a group containing members served by the fan control
189 * application itself, otherwise they may not be mapped correctly into any
190 * configured events.
191 */
192 void setService(const json& jsonObj);
193};
194
195} // namespace phosphor::fan::control::json