1 /**
2  * Copyright © 2021 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 "xyz/openbmc_project/Control/ThermalMode/server.hpp"
19 
20 /* Extend the Control::ThermalMode interface */
21 using ThermalModeIntf = sdbusplus::server::object_t<
22     sdbusplus::xyz::openbmc_project::Control::server::ThermalMode>;
23 
24 namespace phosphor::fan::control::json
25 {
26 
27 class Zone;
28 
29 class DBusZone : public ThermalModeIntf
30 {
31   public:
32     static constexpr auto thermalModeIntf =
33         "xyz.openbmc_project.Control.ThermalMode";
34     static constexpr auto supportedProp = "Supported";
35     static constexpr auto currentProp = "Current";
36 
37     DBusZone() = delete;
38     DBusZone(const DBusZone&) = delete;
39     DBusZone(DBusZone&&) = delete;
40     DBusZone& operator=(const DBusZone&) = delete;
41     DBusZone& operator=(DBusZone&&) = delete;
42     ~DBusZone() = default;
43 
44     /**
45      * Constructor
46      * Creates a thermal control dbus object associated with the given zone
47      *
48      * @param[in] zone - Zone object
49      */
50     explicit DBusZone(const Zone& zone);
51 
52     /**
53      * @brief Overridden thermalmode interface's set 'Current' property function
54      *
55      * @param[in] value - Value to set 'Current' to
56      *
57      * @return - The updated value of the 'Current' property
58      */
59     std::string current(std::string value) override;
60 
61     /**
62      * @brief Restore persisted thermalmode `Current` mode property value,
63      * setting the mode to "Default" otherwise
64      */
65     void restoreCurrentMode();
66 
67   private:
68     /* Zone object associated with this thermal control dbus object */
69     const Zone& _zone;
70 
71     /**
72      * @brief Save the thermalmode `Current` mode property to persisted storage
73      */
74     void saveCurrentMode();
75 };
76 
77 } // namespace phosphor::fan::control::json
78