Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 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 | |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 19 | #include "Utils.hpp" |
| 20 | |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 21 | #include <boost/asio/io_context.hpp> |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 22 | #include <boost/asio/random_access_file.hpp> |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 23 | #include <boost/asio/steady_timer.hpp> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 24 | #include <boost/container/flat_map.hpp> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 25 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 26 | |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 27 | #include <array> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 28 | #include <memory> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 29 | #include <set> |
| 30 | #include <string> |
| 31 | #include <vector> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 32 | |
George Liu | 5b3542e | 2023-10-31 17:27:12 +0800 | [diff] [blame^] | 33 | using EventPathList = |
| 34 | boost::container::flat_map<std::string, std::vector<std::string>>; |
| 35 | using GroupEventPathList = |
| 36 | boost::container::flat_map<std::string, EventPathList>; |
| 37 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 38 | class PSUSubEvent : public std::enable_shared_from_this<PSUSubEvent> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 39 | { |
| 40 | public: |
| 41 | PSUSubEvent(std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface, |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 42 | const std::string& path, |
| 43 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 44 | boost::asio::io_context& io, const PowerState& powerState, |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 45 | const std::string& groupEventName, const std::string& eventName, |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 46 | std::shared_ptr<std::set<std::string>> asserts, |
| 47 | std::shared_ptr<std::set<std::string>> combineEvent, |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 48 | std::shared_ptr<bool> state, const std::string& psuName, |
| 49 | double pollRate); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 50 | ~PSUSubEvent(); |
| 51 | |
| 52 | std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface; |
| 53 | std::shared_ptr<std::set<std::string>> asserts; |
| 54 | std::shared_ptr<std::set<std::string>> combineEvent; |
| 55 | std::shared_ptr<bool> assertState; |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 56 | void setupRead(void); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | int value = 0; |
Ed Tanous | b429f31 | 2022-06-27 16:09:53 -0700 | [diff] [blame] | 60 | size_t errCount{0}; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 61 | std::string path; |
| 62 | std::string eventName; |
Brad Bishop | feb19ef | 2019-11-07 18:02:16 -0500 | [diff] [blame] | 63 | |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 64 | PowerState readState; |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 65 | boost::asio::steady_timer waitTimer; |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 66 | std::shared_ptr<std::array<char, 128>> buffer; |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 67 | void restartRead(); |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 68 | void handleResponse(const boost::system::error_code& err, |
| 69 | size_t bytesTransferred); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 70 | void updateValue(const int& newValue); |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 71 | boost::asio::random_access_file inputDev; |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 72 | std::string psuName; |
Brad Bishop | feb19ef | 2019-11-07 18:02:16 -0500 | [diff] [blame] | 73 | std::string groupEventName; |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 74 | std::string fanName; |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 75 | std::string assertMessage; |
| 76 | std::string deassertMessage; |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 77 | std::shared_ptr<sdbusplus::asio::connection> systemBus; |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 78 | unsigned int eventPollMs = defaultEventPollMs; |
| 79 | static constexpr unsigned int defaultEventPollMs = 1000; |
| 80 | static constexpr size_t warnAfterErrorCount = 10; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | class PSUCombineEvent |
| 84 | { |
| 85 | public: |
George Liu | 5b3542e | 2023-10-31 17:27:12 +0800 | [diff] [blame^] | 86 | PSUCombineEvent(sdbusplus::asio::object_server& objectServer, |
| 87 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 88 | boost::asio::io_context& io, const std::string& psuName, |
| 89 | const PowerState& powerState, EventPathList& eventPathList, |
| 90 | GroupEventPathList& groupEventPathList, |
| 91 | const std::string& combineEventName, double pollRate); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 92 | ~PSUCombineEvent(); |
| 93 | |
| 94 | sdbusplus::asio::object_server& objServer; |
| 95 | std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface; |
| 96 | boost::container::flat_map<std::string, |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 97 | std::vector<std::shared_ptr<PSUSubEvent>>> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 98 | events; |
| 99 | std::vector<std::shared_ptr<std::set<std::string>>> asserts; |
| 100 | std::vector<std::shared_ptr<bool>> states; |
| 101 | }; |