/* // 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 #include #include #include #include #include #include #include #include #include using EventPathList = boost::container::flat_map>; using GroupEventPathList = boost::container::flat_map; class PSUSubEvent : public std::enable_shared_from_this { public: PSUSubEvent(std::shared_ptr eventInterface, const std::string& path, std::shared_ptr& conn, boost::asio::io_context& io, const PowerState& powerState, const std::string& groupEventName, const std::string& eventName, std::shared_ptr> asserts, std::shared_ptr> combineEvent, std::shared_ptr state, const std::string& psuName, double pollRate); ~PSUSubEvent(); std::shared_ptr eventInterface; std::shared_ptr> asserts; std::shared_ptr> combineEvent; std::shared_ptr 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> 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 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& 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 eventInterface; boost::container::flat_map>> events; std::vector>> asserts; std::vector> states; };