From 1f13855e412bba26064672b02dff78deecb795ab Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Tue, 27 Apr 2021 23:45:28 +0200 Subject: #1043 add WOL_SENT state WOL_SENT tells that WakeOnLan was sent to computer, after 60 seconds, if computer does not boot, this state is released. --- src/wol.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/wol.c') diff --git a/src/wol.c b/src/wol.c index 0ebf718..b0c9426 100644 --- a/src/wol.c +++ b/src/wol.c @@ -18,6 +18,7 @@ #include #include #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"; +} -- cgit v1.2.3-18-g5258