Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 1 | /** |
| 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 Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 21 | |
| 22 | namespace phosphor::fan::control::json |
| 23 | { |
| 24 | |
| 25 | using 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 Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 33 | * result in a fan control target change. A group may also be configured against |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 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 | */ |
| 41 | class 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 Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 58 | * @param[in] jsonObj - JSON object |
| 59 | */ |
Matthew Barth | 391ade0 | 2021-01-15 14:33:21 -0600 | [diff] [blame] | 60 | Group(const json& jsonObj); |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 61 | |
| 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 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 82 | /** |
| 83 | * @brief Set the dbus interface name for the group |
| 84 | */ |
| 85 | inline void setInterface(std::string& intf) |
| 86 | { |
| 87 | _interface = intf; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @brief Get the group's dbus interface name |
| 92 | */ |
| 93 | inline const auto& getInterface() const |
| 94 | { |
| 95 | return _interface; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @brief Set the dbus property name for the group |
| 100 | */ |
| 101 | inline void setProperty(std::string& prop) |
| 102 | { |
| 103 | _property = prop; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @brief Get the group's dbus property name |
| 108 | */ |
| 109 | inline const auto& getProperty() const |
| 110 | { |
| 111 | return _property; |
| 112 | } |
| 113 | |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 114 | private: |
| 115 | /* Members of the group */ |
| 116 | std::vector<std::string> _members; |
| 117 | |
| 118 | /* Service name serving all the members */ |
| 119 | std::string _service; |
| 120 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 121 | /* Dbus interface name for all the members */ |
| 122 | std::string _interface; |
| 123 | |
| 124 | /* Dbus property name for all the members */ |
| 125 | std::string _property; |
| 126 | |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 127 | /** |
| 128 | * @brief Parse and set the members list |
| 129 | * |
| 130 | * @param[in] jsonObj - JSON object for the group |
| 131 | * |
| 132 | * Sets the list of dbus paths making up the members of the group |
| 133 | */ |
| 134 | void setMembers(const json& jsonObj); |
| 135 | |
| 136 | /** |
| 137 | * @brief Parse and set the service name(OPTIONAL) |
| 138 | * |
| 139 | * @param[in] jsonObj - JSON object for the group |
| 140 | * |
| 141 | * Sets the service name serving the members. It is recommended this service |
| 142 | * name be provided for a group containing members served by the fan control |
| 143 | * application itself, otherwise they may not be mapped correctly into any |
| 144 | * configured events. |
| 145 | */ |
| 146 | void setService(const json& jsonObj); |
| 147 | }; |
| 148 | |
| 149 | } // namespace phosphor::fan::control::json |