James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 1 | /* |
| 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 Venture | aadb30d | 2020-08-10 09:17:11 -0700 | [diff] [blame] | 19 | #include "dbushelper_interface.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 20 | #include "interfaces.hpp" |
James Feist | 0c8223b | 2019-05-08 15:33:33 -0700 | [diff] [blame] | 21 | #include "util.hpp" |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 22 | |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 23 | #include <sdbusplus/bus.hpp> |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 24 | |
| 25 | #include <memory> |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 26 | #include <string> |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 27 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 28 | namespace pid_control |
| 29 | { |
| 30 | |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 31 | class DbusWritePercent : public WriteInterface |
| 32 | { |
| 33 | public: |
Patrick Venture | f5e770b | 2018-10-30 12:28:53 -0700 | [diff] [blame] | 34 | static std::unique_ptr<WriteInterface> |
| 35 | createDbusWrite(const std::string& path, int64_t min, int64_t max, |
Patrick Venture | 8729eb9 | 2020-08-10 10:38:44 -0700 | [diff] [blame] | 36 | std::unique_ptr<DbusHelperInterface> helper); |
Patrick Venture | f5e770b | 2018-10-30 12:28:53 -0700 | [diff] [blame] | 37 | |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 38 | DbusWritePercent(const std::string& path, int64_t min, int64_t max, |
Patrick Venture | f5e770b | 2018-10-30 12:28:53 -0700 | [diff] [blame] | 39 | const std::string& connectionName) : |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 40 | WriteInterface(min, max), |
Patrick Venture | f5e770b | 2018-10-30 12:28:53 -0700 | [diff] [blame] | 41 | path(path), connectionName(connectionName) |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 42 | {} |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 43 | |
| 44 | void write(double value) override; |
Josh Lehan | 2400ce4 | 2020-10-01 01:50:39 -0700 | [diff] [blame] | 45 | void write(double value, bool force, int64_t* written) override; |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | std::string path; |
| 49 | std::string connectionName; |
James Feist | cd9e109 | 2018-10-08 13:06:41 -0700 | [diff] [blame] | 50 | int64_t oldValue = -1; |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | class DbusWrite : public WriteInterface |
| 54 | { |
| 55 | public: |
Patrick Venture | f5e770b | 2018-10-30 12:28:53 -0700 | [diff] [blame] | 56 | static std::unique_ptr<WriteInterface> |
| 57 | createDbusWrite(const std::string& path, int64_t min, int64_t max, |
Patrick Venture | 8729eb9 | 2020-08-10 10:38:44 -0700 | [diff] [blame] | 58 | std::unique_ptr<DbusHelperInterface> helper); |
Patrick Venture | f5e770b | 2018-10-30 12:28:53 -0700 | [diff] [blame] | 59 | |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 60 | DbusWrite(const std::string& path, int64_t min, int64_t max, |
Patrick Venture | f5e770b | 2018-10-30 12:28:53 -0700 | [diff] [blame] | 61 | const std::string& connectionName) : |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 62 | WriteInterface(min, max), |
Patrick Venture | f5e770b | 2018-10-30 12:28:53 -0700 | [diff] [blame] | 63 | path(path), connectionName(connectionName) |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 64 | {} |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 65 | |
| 66 | void write(double value) override; |
Josh Lehan | 2400ce4 | 2020-10-01 01:50:39 -0700 | [diff] [blame] | 67 | void write(double value, bool needRedundant, int64_t* rawWritten) override; |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 68 | |
| 69 | private: |
| 70 | std::string path; |
| 71 | std::string connectionName; |
James Feist | cd9e109 | 2018-10-08 13:06:41 -0700 | [diff] [blame] | 72 | int64_t oldValue = -1; |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 73 | }; |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 74 | |
| 75 | } // namespace pid_control |