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