blob: 54b29465a61aee08301b8c334f2e824f7b049e18 [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>
Vernon Maueryd92bc322019-03-15 15:24:30 -070010#include <sdbusplus/asio/connection.hpp>
11
12namespace ipmi
13{
14namespace rmcpp
15{
16constexpr uint16_t defaultPort = 623;
17} // namespace rmcpp
18} // namespace ipmi
Tom Joseph807c7e82017-02-09 19:49:38 +053019
20namespace eventloop
21{
22
Tom Joseph807c7e82017-02-09 19:49:38 +053023class EventLoop
24{
Vernon Mauery9e801a22018-10-12 13:20:49 -070025 public:
Vernon Mauerycbccb052018-10-24 13:52:22 -070026 explicit EventLoop(std::shared_ptr<boost::asio::io_context> io) : io(io)
27 {
28 }
29 EventLoop() = delete;
Vernon Mauery9e801a22018-10-12 13:20:49 -070030 ~EventLoop() = default;
31 EventLoop(const EventLoop&) = delete;
32 EventLoop& operator=(const EventLoop&) = delete;
33 EventLoop(EventLoop&&) = delete;
34 EventLoop& operator=(EventLoop&&) = delete;
Tom Joseph807c7e82017-02-09 19:49:38 +053035
Vernon Mauery9e801a22018-10-12 13:20:49 -070036 /** @brief Initialise the event loop and add the handler for incoming
37 * IPMI packets.
Vernon Mauery9e801a22018-10-12 13:20:49 -070038 *
39 * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure.
40 */
Vernon Mauerycbccb052018-10-24 13:52:22 -070041 int startEventLoop();
Tom Joseph807c7e82017-02-09 19:49:38 +053042
Vernon Maueryd92bc322019-03-15 15:24:30 -070043 /** @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 Mauery9e801a22018-10-12 13:20:49 -070050 private:
Vernon Mauery7a0142c2018-11-09 08:38:16 -080051 /** @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 Mauerycbccb052018-10-24 13:52:22 -070057 /** @brief boost::asio io context to run with
58 */
59 std::shared_ptr<boost::asio::io_context> io;
60
Vernon Mauery7a0142c2018-11-09 08:38:16 -080061 /** @brief boost::asio udp socket
Vernon Mauery9e801a22018-10-12 13:20:49 -070062 */
Vernon Mauery7a0142c2018-11-09 08:38:16 -080063 std::shared_ptr<boost::asio::ip::udp::socket> udpSocket = nullptr;
Tom Joseph807c7e82017-02-09 19:49:38 +053064};
65
66} // namespace eventloop