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> 21 #include <sdbusplus/bus.hpp> 22 23 namespace phosphor::fan::control::json 24 { 25 26 using json = nlohmann::json; 27 28 /** 29 * @class Group - Represents a group of dbus objects for configured events 30 * 31 * A group contains a list of dbus objects that are logically grouped together 32 * to be used within one-or-more configured fan control events. An event object 33 * is configured to apply a set of actions against a list of groups that could 34 * result in a fan control speed change. A group may also be configured against 35 * a list of profiles(OPTIONAL) and or denote a specific service(OPTIONAL) that 36 * serves the list of dbus objects in the group. 37 * 38 * (When no profile for a group is given, the group defaults to always be used 39 * within the events its included in) 40 * 41 */ 42 class Group : public ConfigBase 43 { 44 public: 45 /* JSON file name for groups */ 46 static constexpr auto confFileName = "groups.json"; 47 48 Group() = delete; 49 Group(const Group&) = delete; 50 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 * 59 * @param[in] bus - sdbusplus bus object 60 * @param[in] jsonObj - JSON object 61 */ 62 Group(sdbusplus::bus::bus& bus, const json& jsonObj); 63 64 /** 65 * @brief Get the members 66 * 67 * @return List of dbus paths representing the members of the group 68 */ 69 inline const auto& getMembers() const 70 { 71 return _members; 72 } 73 74 /** 75 * @brief Get the service 76 * 77 * @return Service name serving the members of the group 78 */ 79 inline const auto& getService() const 80 { 81 return _service; 82 } 83 84 private: 85 /* Members of the group */ 86 std::vector<std::string> _members; 87 88 /* Service name serving all the members */ 89 std::string _service; 90 91 /** 92 * @brief Parse and set the members list 93 * 94 * @param[in] jsonObj - JSON object for the group 95 * 96 * Sets the list of dbus paths making up the members of the group 97 */ 98 void setMembers(const json& jsonObj); 99 100 /** 101 * @brief Parse and set the service name(OPTIONAL) 102 * 103 * @param[in] jsonObj - JSON object for the group 104 * 105 * Sets the service name serving the members. It is recommended this service 106 * name be provided for a group containing members served by the fan control 107 * application itself, otherwise they may not be mapped correctly into any 108 * configured events. 109 */ 110 void setService(const json& jsonObj); 111 }; 112 113 } // namespace phosphor::fan::control::json 114