| /* |
| // Copyright (c) 2019 Intel Corporation |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| */ |
| |
| #pragma once |
| |
| #include "Utils.hpp" |
| |
| #include <boost/asio/io_context.hpp> |
| #include <boost/asio/random_access_file.hpp> |
| #include <boost/asio/steady_timer.hpp> |
| #include <boost/container/flat_map.hpp> |
| #include <sdbusplus/asio/object_server.hpp> |
| |
| #include <array> |
| #include <memory> |
| #include <set> |
| #include <string> |
| #include <vector> |
| |
| using EventPathList = |
| boost::container::flat_map<std::string, std::vector<std::string>>; |
| using GroupEventPathList = |
| boost::container::flat_map<std::string, EventPathList>; |
| |
| class PSUSubEvent : public std::enable_shared_from_this<PSUSubEvent> |
| { |
| public: |
| PSUSubEvent(std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface, |
| const std::string& path, |
| std::shared_ptr<sdbusplus::asio::connection>& conn, |
| boost::asio::io_context& io, const PowerState& powerState, |
| const std::string& groupEventName, const std::string& eventName, |
| std::shared_ptr<std::set<std::string>> asserts, |
| std::shared_ptr<std::set<std::string>> combineEvent, |
| std::shared_ptr<bool> state, const std::string& psuName, |
| double pollRate); |
| ~PSUSubEvent(); |
| |
| std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface; |
| std::shared_ptr<std::set<std::string>> asserts; |
| std::shared_ptr<std::set<std::string>> combineEvent; |
| std::shared_ptr<bool> assertState; |
| void setupRead(); |
| |
| private: |
| int value = 0; |
| size_t errCount{0}; |
| std::string path; |
| std::string eventName; |
| |
| PowerState readState; |
| boost::asio::steady_timer waitTimer; |
| std::shared_ptr<std::array<char, 128>> buffer; |
| void restartRead(); |
| void handleResponse(const boost::system::error_code& err, |
| size_t bytesTransferred); |
| void updateValue(const int& newValue); |
| boost::asio::random_access_file inputDev; |
| std::string psuName; |
| std::string groupEventName; |
| std::string fanName; |
| std::string assertMessage; |
| std::string deassertMessage; |
| std::shared_ptr<sdbusplus::asio::connection> systemBus; |
| unsigned int eventPollMs = defaultEventPollMs; |
| static constexpr unsigned int defaultEventPollMs = 1000; |
| static constexpr size_t warnAfterErrorCount = 10; |
| }; |
| |
| class PSUCombineEvent |
| { |
| public: |
| PSUCombineEvent(sdbusplus::asio::object_server& objectServer, |
| std::shared_ptr<sdbusplus::asio::connection>& conn, |
| boost::asio::io_context& io, const std::string& psuName, |
| const PowerState& powerState, EventPathList& eventPathList, |
| GroupEventPathList& groupEventPathList, |
| const std::string& combineEventName, double pollRate); |
| ~PSUCombineEvent(); |
| |
| sdbusplus::asio::object_server& objServer; |
| std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface; |
| boost::container::flat_map<std::string, |
| std::vector<std::shared_ptr<PSUSubEvent>>> |
| events; |
| std::vector<std::shared_ptr<std::set<std::string>>> asserts; |
| std::vector<std::shared_ptr<bool>> states; |
| }; |