xref: /openbmc/slpd-lite/slp_server.hpp (revision 1a6b1c2b67e2277acbae2799cff92d0037bf4401)
1 #pragma once
2 
3 #include "slp.hpp"
4 #include "slp_meta.hpp"
5 
6 #include <sys/types.h>
7 #include <systemd/sd-bus.h>
8 #include <systemd/sd-daemon.h>
9 #include <systemd/sd-event.h>
10 
11 #include <iostream>
12 #include <string>
13 
14 namespace slp
15 {
16 
17 namespace udp
18 {
19 /** General udp server which waits for the POLLIN event
20     on the port and calls the call back once it gets the event.
21     usage would be create the server with the port and the call back
22     and call the run method.
23  */
24 class Server
25 {
26   public:
Server()27     Server() : Server(slp::PORT, nullptr) {};
28 
Server(uint16_t port,sd_event_io_handler_t cb)29     Server(uint16_t port, sd_event_io_handler_t cb) : port(port), callme(cb) {};
30 
31     Server(const Server&) = delete;
32     Server& operator=(const Server&) = delete;
33     Server(Server&&) = default;
34     Server& operator=(Server&&) = default;
35 
36     uint16_t port;
37     sd_event_io_handler_t callme;
38 
39     int run();
40 };
41 } // namespace udp
42 } // namespace slp
43