blob: dd96cfe8090e9e21f04ed952e6c99a4818910cbc [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{
Patrick Venture537ff142018-11-01 16:37:09 -070026 public:
27 Server() : Server(slp::PORT, nullptr){};
Ratan Gupta309ac442016-12-13 20:40:06 +053028
Patrick Venture537ff142018-11-01 16:37:09 -070029 Server(uint16_t port, sd_event_io_handler_t cb) : port(port), callme(cb){};
Ratan Gupta309ac442016-12-13 20:40:06 +053030
Patrick Venture537ff142018-11-01 16:37:09 -070031 Server(const Server&) = delete;
32 Server& operator=(const Server&) = delete;
33 Server(Server&&) = default;
34 Server& operator=(Server&&) = default;
Ratan Gupta309ac442016-12-13 20:40:06 +053035
Patrick Venture537ff142018-11-01 16:37:09 -070036 uint16_t port;
37 sd_event_io_handler_t callme;
Ratan Gupta309ac442016-12-13 20:40:06 +053038
Patrick Venture537ff142018-11-01 16:37:09 -070039 int run();
Ratan Gupta309ac442016-12-13 20:40:06 +053040};
Patrick Venture537ff142018-11-01 16:37:09 -070041} // namespace udp
42} // namespace slp