diff options
Diffstat (limited to 'src/wol.c')
-rw-r--r-- | src/wol.c | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -18,6 +18,7 @@ #include <sys/socket.h> #include <fcntl.h> #include "wol.h" +#include "rest.h" #include "cfg.h" #include "ogAdmServer.h" @@ -86,3 +87,52 @@ bool wake_up_broadcast(int sd, struct sockaddr_in *client, return wake_up_send(sd, client, msg, &addr.sin_addr); } + +#define OG_WOL_CLIENT_TIMEOUT 60 + +static void og_client_wol_timer_cb(struct ev_loop *loop, ev_timer *timer, + int events) +{ + struct og_client_wol *cli_wol; + + cli_wol = container_of(timer, struct og_client_wol, timer); + + syslog(LOG_ERR, "timeout WakeOnLAN request for client %s\n", + inet_ntoa(cli_wol->addr)); + list_del(&cli_wol->list); + free(cli_wol); +} + +struct og_client_wol *og_client_wol_create(const struct in_addr *addr) +{ + struct og_client_wol *cli_wol; + + cli_wol = calloc(1, sizeof(struct og_client_wol)); + if (!cli_wol) + return NULL; + + cli_wol->addr = *addr; + + ev_timer_init(&cli_wol->timer, og_client_wol_timer_cb, + OG_WOL_CLIENT_TIMEOUT, 0.); + ev_timer_start(og_loop, &cli_wol->timer); + + return cli_wol; +} + +void og_client_wol_refresh(struct og_client_wol *cli_wol) +{ + ev_timer_again(og_loop, &cli_wol->timer); +} + +void og_client_wol_destroy(struct og_client_wol *cli_wol) +{ + ev_timer_stop(og_loop, &cli_wol->timer); + list_del(&cli_wol->list); + free(cli_wol); +} + +const char *og_client_wol_status(const struct og_client_wol *wol) +{ + return "WOL_SENT"; +} |