blob: 5cc2d4991e215bf21354bd00c56bc3e2de3be8a6 [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 "interfaces.hpp"
James Feist0c8223b2019-05-08 15:33:33 -070020#include "util.hpp"
James Feist7136a5a2018-07-19 09:52:05 -070021
James Feist7136a5a2018-07-19 09:52:05 -070022#include <sdbusplus/bus.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -070023
24#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025#include <string>
James Feist7136a5a2018-07-19 09:52:05 -070026
Patrick Venturea0764872020-08-08 07:48:43 -070027namespace pid_control
28{
29
James Feist7136a5a2018-07-19 09:52:05 -070030class DbusWritePercent : public WriteInterface
31{
32 public:
Patrick Venturef5e770b2018-10-30 12:28:53 -070033 static std::unique_ptr<WriteInterface>
34 createDbusWrite(const std::string& path, int64_t min, int64_t max,
35 DbusHelperInterface& helper);
36
Patrick Venturee2ec0f62018-09-04 12:30:27 -070037 DbusWritePercent(const std::string& path, int64_t min, int64_t max,
Patrick Venturef5e770b2018-10-30 12:28:53 -070038 const std::string& connectionName) :
James Feist7136a5a2018-07-19 09:52:05 -070039 WriteInterface(min, max),
Patrick Venturef5e770b2018-10-30 12:28:53 -070040 path(path), connectionName(connectionName)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070041 {}
James Feist7136a5a2018-07-19 09:52:05 -070042
43 void write(double value) override;
44
45 private:
46 std::string path;
47 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070048 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070049};
50
51class DbusWrite : public WriteInterface
52{
53 public:
Patrick Venturef5e770b2018-10-30 12:28:53 -070054 static std::unique_ptr<WriteInterface>
55 createDbusWrite(const std::string& path, int64_t min, int64_t max,
56 DbusHelperInterface& helper);
57
Patrick Venturee2ec0f62018-09-04 12:30:27 -070058 DbusWrite(const std::string& path, int64_t min, int64_t max,
Patrick Venturef5e770b2018-10-30 12:28:53 -070059 const std::string& connectionName) :
James Feist7136a5a2018-07-19 09:52:05 -070060 WriteInterface(min, max),
Patrick Venturef5e770b2018-10-30 12:28:53 -070061 path(path), connectionName(connectionName)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070062 {}
James Feist7136a5a2018-07-19 09:52:05 -070063
64 void write(double value) override;
65
66 private:
67 std::string path;
68 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070069 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070070};
Patrick Venturea0764872020-08-08 07:48:43 -070071
72} // namespace pid_control