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     void write(double value, bool force, int64_t* written) override;
46 
47   private:
48     std::string path;
49     std::string connectionName;
50     int64_t oldValue = -1;
51 };
52 
53 class DbusWrite : public WriteInterface
54 {
55   public:
56     static std::unique_ptr<WriteInterface>
57         createDbusWrite(const std::string& path, int64_t min, int64_t max,
58                         std::unique_ptr<DbusHelperInterface> helper);
59 
60     DbusWrite(const std::string& path, int64_t min, int64_t max,
61               const std::string& connectionName) :
62         WriteInterface(min, max),
63         path(path), connectionName(connectionName)
64     {}
65 
66     void write(double value) override;
67     void write(double value, bool needRedundant, int64_t* rawWritten) override;
68 
69   private:
70     std::string path;
71     std::string connectionName;
72     int64_t oldValue = -1;
73 };
74 
75 } // namespace pid_control
76