Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 3 | #include "sol/sol_manager.hpp" |
| 4 | |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 5 | #include <systemd/sd-event.h> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 6 | |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 7 | #include <boost/asio/io_context.hpp> |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 8 | #include <chrono> |
| 9 | #include <map> |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 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 |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 19 | |
| 20 | namespace eventloop |
| 21 | { |
| 22 | |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 23 | class EventLoop |
| 24 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 25 | public: |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 26 | explicit EventLoop(std::shared_ptr<boost::asio::io_context> io) : io(io) |
| 27 | { |
| 28 | } |
| 29 | EventLoop() = delete; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 30 | ~EventLoop() = default; |
| 31 | EventLoop(const EventLoop&) = delete; |
| 32 | EventLoop& operator=(const EventLoop&) = delete; |
| 33 | EventLoop(EventLoop&&) = delete; |
| 34 | EventLoop& operator=(EventLoop&&) = delete; |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 35 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 36 | /** @brief Initialise the event loop and add the handler for incoming |
| 37 | * IPMI packets. |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 38 | * |
| 39 | * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure. |
| 40 | */ |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 41 | int startEventLoop(); |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 42 | |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 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 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 50 | private: |
Vernon Mauery | 7a0142c | 2018-11-09 08:38:16 -0800 | [diff] [blame] | 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 | |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 57 | /** @brief boost::asio io context to run with |
| 58 | */ |
| 59 | std::shared_ptr<boost::asio::io_context> io; |
| 60 | |
Vernon Mauery | 7a0142c | 2018-11-09 08:38:16 -0800 | [diff] [blame] | 61 | /** @brief boost::asio udp socket |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 62 | */ |
Vernon Mauery | 7a0142c | 2018-11-09 08:38:16 -0800 | [diff] [blame] | 63 | std::shared_ptr<boost::asio::ip::udp::socket> udpSocket = nullptr; |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | } // namespace eventloop |