Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame] | 3 | #include "slp.hpp" |
| 4 | #include "slp_meta.hpp" |
| 5 | |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 6 | #include <sys/types.h> |
| 7 | #include <systemd/sd-bus.h> |
| 8 | #include <systemd/sd-daemon.h> |
| 9 | #include <systemd/sd-event.h> |
| 10 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame] | 11 | #include <iostream> |
| 12 | #include <string> |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 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 | { |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame] | 26 | public: |
| 27 | Server() : Server(slp::PORT, nullptr){}; |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 28 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame] | 29 | Server(uint16_t port, sd_event_io_handler_t cb) : port(port), callme(cb){}; |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 30 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame] | 31 | Server(const Server&) = delete; |
| 32 | Server& operator=(const Server&) = delete; |
| 33 | Server(Server&&) = default; |
| 34 | Server& operator=(Server&&) = default; |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 35 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame] | 36 | uint16_t port; |
| 37 | sd_event_io_handler_t callme; |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 38 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame] | 39 | int run(); |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 40 | }; |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame] | 41 | } // namespace udp |
| 42 | } // namespace slp |