blob: e8d607fd5adc8310c6fc2684da33bcdcc42b61d3 [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
33 * result in a fan control speed change. A group may also be configured against
34 * 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;
48 Group(const Group&) = delete;
49 Group(Group&&) = delete;
50 Group& operator=(const Group&) = delete;
51 Group& operator=(Group&&) = delete;
52 ~Group() = default;
53
54 /**
55 * Constructor
56 * Parses and populates a configuration group from JSON object data
57 *
Matthew Barthdfd4a052020-09-02 16:31:51 -050058 * @param[in] jsonObj - JSON object
59 */
Matthew Barth391ade02021-01-15 14:33:21 -060060 Group(const json& jsonObj);
Matthew Barthdfd4a052020-09-02 16:31:51 -050061
62 /**
63 * @brief Get the members
64 *
65 * @return List of dbus paths representing the members of the group
66 */
67 inline const auto& getMembers() const
68 {
69 return _members;
70 }
71
72 /**
73 * @brief Get the service
74 *
75 * @return Service name serving the members of the group
76 */
77 inline const auto& getService() const
78 {
79 return _service;
80 }
81
82 private:
83 /* Members of the group */
84 std::vector<std::string> _members;
85
86 /* Service name serving all the members */
87 std::string _service;
88
89 /**
90 * @brief Parse and set the members list
91 *
92 * @param[in] jsonObj - JSON object for the group
93 *
94 * Sets the list of dbus paths making up the members of the group
95 */
96 void setMembers(const json& jsonObj);
97
98 /**
99 * @brief Parse and set the service name(OPTIONAL)
100 *
101 * @param[in] jsonObj - JSON object for the group
102 *
103 * Sets the service name serving the members. It is recommended this service
104 * name be provided for a group containing members served by the fan control
105 * application itself, otherwise they may not be mapped correctly into any
106 * configured events.
107 */
108 void setService(const json& jsonObj);
109};
110
111} // namespace phosphor::fan::control::json