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