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