1 /*
2 // Copyright (c) 2018 Intel 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 
17 #pragma once
18 
19 #include <string>
20 
21 #include <dbus/util.hpp>
22 #include <interfaces.hpp>
23 #include <sdbusplus/bus.hpp>
24 
25 constexpr const char *pwmInterface = "xyz.openbmc_project.Control.FanPwm";
26 
27 class DbusWritePercent : public WriteInterface
28 {
29   public:
30     DbusWritePercent(const std::string &path, int64_t min, int64_t max,
31                      DbusHelperInterface &helper) :
32         WriteInterface(min, max),
33         path(path)
34     {
35         auto tempBus = sdbusplus::bus::new_default();
36         connectionName = helper.GetService(tempBus, pwmInterface, path);
37     }
38 
39     void write(double value) override;
40 
41   private:
42     std::string path;
43     std::string connectionName;
44 };
45 
46 class DbusWrite : public WriteInterface
47 {
48   public:
49     DbusWrite(const std::string &path, int64_t min, int64_t max,
50               DbusHelperInterface &helper) :
51         WriteInterface(min, max),
52         path(path)
53     {
54         auto tempBus = sdbusplus::bus::new_default();
55         connectionName = helper.GetService(tempBus, pwmInterface, path);
56     }
57 
58     void write(double value) override;
59 
60   private:
61     std::string path;
62     std::string connectionName;
63 };
64