blob: bf49856769f9b0abe7a07931afbdacb0e3a4c08a [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 Feist7136a5a2018-07-19 09:52:05 -070021
Ed Tanousf8b6e552025-06-27 13:27:50 -070022#include <cstdint>
Patrick Venturea83a3ec2020-08-04 09:52:05 -070023#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070024#include <string>
James Feist7136a5a2018-07-19 09:52:05 -070025
Patrick Venturea0764872020-08-08 07:48:43 -070026namespace pid_control
27{
28
James Feist7136a5a2018-07-19 09:52:05 -070029class DbusWritePercent : public WriteInterface
30{
31 public:
Patrick Williams19300272025-02-01 08:22:48 -050032 static std::unique_ptr<WriteInterface> createDbusWrite(
33 const std::string& path, int64_t min, int64_t max,
34 std::unique_ptr<DbusHelperInterface> helper);
Patrick Venturef5e770b2018-10-30 12:28:53 -070035
Patrick Venturee2ec0f62018-09-04 12:30:27 -070036 DbusWritePercent(const std::string& path, int64_t min, int64_t max,
Patrick Venturef5e770b2018-10-30 12:28:53 -070037 const std::string& connectionName) :
Patrick Williamsbd63bca2024-08-16 15:21:10 -040038 WriteInterface(min, max), path(path), connectionName(connectionName)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070039 {}
James Feist7136a5a2018-07-19 09:52:05 -070040
41 void write(double value) override;
Josh Lehan2400ce42020-10-01 01:50:39 -070042 void write(double value, bool force, int64_t* written) override;
James Feist7136a5a2018-07-19 09:52:05 -070043
44 private:
45 std::string path;
46 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070047 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070048};
49
50class DbusWrite : public WriteInterface
51{
52 public:
Patrick Williams19300272025-02-01 08:22:48 -050053 static std::unique_ptr<WriteInterface> createDbusWrite(
54 const std::string& path, int64_t min, int64_t max,
55 std::unique_ptr<DbusHelperInterface> helper);
Patrick Venturef5e770b2018-10-30 12:28:53 -070056
Patrick Venturee2ec0f62018-09-04 12:30:27 -070057 DbusWrite(const std::string& path, int64_t min, int64_t max,
Patrick Venturef5e770b2018-10-30 12:28:53 -070058 const std::string& connectionName) :
Patrick Williamsbd63bca2024-08-16 15:21:10 -040059 WriteInterface(min, max), path(path), connectionName(connectionName)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070060 {}
James Feist7136a5a2018-07-19 09:52:05 -070061
62 void write(double value) override;
Josh Lehan2400ce42020-10-01 01:50:39 -070063 void write(double value, bool needRedundant, int64_t* rawWritten) override;
James Feist7136a5a2018-07-19 09:52:05 -070064
65 private:
66 std::string path;
67 std::string connectionName;
James Feistcd9e1092018-10-08 13:06:41 -070068 int64_t oldValue = -1;
James Feist7136a5a2018-07-19 09:52:05 -070069};
Patrick Venturea0764872020-08-08 07:48:43 -070070
71} // namespace pid_control