xref: /openbmc/phosphor-pid-control/dbus/dbuswrite.hpp (revision cd9e109fef2e1a2cc44fd54a856117245ff47e4d)
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 "dbus/util.hpp"
20da4a5dd1SPatrick Venture #include "interfaces.hpp"
217136a5aeSJames Feist 
227136a5aeSJames Feist #include <sdbusplus/bus.hpp>
23da4a5dd1SPatrick Venture #include <string>
247136a5aeSJames Feist 
257136a5aeSJames Feist constexpr const char* pwmInterface = "xyz.openbmc_project.Control.FanPwm";
267136a5aeSJames Feist 
277136a5aeSJames Feist class DbusWritePercent : public WriteInterface
287136a5aeSJames Feist {
297136a5aeSJames Feist   public:
307136a5aeSJames Feist     DbusWritePercent(const std::string& path, int64_t min, int64_t max,
317136a5aeSJames Feist                      DbusHelperInterface& helper) :
327136a5aeSJames Feist         WriteInterface(min, max),
337136a5aeSJames Feist         path(path)
347136a5aeSJames Feist     {
357136a5aeSJames Feist         auto tempBus = sdbusplus::bus::new_default();
367136a5aeSJames Feist         connectionName = helper.GetService(tempBus, pwmInterface, path);
377136a5aeSJames Feist     }
387136a5aeSJames Feist 
397136a5aeSJames Feist     void write(double value) override;
407136a5aeSJames Feist 
417136a5aeSJames Feist   private:
427136a5aeSJames Feist     std::string path;
437136a5aeSJames Feist     std::string connectionName;
44*cd9e109fSJames Feist     int64_t oldValue = -1;
457136a5aeSJames Feist };
467136a5aeSJames Feist 
477136a5aeSJames Feist class DbusWrite : public WriteInterface
487136a5aeSJames Feist {
497136a5aeSJames Feist   public:
507136a5aeSJames Feist     DbusWrite(const std::string& path, int64_t min, int64_t max,
517136a5aeSJames Feist               DbusHelperInterface& helper) :
527136a5aeSJames Feist         WriteInterface(min, max),
537136a5aeSJames Feist         path(path)
547136a5aeSJames Feist     {
557136a5aeSJames Feist         auto tempBus = sdbusplus::bus::new_default();
567136a5aeSJames Feist         connectionName = helper.GetService(tempBus, pwmInterface, path);
577136a5aeSJames Feist     }
587136a5aeSJames Feist 
597136a5aeSJames Feist     void write(double value) override;
607136a5aeSJames Feist 
617136a5aeSJames Feist   private:
627136a5aeSJames Feist     std::string path;
637136a5aeSJames Feist     std::string connectionName;
64*cd9e109fSJames Feist     int64_t oldValue = -1;
657136a5aeSJames Feist };
66