summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-03-20 21:40:29 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-03-20 21:40:29 (GMT)
commit270ecd189fc229375871f3f2ef76934ca4d42a56 (patch)
tree65dbb517e2b951f2d51d0b2c9eb44dbd8c997c91 /switchctl.c
parent16842a01fa7785f240677687a2212ed575b384e2 (diff)
added heartbeat command
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c61
1 files changed, 47 insertions, 14 deletions
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);