xref: /openbmc/phosphor-pid-control/dbus/dbuswrite.hpp (revision da4a5dd133b88ebfeb69e89d05b381f81ba70e50)
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 
19*da4a5dd1SPatrick Venture #include "dbus/util.hpp"
20*da4a5dd1SPatrick Venture #include "interfaces.hpp"
217136a5aeSJames Feist 
227136a5aeSJames Feist #include <sdbusplus/bus.hpp>
23*da4a5dd1SPatrick 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;
447136a5aeSJames Feist };
457136a5aeSJames Feist 
467136a5aeSJames Feist class DbusWrite : public WriteInterface
477136a5aeSJames Feist {
487136a5aeSJames Feist   public:
497136a5aeSJames Feist     DbusWrite(const std::string &path, int64_t min, int64_t max,
507136a5aeSJames Feist               DbusHelperInterface &helper) :
517136a5aeSJames Feist         WriteInterface(min, max),
527136a5aeSJames Feist         path(path)
537136a5aeSJames Feist     {
547136a5aeSJames Feist         auto tempBus = sdbusplus::bus::new_default();
557136a5aeSJames Feist         connectionName = helper.GetService(tempBus, pwmInterface, path);
567136a5aeSJames Feist     }
577136a5aeSJames Feist 
587136a5aeSJames Feist     void write(double value) override;
597136a5aeSJames Feist 
607136a5aeSJames Feist   private:
617136a5aeSJames Feist     std::string path;
627136a5aeSJames Feist     std::string connectionName;
637136a5aeSJames Feist };
64