xref: /openbmc/phosphor-pid-control/dbus/dbuswrite.hpp (revision 2400ce43fafd35bc26b2a6798ac50ddf6aa7a517)
17136a5aeSJames Feist /*
27136a5aeSJames Feist // Copyright (c) 2018 Intel Corporation
37136a5aeSJames Feist //
47136a5aeSJames Feist // Licensed under the Apache License, Version 2.0 (the "License");
57136a5aeSJames Feist // you may not use this file except in compliance with the License.
67136a5aeSJames Feist // You may obtain a copy of the License at
77136a5aeSJames Feist //
87136a5aeSJames Feist //      http://www.apache.org/licenses/LICENSE-2.0
97136a5aeSJames Feist //
107136a5aeSJames Feist // Unless required by applicable law or agreed to in writing, software
117136a5aeSJames Feist // distributed under the License is distributed on an "AS IS" BASIS,
127136a5aeSJames Feist // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137136a5aeSJames Feist // See the License for the specific language governing permissions and
147136a5aeSJames Feist // limitations under the License.
157136a5aeSJames Feist */
167136a5aeSJames Feist 
177136a5aeSJames Feist #pragma once
187136a5aeSJames Feist 
19aadb30ddSPatrick Venture #include "dbushelper_interface.hpp"
20da4a5dd1SPatrick Venture #include "interfaces.hpp"
210c8223b5SJames Feist #include "util.hpp"
227136a5aeSJames Feist 
237136a5aeSJames Feist #include <sdbusplus/bus.hpp>
24a83a3eccSPatrick Venture 
25a83a3eccSPatrick Venture #include <memory>
26da4a5dd1SPatrick Venture #include <string>
277136a5aeSJames Feist 
28a076487aSPatrick Venture namespace pid_control
29a076487aSPatrick Venture {
30a076487aSPatrick Venture 
317136a5aeSJames Feist class DbusWritePercent : public WriteInterface
327136a5aeSJames Feist {
337136a5aeSJames Feist   public:
34f5e770b3SPatrick Venture     static std::unique_ptr<WriteInterface>
35f5e770b3SPatrick Venture         createDbusWrite(const std::string& path, int64_t min, int64_t max,
368729eb98SPatrick Venture                         std::unique_ptr<DbusHelperInterface> helper);
37f5e770b3SPatrick Venture 
387136a5aeSJames Feist     DbusWritePercent(const std::string& path, int64_t min, int64_t max,
39f5e770b3SPatrick Venture                      const std::string& connectionName) :
407136a5aeSJames Feist         WriteInterface(min, max),
41f5e770b3SPatrick Venture         path(path), connectionName(connectionName)
42a83a3eccSPatrick Venture     {}
437136a5aeSJames Feist 
447136a5aeSJames Feist     void write(double value) override;
45*2400ce43SJosh Lehan     void write(double value, bool force, int64_t* written) override;
467136a5aeSJames Feist 
477136a5aeSJames Feist   private:
487136a5aeSJames Feist     std::string path;
497136a5aeSJames Feist     std::string connectionName;
50cd9e109fSJames Feist     int64_t oldValue = -1;
517136a5aeSJames Feist };
527136a5aeSJames Feist 
537136a5aeSJames Feist class DbusWrite : public WriteInterface
547136a5aeSJames Feist {
557136a5aeSJames Feist   public:
56f5e770b3SPatrick Venture     static std::unique_ptr<WriteInterface>
57f5e770b3SPatrick Venture         createDbusWrite(const std::string& path, int64_t min, int64_t max,
588729eb98SPatrick Venture                         std::unique_ptr<DbusHelperInterface> helper);
59f5e770b3SPatrick Venture 
607136a5aeSJames Feist     DbusWrite(const std::string& path, int64_t min, int64_t max,
61f5e770b3SPatrick Venture               const std::string& connectionName) :
627136a5aeSJames Feist         WriteInterface(min, max),
63f5e770b3SPatrick Venture         path(path), connectionName(connectionName)
64a83a3eccSPatrick Venture     {}
657136a5aeSJames Feist 
667136a5aeSJames Feist     void write(double value) override;
67*2400ce43SJosh Lehan     void write(double value, bool needRedundant, int64_t* rawWritten) override;
687136a5aeSJames Feist 
697136a5aeSJames Feist   private:
707136a5aeSJames Feist     std::string path;
717136a5aeSJames Feist     std::string connectionName;
72cd9e109fSJames Feist     int64_t oldValue = -1;
737136a5aeSJames Feist };
74a076487aSPatrick Venture 
75a076487aSPatrick Venture } // namespace pid_control
76