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 | { |
| 26 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame^] | 27 | public: |
| 28 | Server() : Server(slp::PORT, nullptr){}; |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 29 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame^] | 30 | 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] | 31 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame^] | 32 | Server(const Server&) = delete; |
| 33 | Server& operator=(const Server&) = delete; |
| 34 | Server(Server&&) = default; |
| 35 | Server& operator=(Server&&) = default; |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 36 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame^] | 37 | uint16_t port; |
| 38 | sd_event_io_handler_t callme; |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 39 | |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame^] | 40 | int run(); |
Ratan Gupta | 309ac44 | 2016-12-13 20:40:06 +0530 | [diff] [blame] | 41 | }; |
Patrick Venture | 537ff14 | 2018-11-01 16:37:09 -0700 | [diff] [blame^] | 42 | } // namespace udp |
| 43 | } // namespace slp |