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 | |
James Feist | 8086aba | 2020-08-25 16:00:59 -0700 | [diff] [blame] | 19 | #include <boost/asio/deadline_timer.hpp> |
| 20 | #include <boost/asio/io_service.hpp> |
| 21 | #include <boost/asio/streambuf.hpp> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 22 | #include <boost/container/flat_map.hpp> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 23 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 24 | |
| 25 | #include <memory> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 26 | #include <set> |
| 27 | #include <string> |
| 28 | #include <vector> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 29 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 30 | class PSUSubEvent : public std::enable_shared_from_this<PSUSubEvent> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 31 | { |
| 32 | public: |
| 33 | PSUSubEvent(std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface, |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 34 | const std::string& path, |
| 35 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 36 | boost::asio::io_service& io, const std::string& groupEventName, |
| 37 | const std::string& eventName, |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 38 | std::shared_ptr<std::set<std::string>> asserts, |
| 39 | std::shared_ptr<std::set<std::string>> combineEvent, |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 40 | std::shared_ptr<bool> state, const std::string& psuName); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 41 | ~PSUSubEvent(); |
| 42 | |
| 43 | std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface; |
| 44 | std::shared_ptr<std::set<std::string>> asserts; |
| 45 | std::shared_ptr<std::set<std::string>> combineEvent; |
| 46 | std::shared_ptr<bool> assertState; |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 47 | void setupRead(void); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | int value = 0; |
Cheng C Yang | a97f134 | 2020-02-11 15:10:41 +0800 | [diff] [blame] | 51 | int fd; |
Brad Bishop | fbb44ad | 2019-11-08 09:42:37 -0500 | [diff] [blame] | 52 | size_t errCount; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 53 | std::string path; |
| 54 | std::string eventName; |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 55 | std::string groupEventName; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 56 | boost::asio::deadline_timer waitTimer; |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 57 | std::shared_ptr<boost::asio::streambuf> readBuf; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 58 | void handleResponse(const boost::system::error_code& err); |
| 59 | void updateValue(const int& newValue); |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 60 | void beep(const uint8_t& beepPriority); |
| 61 | static constexpr uint8_t beepPSUFailure = 2; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 62 | boost::asio::posix::stream_descriptor inputDev; |
| 63 | static constexpr unsigned int eventPollMs = 1000; |
| 64 | static constexpr size_t warnAfterErrorCount = 10; |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 65 | std::string psuName; |
| 66 | std::string fanName; |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 67 | std::string assertMessage; |
| 68 | std::string deassertMessage; |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 69 | std::shared_ptr<sdbusplus::asio::connection> systemBus; |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | class PSUCombineEvent |
| 73 | { |
| 74 | public: |
| 75 | PSUCombineEvent( |
| 76 | sdbusplus::asio::object_server& objectSever, |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 77 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 78 | boost::asio::io_service& io, const std::string& psuName, |
| 79 | boost::container::flat_map<std::string, std::vector<std::string>>& |
| 80 | eventPathList, |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 81 | boost::container::flat_map< |
| 82 | std::string, |
| 83 | boost::container::flat_map<std::string, std::vector<std::string>>>& |
| 84 | groupEventPathList, |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 85 | const std::string& combineEventName); |
| 86 | ~PSUCombineEvent(); |
| 87 | |
| 88 | sdbusplus::asio::object_server& objServer; |
| 89 | std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface; |
| 90 | boost::container::flat_map<std::string, |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 91 | std::vector<std::shared_ptr<PSUSubEvent>>> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 92 | events; |
| 93 | std::vector<std::shared_ptr<std::set<std::string>>> asserts; |
| 94 | std::vector<std::shared_ptr<bool>> states; |
| 95 | }; |