xref: /openbmc/phosphor-pid-control/dbus/dbuswrite.hpp (revision a076487aab0ee71ea32d53f798d5ca6b31677278)
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 "interfaces.hpp"
20 #include "util.hpp"
21 
22 #include <sdbusplus/bus.hpp>
23 
24 #include <memory>
25 #include <string>
26 
27 namespace pid_control
28 {
29 
30 class DbusWritePercent : public WriteInterface
31 {
32   public:
33     static std::unique_ptr<WriteInterface>
34         createDbusWrite(const std::string& path, int64_t min, int64_t max,
35                         DbusHelperInterface& helper);
36 
37     DbusWritePercent(const std::string& path, int64_t min, int64_t max,
38                      const std::string& connectionName) :
39         WriteInterface(min, max),
40         path(path), connectionName(connectionName)
41     {}
42 
43     void write(double value) override;
44 
45   private:
46     std::string path;
47     std::string connectionName;
48     int64_t oldValue = -1;
49 };
50 
51 class DbusWrite : public WriteInterface
52 {
53   public:
54     static std::unique_ptr<WriteInterface>
55         createDbusWrite(const std::string& path, int64_t min, int64_t max,
56                         DbusHelperInterface& helper);
57 
58     DbusWrite(const std::string& path, int64_t min, int64_t max,
59               const std::string& connectionName) :
60         WriteInterface(min, max),
61         path(path), connectionName(connectionName)
62     {}
63 
64     void write(double value) override;
65 
66   private:
67     std::string path;
68     std::string connectionName;
69     int64_t oldValue = -1;
70 };
71 
72 } // namespace pid_control
73