blob: 7cc84e918bfa6f5433946b9545d9bc308ffa99fb [file] [log] [blame]
/**
* Copyright © 2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "config_base.hpp"
#include <nlohmann/json.hpp>
#include <sdbusplus/bus.hpp>
namespace phosphor::fan::control::json
{
using json = nlohmann::json;
/**
* @class Group - Represents a group of dbus objects for configured events
*
* A group contains a list of dbus objects that are logically grouped together
* to be used within one-or-more configured fan control events. An event object
* is configured to apply a set of actions against a list of groups that could
* result in a fan control speed change. A group may also be configured against
* a list of profiles(OPTIONAL) and or denote a specific service(OPTIONAL) that
* serves the list of dbus objects in the group.
*
* (When no profile for a group is given, the group defaults to always be used
* within the events its included in)
*
*/
class Group : public ConfigBase
{
public:
/* JSON file name for groups */
static constexpr auto confFileName = "groups.json";
Group() = delete;
Group(const Group&) = delete;
Group(Group&&) = delete;
Group& operator=(const Group&) = delete;
Group& operator=(Group&&) = delete;
~Group() = default;
/**
* Constructor
* Parses and populates a configuration group from JSON object data
*
* @param[in] bus - sdbusplus bus object
* @param[in] jsonObj - JSON object
*/
Group(sdbusplus::bus::bus& bus, const json& jsonObj);
/**
* @brief Get the members
*
* @return List of dbus paths representing the members of the group
*/
inline const auto& getMembers() const
{
return _members;
}
/**
* @brief Get the service
*
* @return Service name serving the members of the group
*/
inline const auto& getService() const
{
return _service;
}
private:
/* Members of the group */
std::vector<std::string> _members;
/* Service name serving all the members */
std::string _service;
/**
* @brief Parse and set the members list
*
* @param[in] jsonObj - JSON object for the group
*
* Sets the list of dbus paths making up the members of the group
*/
void setMembers(const json& jsonObj);
/**
* @brief Parse and set the service name(OPTIONAL)
*
* @param[in] jsonObj - JSON object for the group
*
* Sets the service name serving the members. It is recommended this service
* name be provided for a group containing members served by the fan control
* application itself, otherwise they may not be mapped correctly into any
* configured events.
*/
void setService(const json& jsonObj);
};
} // namespace phosphor::fan::control::json