1*7136a5aeSJames Feist /* 2*7136a5aeSJames Feist // Copyright (c) 2018 Intel Corporation 3*7136a5aeSJames Feist // 4*7136a5aeSJames Feist // Licensed under the Apache License, Version 2.0 (the "License"); 5*7136a5aeSJames Feist // you may not use this file except in compliance with the License. 6*7136a5aeSJames Feist // You may obtain a copy of the License at 7*7136a5aeSJames Feist // 8*7136a5aeSJames Feist // http://www.apache.org/licenses/LICENSE-2.0 9*7136a5aeSJames Feist // 10*7136a5aeSJames Feist // Unless required by applicable law or agreed to in writing, software 11*7136a5aeSJames Feist // distributed under the License is distributed on an "AS IS" BASIS, 12*7136a5aeSJames Feist // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*7136a5aeSJames Feist // See the License for the specific language governing permissions and 14*7136a5aeSJames Feist // limitations under the License. 15*7136a5aeSJames Feist */ 16*7136a5aeSJames Feist 17*7136a5aeSJames Feist #pragma once 18*7136a5aeSJames Feist 19*7136a5aeSJames Feist #include <string> 20*7136a5aeSJames Feist 21*7136a5aeSJames Feist #include <dbus/util.hpp> 22*7136a5aeSJames Feist #include <interfaces.hpp> 23*7136a5aeSJames Feist #include <sdbusplus/bus.hpp> 24*7136a5aeSJames Feist 25*7136a5aeSJames Feist constexpr const char *pwmInterface = "xyz.openbmc_project.Control.FanPwm"; 26*7136a5aeSJames Feist 27*7136a5aeSJames Feist class DbusWritePercent : public WriteInterface 28*7136a5aeSJames Feist { 29*7136a5aeSJames Feist public: 30*7136a5aeSJames Feist DbusWritePercent(const std::string &path, int64_t min, int64_t max, 31*7136a5aeSJames Feist DbusHelperInterface &helper) : 32*7136a5aeSJames Feist WriteInterface(min, max), 33*7136a5aeSJames Feist path(path) 34*7136a5aeSJames Feist { 35*7136a5aeSJames Feist auto tempBus = sdbusplus::bus::new_default(); 36*7136a5aeSJames Feist connectionName = helper.GetService(tempBus, pwmInterface, path); 37*7136a5aeSJames Feist } 38*7136a5aeSJames Feist 39*7136a5aeSJames Feist void write(double value) override; 40*7136a5aeSJames Feist 41*7136a5aeSJames Feist private: 42*7136a5aeSJames Feist std::string path; 43*7136a5aeSJames Feist std::string connectionName; 44*7136a5aeSJames Feist }; 45*7136a5aeSJames Feist 46*7136a5aeSJames Feist class DbusWrite : public WriteInterface 47*7136a5aeSJames Feist { 48*7136a5aeSJames Feist public: 49*7136a5aeSJames Feist DbusWrite(const std::string &path, int64_t min, int64_t max, 50*7136a5aeSJames Feist DbusHelperInterface &helper) : 51*7136a5aeSJames Feist WriteInterface(min, max), 52*7136a5aeSJames Feist path(path) 53*7136a5aeSJames Feist { 54*7136a5aeSJames Feist auto tempBus = sdbusplus::bus::new_default(); 55*7136a5aeSJames Feist connectionName = helper.GetService(tempBus, pwmInterface, path); 56*7136a5aeSJames Feist } 57*7136a5aeSJames Feist 58*7136a5aeSJames Feist void write(double value) override; 59*7136a5aeSJames Feist 60*7136a5aeSJames Feist private: 61*7136a5aeSJames Feist std::string path; 62*7136a5aeSJames Feist std::string connectionName; 63*7136a5aeSJames Feist }; 64