1 #pragma once 2 3 #include "sol/sol_manager.hpp" 4 5 #include <systemd/sd-event.h> 6 7 #include <boost/asio/io_context.hpp> 8 #include <chrono> 9 #include <map> 10 #include <sdbusplus/asio/connection.hpp> 11 12 namespace ipmi 13 { 14 namespace rmcpp 15 { 16 constexpr uint16_t defaultPort = 623; 17 } // namespace rmcpp 18 } // namespace ipmi 19 20 namespace eventloop 21 { 22 23 class EventLoop 24 { 25 public: 26 explicit EventLoop(std::shared_ptr<boost::asio::io_context> io) : io(io) 27 { 28 } 29 EventLoop() = delete; 30 ~EventLoop() = default; 31 EventLoop(const EventLoop&) = delete; 32 EventLoop& operator=(const EventLoop&) = delete; 33 EventLoop(EventLoop&&) = delete; 34 EventLoop& operator=(EventLoop&&) = delete; 35 36 /** @brief Initialise the event loop and add the handler for incoming 37 * IPMI packets. 38 * 39 * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure. 40 */ 41 int startEventLoop(); 42 43 /** @brief Set up the socket (if systemd has not already) and 44 * make sure that the bus name matches the specified channel 45 */ 46 int setupSocket(std::shared_ptr<sdbusplus::asio::connection>& bus, 47 std::string iface, 48 uint16_t reqPort = ipmi::rmcpp::defaultPort); 49 50 private: 51 /** @brief async handler for incoming udp packets */ 52 void handleRmcpPacket(); 53 54 /** @brief register the async handler for incoming udp packets */ 55 void startRmcpReceive(); 56 57 /** @brief boost::asio io context to run with 58 */ 59 std::shared_ptr<boost::asio::io_context> io; 60 61 /** @brief boost::asio udp socket 62 */ 63 std::shared_ptr<boost::asio::ip::udp::socket> udpSocket = nullptr; 64 }; 65 66 } // namespace eventloop 67