blob: c890ced9d144c058d06e021adcff9cdf4263bf29 [file] [log] [blame]
Ratan Gupta309ac442016-12-13 20:40:06 +05301#pragma once
2
Patrick Venture537ff142018-11-01 16:37:09 -07003#include "slp.hpp"
4#include "slp_meta.hpp"
5
Ratan Gupta309ac442016-12-13 20:40:06 +05306#include <sys/types.h>
7#include <systemd/sd-bus.h>
8#include <systemd/sd-daemon.h>
9#include <systemd/sd-event.h>
10
Patrick Venture537ff142018-11-01 16:37:09 -070011#include <iostream>
12#include <string>
Ratan Gupta309ac442016-12-13 20:40:06 +053013
14namespace slp
15{
16
17namespace 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 */
24class Server
25{
26
Patrick Venture537ff142018-11-01 16:37:09 -070027 public:
28 Server() : Server(slp::PORT, nullptr){};
Ratan Gupta309ac442016-12-13 20:40:06 +053029
Patrick Venture537ff142018-11-01 16:37:09 -070030 Server(uint16_t port, sd_event_io_handler_t cb) : port(port), callme(cb){};
Ratan Gupta309ac442016-12-13 20:40:06 +053031
Patrick Venture537ff142018-11-01 16:37:09 -070032 Server(const Server&) = delete;
33 Server& operator=(const Server&) = delete;
34 Server(Server&&) = default;
35 Server& operator=(Server&&) = default;
Ratan Gupta309ac442016-12-13 20:40:06 +053036
Patrick Venture537ff142018-11-01 16:37:09 -070037 uint16_t port;
38 sd_event_io_handler_t callme;
Ratan Gupta309ac442016-12-13 20:40:06 +053039
Patrick Venture537ff142018-11-01 16:37:09 -070040 int run();
Ratan Gupta309ac442016-12-13 20:40:06 +053041};
Patrick Venture537ff142018-11-01 16:37:09 -070042} // namespace udp
43} // namespace slp