summaryrefslogtreecommitdiffstats
path: root/src/wol.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2021-04-27 23:45:28 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-04-29 11:52:32 +0200
commit1f13855e412bba26064672b02dff78deecb795ab (patch)
tree7a44db095824ef03cedaa597485ca5d5c73969b6 /src/wol.c
parentc05f1345e76e26eadc798425d820665b9fb8a819 (diff)
#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.
Diffstat (limited to 'src/wol.c')
-rw-r--r--src/wol.c50
1 files changed, 50 insertions, 0 deletions
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 <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";
+}