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 public: Server()27309ac445SRatan Gupta Server() : Server(slp::PORT, nullptr){}; 28309ac445SRatan Gupta Server(uint16_t port,sd_event_io_handler_t cb)29*537ff140SPatrick Venture Server(uint16_t port, sd_event_io_handler_t cb) : port(port), callme(cb){}; 30309ac445SRatan Gupta 31309ac445SRatan Gupta Server(const Server&) = delete; 32309ac445SRatan Gupta Server& operator=(const Server&) = delete; 33309ac445SRatan Gupta Server(Server&&) = default; 34309ac445SRatan Gupta Server& operator=(Server&&) = default; 35309ac445SRatan Gupta 36309ac445SRatan Gupta uint16_t port; 37309ac445SRatan Gupta sd_event_io_handler_t callme; 38309ac445SRatan Gupta 39309ac445SRatan Gupta int run(); 40309ac445SRatan Gupta }; 41*537ff140SPatrick Venture } // namespace udp 42309ac445SRatan Gupta } // namespace slp 43