xref: /openbmc/phosphor-pid-control/dbus/dbuswrite.hpp (revision a076487aab0ee71ea32d53f798d5ca6b31677278)
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 
19da4a5dd1SPatrick Venture #include "interfaces.hpp"
200c8223b5SJames Feist #include "util.hpp"
217136a5aeSJames Feist 
227136a5aeSJames Feist #include <sdbusplus/bus.hpp>
23a83a3eccSPatrick Venture 
24a83a3eccSPatrick Venture #include <memory>
25da4a5dd1SPatrick Venture #include <string>
267136a5aeSJames Feist 
27*a076487aSPatrick Venture namespace pid_control
28*a076487aSPatrick Venture {
29*a076487aSPatrick Venture 
307136a5aeSJames Feist class DbusWritePercent : public WriteInterface
317136a5aeSJames Feist {
327136a5aeSJames Feist   public:
33f5e770b3SPatrick Venture     static std::unique_ptr<WriteInterface>
34f5e770b3SPatrick Venture         createDbusWrite(const std::string& path, int64_t min, int64_t max,
35f5e770b3SPatrick Venture                         DbusHelperInterface& helper);
36f5e770b3SPatrick Venture 
377136a5aeSJames Feist     DbusWritePercent(const std::string& path, int64_t min, int64_t max,
38f5e770b3SPatrick Venture                      const std::string& connectionName) :
397136a5aeSJames Feist         WriteInterface(min, max),
40f5e770b3SPatrick Venture         path(path), connectionName(connectionName)
41a83a3eccSPatrick Venture     {}
427136a5aeSJames Feist 
437136a5aeSJames Feist     void write(double value) override;
447136a5aeSJames Feist 
457136a5aeSJames Feist   private:
467136a5aeSJames Feist     std::string path;
477136a5aeSJames Feist     std::string connectionName;
48cd9e109fSJames Feist     int64_t oldValue = -1;
497136a5aeSJames Feist };
507136a5aeSJames Feist 
517136a5aeSJames Feist class DbusWrite : public WriteInterface
527136a5aeSJames Feist {
537136a5aeSJames Feist   public:
54f5e770b3SPatrick Venture     static std::unique_ptr<WriteInterface>
55f5e770b3SPatrick Venture         createDbusWrite(const std::string& path, int64_t min, int64_t max,
56f5e770b3SPatrick Venture                         DbusHelperInterface& helper);
57f5e770b3SPatrick Venture 
587136a5aeSJames Feist     DbusWrite(const std::string& path, int64_t min, int64_t max,
59f5e770b3SPatrick Venture               const std::string& connectionName) :
607136a5aeSJames Feist         WriteInterface(min, max),
61f5e770b3SPatrick Venture         path(path), connectionName(connectionName)
62a83a3eccSPatrick Venture     {}
637136a5aeSJames Feist 
647136a5aeSJames Feist     void write(double value) override;
657136a5aeSJames Feist 
667136a5aeSJames Feist   private:
677136a5aeSJames Feist     std::string path;
687136a5aeSJames Feist     std::string connectionName;
69cd9e109fSJames Feist     int64_t oldValue = -1;
707136a5aeSJames Feist };
71*a076487aSPatrick Venture 
72*a076487aSPatrick Venture } // namespace pid_control
73