xref: /openbmc/slpd-lite/slp_server.hpp (revision 537ff140)
1309ac445SRatan Gupta #pragma once
2309ac445SRatan Gupta 
3*537ff140SPatrick Venture #include "slp.hpp"
4*537ff140SPatrick Venture #include "slp_meta.hpp"
5*537ff140SPatrick Venture 
6309ac445SRatan Gupta #include <sys/types.h>
7309ac445SRatan Gupta #include <systemd/sd-bus.h>
8309ac445SRatan Gupta #include <systemd/sd-daemon.h>
9309ac445SRatan Gupta #include <systemd/sd-event.h>
10309ac445SRatan Gupta 
11*537ff140SPatrick Venture #include <iostream>
12*537ff140SPatrick Venture #include <string>
13309ac445SRatan Gupta 
14309ac445SRatan Gupta namespace slp
15309ac445SRatan Gupta {
16309ac445SRatan Gupta 
17309ac445SRatan Gupta namespace udp
18309ac445SRatan Gupta {
19309ac445SRatan Gupta /** General udp server which waits for the POLLIN event
20309ac445SRatan Gupta     on the port and calls the call back once it gets the event.
21309ac445SRatan Gupta     usage would be create the server with the port and the call back
22309ac445SRatan Gupta     and call the run method.
23309ac445SRatan Gupta  */
24309ac445SRatan Gupta class Server
25309ac445SRatan Gupta {
26309ac445SRatan Gupta 
27309ac445SRatan Gupta   public:
28309ac445SRatan Gupta     Server() : Server(slp::PORT, nullptr){};
29309ac445SRatan Gupta 
30*537ff140SPatrick Venture     Server(uint16_t port, sd_event_io_handler_t cb) : port(port), callme(cb){};
31309ac445SRatan Gupta 
32309ac445SRatan Gupta     Server(const Server&) = delete;
33309ac445SRatan Gupta     Server& operator=(const Server&) = delete;
34309ac445SRatan Gupta     Server(Server&&) = default;
35309ac445SRatan Gupta     Server& operator=(Server&&) = default;
36309ac445SRatan Gupta 
37309ac445SRatan Gupta     uint16_t port;
38309ac445SRatan Gupta     sd_event_io_handler_t callme;
39309ac445SRatan Gupta 
40309ac445SRatan Gupta     int run();
41309ac445SRatan Gupta };
42*537ff140SPatrick Venture } // namespace udp
43309ac445SRatan Gupta } // namespace slp
44