Loading...
Searching...
No Matches
link_change.h
Go to the documentation of this file.
1
12#pragma once
13#include <stdbool.h>
14
19
29
33typedef struct
34{
35 bool connected;
36 bool seeded;
37} LinkState;
38
49static inline LinkChange link_change_read(LinkState *state, bool connected)
50{
51 bool was_connected = state->connected;
52 bool seeded = state->seeded;
53
54 state->connected = connected;
55 state->seeded = true;
56
57 if (!seeded || was_connected == connected)
58 {
59 return LINK_SAME;
60 }
61
62 return connected ? LINK_RECONNECTED : LINK_DROPPED;
63}
64
static LinkChange link_change_read(LinkState *state, bool connected)
Takes one reading of the link and says what it means.
Definition link_change.h:49
LinkChange
What one reading of the link means.
Definition link_change.h:24
@ LINK_RECONNECTED
The phone link just came back.
Definition link_change.h:27
@ LINK_SAME
The first reading, or one that matches the last. Nothing to act on.
Definition link_change.h:25
@ LINK_DROPPED
The phone link just went down.
Definition link_change.h:26
The link as last read. Zeroed is a store that has read nothing yet.
Definition link_change.h:34
bool seeded
True once a reading has come in, so the next one can be a change.
Definition link_change.h:36
bool connected
True when the phone link was up at the last reading.
Definition link_change.h:35