107fecfc6SMatthew Barth /**
207fecfc6SMatthew Barth  * Copyright © 2021 IBM Corporation
307fecfc6SMatthew Barth  *
407fecfc6SMatthew Barth  * Licensed under the Apache License, Version 2.0 (the "License");
507fecfc6SMatthew Barth  * you may not use this file except in compliance with the License.
607fecfc6SMatthew Barth  * You may obtain a copy of the License at
707fecfc6SMatthew Barth  *
807fecfc6SMatthew Barth  *     http://www.apache.org/licenses/LICENSE-2.0
907fecfc6SMatthew Barth  *
1007fecfc6SMatthew Barth  * Unless required by applicable law or agreed to in writing, software
1107fecfc6SMatthew Barth  * distributed under the License is distributed on an "AS IS" BASIS,
1207fecfc6SMatthew Barth  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1307fecfc6SMatthew Barth  * See the License for the specific language governing permissions and
1407fecfc6SMatthew Barth  * limitations under the License.
1507fecfc6SMatthew Barth  */
1607fecfc6SMatthew Barth #pragma once
1707fecfc6SMatthew Barth 
1807fecfc6SMatthew Barth #include "../zone.hpp"
1907fecfc6SMatthew Barth #include "action.hpp"
2007fecfc6SMatthew Barth #include "group.hpp"
2107fecfc6SMatthew Barth 
2207fecfc6SMatthew Barth #include <nlohmann/json.hpp>
2307fecfc6SMatthew Barth 
2407fecfc6SMatthew Barth namespace phosphor::fan::control::json
2507fecfc6SMatthew Barth {
2607fecfc6SMatthew Barth 
2707fecfc6SMatthew Barth using json = nlohmann::json;
2807fecfc6SMatthew Barth 
2907fecfc6SMatthew Barth /**
3007fecfc6SMatthew Barth  * @class RequestTargetBase - Action to set the requested target base
3107fecfc6SMatthew Barth  *
3207fecfc6SMatthew Barth  * Sets the base of a calculated requested target to the maximum value found
3307fecfc6SMatthew Barth  * from the properties given within a group. The requested target base is what
3407fecfc6SMatthew Barth  * the calculated requested target should be determined from when changing fan
3507fecfc6SMatthew Barth  * targets. By default, the base of the next calculated requested target is the
3607fecfc6SMatthew Barth  * current target of the zone. This action allows that base to be changed
3707fecfc6SMatthew Barth  * according to the maximum value found from a given group of dbus objects.
3807fecfc6SMatthew Barth  */
3907fecfc6SMatthew Barth class RequestTargetBase :
4007fecfc6SMatthew Barth     public ActionBase,
4107fecfc6SMatthew Barth     public ActionRegister<RequestTargetBase>
4207fecfc6SMatthew Barth {
4307fecfc6SMatthew Barth   public:
4407fecfc6SMatthew Barth     /* Name of this action */
45*55ed901bSMatthew Barth     static constexpr auto name = "set_request_target_base_with_max";
4607fecfc6SMatthew Barth 
4707fecfc6SMatthew Barth     RequestTargetBase() = delete;
4807fecfc6SMatthew Barth     RequestTargetBase(const RequestTargetBase&) = delete;
4907fecfc6SMatthew Barth     RequestTargetBase(RequestTargetBase&&) = delete;
5007fecfc6SMatthew Barth     RequestTargetBase& operator=(const RequestTargetBase&) = delete;
5107fecfc6SMatthew Barth     RequestTargetBase& operator=(RequestTargetBase&&) = delete;
5207fecfc6SMatthew Barth     ~RequestTargetBase() = default;
5307fecfc6SMatthew Barth 
5407fecfc6SMatthew Barth     /**
5507fecfc6SMatthew Barth      * @brief Update the requested target base
5607fecfc6SMatthew Barth      *
57bfd7e1b7SMatthew Barth      * @param[in] jsonObj - JSON configuration of this action
5819c77494SMatthew Barth      * @param[in] groups - Groups of dbus objects the action uses
5907fecfc6SMatthew Barth      */
6019c77494SMatthew Barth     RequestTargetBase(const json& jsonObj, const std::vector<Group>& groups);
6107fecfc6SMatthew Barth 
6207fecfc6SMatthew Barth     /**
6307fecfc6SMatthew Barth      * @brief Run the action
6407fecfc6SMatthew Barth      *
6507fecfc6SMatthew Barth      * Determines the maximum value from the properties of the group of dbus
6607fecfc6SMatthew Barth      * objects and sets the requested target base to this value. Only positive
6707fecfc6SMatthew Barth      * integer or floating point types are supported as these are the only
6807fecfc6SMatthew Barth      * valid types for a fan target to be based off of.
6907fecfc6SMatthew Barth      *
7007fecfc6SMatthew Barth      * @param[in] zone - Zone to run the action on
7107fecfc6SMatthew Barth      */
726d2476c9SMatthew Barth     void run(Zone& zone) override;
7307fecfc6SMatthew Barth };
7407fecfc6SMatthew Barth 
7507fecfc6SMatthew Barth } // namespace phosphor::fan::control::json
76