From 270ecd189fc229375871f3f2ef76934ca4d42a56 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 20 Mar 2014 21:40:29 +0000 Subject: added heartbeat command diff --git a/client_list.c b/client_list.c index 92f7b91..928c354 100644 --- a/client_list.c +++ b/client_list.c @@ -31,8 +31,8 @@ char* client_type_tostring(client_type_t type) { case MASTER: return "master"; case STANDBY: return "standby"; - case MASTER_HB: return "master_hb"; - case STANDBY_HB: return "standby_hb"; + case HB_MASTER: return "hb_master"; + case HB_STANDBY: return "hb_standby"; case DEFAULT: return "unspecified"; } return ""; diff --git a/client_list.h b/client_list.h index a23e76e..cb69f39 100644 --- a/client_list.h +++ b/client_list.h @@ -24,7 +24,7 @@ #include "datatypes.h" -enum client_type_enum { DEFAULT, MASTER, STANDBY, MASTER_HB, STANDBY_HB }; +enum client_type_enum { DEFAULT, MASTER, STANDBY, HB_MASTER, HB_STANDBY }; typedef enum client_type_enum client_type_t; char* client_type_tostring(client_type_t); diff --git a/command_queue.h b/command_queue.h index f84853e..cba799a 100644 --- a/command_queue.h +++ b/command_queue.h @@ -24,7 +24,7 @@ #include -enum cmd_id_enum { SWITCH, CHANNEL, TYPE, MODE, STATUS, LOG, LISTEN }; +enum cmd_id_enum { SWITCH, CHANNEL, TYPE, MODE, HEARTBEAT, STATUS, LOG, LISTEN }; typedef enum cmd_id_enum cmd_id_t; struct cmd_struct { diff --git a/switchctl.c b/switchctl.c index 37fae8b..0f6124f 100644 --- a/switchctl.c +++ b/switchctl.c @@ -87,16 +87,18 @@ void send_usage(int fd) return; send_response(fd, "Usage: "); - send_response(fd, " help prints this"); - send_response(fd, " type set client type, one of: master, standby, master_hb, standby_hb"); - send_response(fd, " channel switch to channel main or music"); - send_response(fd, " client type master and standby only"); - send_response(fd, " mode switch to mode master or standby"); - send_response(fd, " status get actual status from switch"); - send_response(fd, " listen register for events, no parameter for all"); - send_response(fd, " one of: request, mode, status, gpi, oc, relay, silence, none"); - send_response(fd, " log add line to daemons log file"); - send_response(fd, " switch send raw commands to the switch"); + send_response(fd, " help prints this"); + send_response(fd, " quit close connection"); + send_response(fd, " type set client type, one of: master, standby, hb_master, hb_standby"); + send_response(fd, " channel switch to channel main or music"); + send_response(fd, " client type master and standby only"); + send_response(fd, " mode switch to mode master or standby"); + send_response(fd, " heartbeat update heartbeat status for master or standby"); + send_response(fd, " status get actual status from switch"); + send_response(fd, " listen register for events, no parameter for all"); + send_response(fd, " one of: request, mode, status, gpi, oc, relay, silence, none"); + send_response(fd, " log add line to daemons log file"); + send_response(fd, " switch send raw commands to the switch"); } int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt) @@ -357,10 +359,10 @@ void process_cmd_type(const char* param, int fd, client_t* client_lst) client->type = STANDBY; client->gpi_listener = 1; } - else if(!strncmp(param, "master_hb", 9)) - client->type = MASTER_HB; - else if(!strncmp(param, "standby_hb", 10)) - client->type = STANDBY_HB; + else if(!strncmp(param, "hb_master", 9)) + client->type = HB_MASTER; + else if(!strncmp(param, "hb_standby", 10)) + client->type = HB_STANDBY; else { log_printf(DEBUG, "unkown client type '%s'", param); send_response(fd, "EEE: type: unknown client type"); @@ -467,6 +469,32 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c return 0; } +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"); + } + } + else { + log_printf(ERROR, "unable to update heartbeat status: client not found"); + send_response(fd, "EEE: heartbeat: client not found in client list?!"); + } + } + else { + log_printf(ERROR, "unable to update heartbeat status: empty parameter"); + send_response(fd, "EEE: heartbeat: missing parameter"); + } +} + void process_cmd_listen(const char* param, int fd, client_t* client_lst) { client_t* listener = client_find(client_lst, fd); @@ -534,12 +562,16 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op cmd_id = TYPE; else if(!strncmp(cmd, "mode", 4)) cmd_id = MODE; + else if(!strncmp(cmd, "heartbeat", 5)) + cmd_id = HEARTBEAT; else if(!strncmp(cmd, "status", 6)) cmd_id = STATUS; else if(!strncmp(cmd, "log", 3)) cmd_id = LOG; else if(!strncmp(cmd, "listen", 6)) cmd_id = LISTEN; + else if(!strncmp(cmd, "quit", 4)) + return 2; else { if(!strncmp(cmd, "help", 4)) { send_usage(fd); @@ -593,6 +625,7 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op return ret; break; } + case HEARTBEAT: process_cmd_heartbeat(param, fd, client_lst); break; case LOG: { if(param && param[0]) log_printf(NOTICE, "ext msg: %s", param); -- cgit v0.10.2