blob: 1beac27f50e4d995c25cca693ff2c76774e816da [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;
Josh Lehan2400ce42020-10-01 01:50:39 -070045 void write(double value, bool force, int64_t* written) override;
James Feist7136a5a2018-07-19 09:52:05 -070046
47 private:
48 std::string path;
49 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070050 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070051};
52
53class DbusWrite : public WriteInterface
54{
55 public:
Patrick Venturef5e770b2018-10-30 12:28:53 -070056 static std::unique_ptr<WriteInterface>
57 createDbusWrite(const std::string& path, int64_t min, int64_t max,
Patrick Venture8729eb92020-08-10 10:38:44 -070058 std::unique_ptr<DbusHelperInterface> helper);
Patrick Venturef5e770b2018-10-30 12:28:53 -070059
Patrick Venturee2ec0f62018-09-04 12:30:27 -070060 DbusWrite(const std::string& path, int64_t min, int64_t max,
Patrick Venturef5e770b2018-10-30 12:28:53 -070061 const std::string& connectionName) :
James Feist7136a5a2018-07-19 09:52:05 -070062 WriteInterface(min, max),
Patrick Venturef5e770b2018-10-30 12:28:53 -070063 path(path), connectionName(connectionName)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070064 {}
James Feist7136a5a2018-07-19 09:52:05 -070065
66 void write(double value) override;
Josh Lehan2400ce42020-10-01 01:50:39 -070067 void write(double value, bool needRedundant, int64_t* rawWritten) override;
James Feist7136a5a2018-07-19 09:52:05 -070068
69 private:
70 std::string path;
71 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070072 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070073};
Patrick Venturea0764872020-08-08 07:48:43 -070074
75} // namespace pid_control