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