blob: 10b24edf62e66ee60d2fd13c5c48c1ce64b41c74 [file] [log] [blame]
Tom Joseph807c7e82017-02-09 19:49:38 +05301#pragma once
2
Vernon Mauery9e801a22018-10-12 13:20:49 -07003#include "sol/sol_manager.hpp"
4
Tom Joseph807c7e82017-02-09 19:49:38 +05305#include <systemd/sd-event.h>
Vernon Mauery9e801a22018-10-12 13:20:49 -07006
Vernon Mauerycbccb052018-10-24 13:52:22 -07007#include <boost/asio/io_context.hpp>
Tom Joseph807c7e82017-02-09 19:49:38 +05308#include <chrono>
9#include <map>
10
11namespace eventloop
12{
13
Tom Joseph807c7e82017-02-09 19:49:38 +053014class EventLoop
15{
Vernon Mauery9e801a22018-10-12 13:20:49 -070016 public:
Vernon Mauerycbccb052018-10-24 13:52:22 -070017 explicit EventLoop(std::shared_ptr<boost::asio::io_context> io) : io(io)
18 {
19 }
20 EventLoop() = delete;
Vernon Mauery9e801a22018-10-12 13:20:49 -070021 ~EventLoop() = default;
22 EventLoop(const EventLoop&) = delete;
23 EventLoop& operator=(const EventLoop&) = delete;
24 EventLoop(EventLoop&&) = delete;
25 EventLoop& operator=(EventLoop&&) = delete;
Tom Joseph807c7e82017-02-09 19:49:38 +053026
Vernon Mauery9e801a22018-10-12 13:20:49 -070027 /** @brief Initialise the event loop and add the handler for incoming
28 * IPMI packets.
Vernon Mauery9e801a22018-10-12 13:20:49 -070029 *
30 * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure.
31 */
Vernon Mauerycbccb052018-10-24 13:52:22 -070032 int startEventLoop();
Tom Joseph807c7e82017-02-09 19:49:38 +053033
Vernon Mauery9e801a22018-10-12 13:20:49 -070034 /** @brief Event loop object. */
35 sd_event* event = nullptr;
Tom Joseph807c7e82017-02-09 19:49:38 +053036
Vernon Mauery9e801a22018-10-12 13:20:49 -070037 private:
Vernon Mauery7a0142c2018-11-09 08:38:16 -080038 /** @brief async handler for incoming udp packets */
39 void handleRmcpPacket();
40
41 /** @brief register the async handler for incoming udp packets */
42 void startRmcpReceive();
43
Vernon Mauerycbccb052018-10-24 13:52:22 -070044 /** @brief boost::asio io context to run with
45 */
46 std::shared_ptr<boost::asio::io_context> io;
47
Vernon Mauery7a0142c2018-11-09 08:38:16 -080048 /** @brief boost::asio udp socket
Vernon Mauery9e801a22018-10-12 13:20:49 -070049 */
Vernon Mauery7a0142c2018-11-09 08:38:16 -080050 std::shared_ptr<boost::asio::ip::udp::socket> udpSocket = nullptr;
Tom Joseph807c7e82017-02-09 19:49:38 +053051};
52
53} // namespace eventloop