blob: 49e32ea77e153f17bd00a1430c27f8a11ff52a6b [file] [log] [blame]
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +05301#pragma once
William A. Kennington III217bb3f2022-09-29 13:43:13 -07002#include <sdeventplus/event.hpp>
3#include <sdeventplus/source/io.hpp>
William A. Kennington III32eef712022-01-24 17:03:03 -08004#include <stdplus/fd/managed.hpp>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +05305
6namespace phosphor
7{
8namespace network
9{
William A. Kennington III71590bf2022-10-31 14:14:16 -070010class Manager;
William A. Kennington III5f165dc2022-10-24 15:58:55 -070011namespace netlink
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053012{
13
14constexpr auto BUFSIZE = 4096;
15
16/** General rtnetlink server which waits for the POLLIN event
17 and calls the call back once it gets the event.
18 Usage would be create the server with the call back
19 and call the run method.
20 */
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053021class Server
22{
23
Gunnar Mills57d9c502018-09-14 14:42:34 -050024 public:
25 /** @brief Constructor
26 *
27 * @details Sets up the server to handle incoming RTNETLINK events
28 *
29 * @param[in] eventPtr - Unique ptr reference to sd_event.
William A. Kennington III71590bf2022-10-31 14:14:16 -070030 * @param[in] manager - The network manager that receives updates
Gunnar Mills57d9c502018-09-14 14:42:34 -050031 */
William A. Kennington III71590bf2022-10-31 14:14:16 -070032 Server(sdeventplus::Event& event, Manager& manager);
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053033
William A. Kennington III32eef712022-01-24 17:03:03 -080034 /** @brief Gets the socket associated with this netlink server */
35 inline stdplus::Fd& getSock()
36 {
37 return sock;
38 }
39
40 private:
41 stdplus::ManagedFd sock;
William A. Kennington III217bb3f2022-09-29 13:43:13 -070042 sdeventplus::source::IO io;
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053043};
44
William A. Kennington III5f165dc2022-10-24 15:58:55 -070045} // namespace netlink
Gunnar Mills57d9c502018-09-14 14:42:34 -050046} // namespace network
47} // namespace phosphor