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