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