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> |
| 10 | |
| 11 | namespace eventloop |
| 12 | { |
| 13 | |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 14 | class EventLoop |
| 15 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 16 | public: |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 17 | explicit EventLoop(std::shared_ptr<boost::asio::io_context> io) : io(io) |
| 18 | { |
| 19 | } |
| 20 | EventLoop() = delete; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 21 | ~EventLoop() = default; |
| 22 | EventLoop(const EventLoop&) = delete; |
| 23 | EventLoop& operator=(const EventLoop&) = delete; |
| 24 | EventLoop(EventLoop&&) = delete; |
| 25 | EventLoop& operator=(EventLoop&&) = delete; |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 26 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 27 | /** @brief Initialise the event loop and add the handler for incoming |
| 28 | * IPMI packets. |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 29 | * |
| 30 | * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure. |
| 31 | */ |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 32 | int startEventLoop(); |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 33 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 34 | private: |
Vernon Mauery | 7a0142c | 2018-11-09 08:38:16 -0800 | [diff] [blame] | 35 | /** @brief async handler for incoming udp packets */ |
| 36 | void handleRmcpPacket(); |
| 37 | |
| 38 | /** @brief register the async handler for incoming udp packets */ |
| 39 | void startRmcpReceive(); |
| 40 | |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 41 | /** @brief boost::asio io context to run with |
| 42 | */ |
| 43 | std::shared_ptr<boost::asio::io_context> io; |
| 44 | |
Vernon Mauery | 7a0142c | 2018-11-09 08:38:16 -0800 | [diff] [blame] | 45 | /** @brief boost::asio udp socket |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 46 | */ |
Vernon Mauery | 7a0142c | 2018-11-09 08:38:16 -0800 | [diff] [blame] | 47 | std::shared_ptr<boost::asio::ip::udp::socket> udpSocket = nullptr; |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | } // namespace eventloop |