diff options
-rw-r--r-- | datatypes.h | 4 | ||||
-rw-r--r-- | switchctl.c | 25 |
2 files changed, 20 insertions, 9 deletions
diff --git a/datatypes.h b/datatypes.h index ab714fc..3a72adc 100644 --- a/datatypes.h +++ b/datatypes.h @@ -26,6 +26,10 @@ #include <stdint.h> #include <arpa/inet.h> +typedef uint8_t bool; +#define FALSE 0 +#define TRUE 1 + typedef uint8_t u_int8_t; typedef uint16_t u_int16_t; typedef uint32_t u_int32_t; diff --git a/switchctl.c b/switchctl.c index 2025776..4896f15 100644 --- a/switchctl.c +++ b/switchctl.c @@ -37,11 +37,12 @@ #include "daemon.h" #include "utils.h" - struct state_struct { switchctl_mode_t mode_; switchctl_channel_t channel_master_; switchctl_channel_t channel_standby_; + bool hb_state_master_; + bool hb_state_standby_; }; typedef struct state_struct state_t; @@ -224,6 +225,10 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int send_response(fd, buf[1]); snprintf(buf[1], 30, "Standby Channel: %s", state_.channel_standby_ == CHAN_MAIN ? "Main" : "Music"); send_response(fd, buf[1]); + snprintf(buf[1], 30, "Master Heartbeat: %s", state_.hb_state_master_ ? "present" : "timeout"); + send_response(fd, buf[1]); + snprintf(buf[1], 30, "Standby Heartbeat: %s", state_.hb_state_standby_ ? "present" : "timeout"); + send_response(fd, buf[1]); client_t* client; int listener_cnt = 0; for(client = client_lst; client; client = client->next) @@ -484,14 +489,14 @@ void process_cmd_heartbeat(const char* param, int fd, client_t* client_lst) if(param) { client_t* client = client_find(client_lst, fd); if(client) { - if(client->type == HB_MASTER || client->type == HB_STANDBY) { - log_printf(WARNING, "ignoring heartbeat updates for now!"); - send_response(fd, "EEE: heartbeat: ignoring heartbeat updates for now!"); - // TODO: add support for this - } - else { - log_printf(ERROR, "unable to update heartbeat status: wrong client type"); - send_response(fd, "EEE: heartbeat: wrong client type"); + switch(client->type) { + case HB_MASTER: state_.hb_state_master_ = (param[0] == '1') ? TRUE : FALSE; break; + case HB_STANDBY: state_.hb_state_standby_ = (param[0] == '1') ? TRUE : FALSE; break; + default: { + log_printf(ERROR, "unable to update heartbeat status: wrong client type"); + send_response(fd, "EEE: heartbeat: wrong client type"); + break; + } } } else { @@ -992,6 +997,8 @@ int main(int argc, char* argv[]) state_.mode_ = opt.mode_; state_.channel_master_ = opt.channel_master_; state_.channel_standby_ = opt.channel_standby_; + state_.hb_state_master_ = FALSE; + state_.hb_state_standby_ = FALSE; int switch_fd = 0; for(;;) { |