blob: 577013d207d0c974864da361dc1d7297b43e9401 [file] [log] [blame]
James Feist7136a5a2018-07-19 09:52:05 -07001/*
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 Ventureda4a5dd2018-08-31 09:42:48 -070019#include "dbus/util.hpp"
20#include "interfaces.hpp"
James Feist7136a5a2018-07-19 09:52:05 -070021
James Feist7136a5a2018-07-19 09:52:05 -070022#include <sdbusplus/bus.hpp>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070023#include <string>
James Feist7136a5a2018-07-19 09:52:05 -070024
Patrick Venturee2ec0f62018-09-04 12:30:27 -070025constexpr const char* pwmInterface = "xyz.openbmc_project.Control.FanPwm";
James Feist7136a5a2018-07-19 09:52:05 -070026
27class DbusWritePercent : public WriteInterface
28{
29 public:
Patrick Venturee2ec0f62018-09-04 12:30:27 -070030 DbusWritePercent(const std::string& path, int64_t min, int64_t max,
31 DbusHelperInterface& helper) :
James Feist7136a5a2018-07-19 09:52:05 -070032 WriteInterface(min, max),
33 path(path)
34 {
35 auto tempBus = sdbusplus::bus::new_default();
Patrick Venture34ddc902018-10-30 11:05:17 -070036 // getService can except, does it make more sense to use a factory?
Patrick Venture563a3562018-10-30 09:31:26 -070037 connectionName = helper.getService(tempBus, pwmInterface, path);
James Feist7136a5a2018-07-19 09:52:05 -070038 }
39
40 void write(double value) override;
41
42 private:
43 std::string path;
44 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070045 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070046};
47
48class DbusWrite : public WriteInterface
49{
50 public:
Patrick Venturee2ec0f62018-09-04 12:30:27 -070051 DbusWrite(const std::string& path, int64_t min, int64_t max,
52 DbusHelperInterface& helper) :
James Feist7136a5a2018-07-19 09:52:05 -070053 WriteInterface(min, max),
54 path(path)
55 {
56 auto tempBus = sdbusplus::bus::new_default();
Patrick Venture34ddc902018-10-30 11:05:17 -070057 // getService can except, does it make more sense to use a factory?
Patrick Venture563a3562018-10-30 09:31:26 -070058 connectionName = helper.getService(tempBus, pwmInterface, path);
James Feist7136a5a2018-07-19 09:52:05 -070059 }
60
61 void write(double value) override;
62
63 private:
64 std::string path;
65 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070066 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070067};