blob: f890781eb96b3091badae73fcfcdc6db789daabf [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 Ventureaadb30d2020-08-10 09:17:11 -070019#include "dbushelper_interface.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070020#include "interfaces.hpp"
James Feist0c8223b2019-05-08 15:33:33 -070021#include "util.hpp"
James Feist7136a5a2018-07-19 09:52:05 -070022
James Feist7136a5a2018-07-19 09:52:05 -070023#include <sdbusplus/bus.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -070024
25#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070026#include <string>
James Feist7136a5a2018-07-19 09:52:05 -070027
Patrick Venturea0764872020-08-08 07:48:43 -070028namespace pid_control
29{
30
James Feist7136a5a2018-07-19 09:52:05 -070031class DbusWritePercent : public WriteInterface
32{
33 public:
Patrick Venturef5e770b2018-10-30 12:28:53 -070034 static std::unique_ptr<WriteInterface>
35 createDbusWrite(const std::string& path, int64_t min, int64_t max,
Patrick Venture8729eb92020-08-10 10:38:44 -070036 std::unique_ptr<DbusHelperInterface> helper);
Patrick Venturef5e770b2018-10-30 12:28:53 -070037
Patrick Venturee2ec0f62018-09-04 12:30:27 -070038 DbusWritePercent(const std::string& path, int64_t min, int64_t max,
Patrick Venturef5e770b2018-10-30 12:28:53 -070039 const std::string& connectionName) :
James Feist7136a5a2018-07-19 09:52:05 -070040 WriteInterface(min, max),
Patrick Venturef5e770b2018-10-30 12:28:53 -070041 path(path), connectionName(connectionName)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070042 {}
James Feist7136a5a2018-07-19 09:52:05 -070043
44 void write(double value) override;
45
46 private:
47 std::string path;
48 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070049 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070050};
51
52class DbusWrite : public WriteInterface
53{
54 public:
Patrick Venturef5e770b2018-10-30 12:28:53 -070055 static std::unique_ptr<WriteInterface>
56 createDbusWrite(const std::string& path, int64_t min, int64_t max,
Patrick Venture8729eb92020-08-10 10:38:44 -070057 std::unique_ptr<DbusHelperInterface> helper);
Patrick Venturef5e770b2018-10-30 12:28:53 -070058
Patrick Venturee2ec0f62018-09-04 12:30:27 -070059 DbusWrite(const std::string& path, int64_t min, int64_t max,
Patrick Venturef5e770b2018-10-30 12:28:53 -070060 const std::string& connectionName) :
James Feist7136a5a2018-07-19 09:52:05 -070061 WriteInterface(min, max),
Patrick Venturef5e770b2018-10-30 12:28:53 -070062 path(path), connectionName(connectionName)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070063 {}
James Feist7136a5a2018-07-19 09:52:05 -070064
65 void write(double value) override;
66
67 private:
68 std::string path;
69 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070070 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070071};
Patrick Venturea0764872020-08-08 07:48:43 -070072
73} // namespace pid_control