summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-03-24 16:54:01 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-03-24 16:54:01 (GMT)
commit537fcc5aaf66c9cba993af12f4f2a8b04c36dde1 (patch)
tree442bff424045dea0e9e9cc76a79ec0dddd3d72c6 /switchctl.c
parent9112bdaafb2f5af0c9a426ede0278853f32c7dde (diff)
heartbeat vs health listeners
added new command health (not yet implemented)
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/switchctl.c b/switchctl.c
index 0e1b4ea..e62a5a5 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -106,8 +106,9 @@ void send_usage(int fd)
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, " health get health info");
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, " one of: request, mode, status, health, 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");
}
@@ -218,17 +219,13 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
return ret;
if(cmd_id == STATUS) {
- char buf[5][30];
+ char buf[3][30];
snprintf(buf[0], 30, "Current Mode: %s", state_.mode_ == MODE_MASTER ? "Master" : "Standby");
send_response(fd, buf[0]);
snprintf(buf[1], 30, "Master Channel: %s", state_.channel_master_ == CHAN_MAIN ? "Main" : "Music");
send_response(fd, buf[1]);
snprintf(buf[2], 30, "Standby Channel: %s", state_.channel_standby_ == CHAN_MAIN ? "Main" : "Music");
send_response(fd, buf[2]);
- snprintf(buf[3], 30, "Master Heartbeat: %s", state_.hb_state_master_ ? "present" : "timeout");
- send_response(fd, buf[3]);
- snprintf(buf[4], 30, "Standby Heartbeat: %s", state_.hb_state_standby_ ? "present" : "timeout");
- send_response(fd, buf[4]);
client_t* client;
int listener_cnt = 0;
for(client = client_lst; client; client = client->next)
@@ -502,9 +499,9 @@ int process_cmd_heartbeat(const char* param, int fd, cmd_t **cmd_q, client_t* cl
state_.hb_state_master_ = (param[0] == '1') ? TRUE : FALSE;
if(old_state != state_.hb_state_master_) {
if(state_.hb_state_master_)
- message = "Master: heartbeat is back!";
+ message = "Health: master heartbeat is back!";
else
- message = "Master: heartbeat timed out!";
+ message = "Health: master heartbeat timed out!";
}
break;
}
@@ -513,9 +510,9 @@ int process_cmd_heartbeat(const char* param, int fd, cmd_t **cmd_q, client_t* cl
state_.hb_state_standby_ = (param[0] == '1') ? TRUE : FALSE;
if(old_state != state_.hb_state_standby_) {
if(state_.hb_state_standby_)
- message = "Standby: heartbeat is back!";
+ message = "Health: standby heartbeat is back!";
else
- message = "Standby: heartbeat timed out!";
+ message = "Health: standby heartbeat timed out!";
}
break;
}
@@ -532,7 +529,7 @@ int process_cmd_heartbeat(const char* param, int fd, cmd_t **cmd_q, client_t* cl
state_.mode_ = MODE_STANDBY;
return change_mode(old_mode, fd, cmd_q, opt, client_lst);
} else
- message = "both heartbeats are offline!";
+ message = "Health: both heartbeats are offline!";
}
} else {
if(!state_.hb_state_standby_) {
@@ -540,7 +537,7 @@ int process_cmd_heartbeat(const char* param, int fd, cmd_t **cmd_q, client_t* cl
state_.mode_ = MODE_MASTER;
return change_mode(old_mode, fd, cmd_q, opt, client_lst);
} else
- message = "both heartbeats are offline!";
+ message = "Health: both heartbeats are offline!";
}
}
if(message) {
@@ -548,11 +545,11 @@ int process_cmd_heartbeat(const char* param, int fd, cmd_t **cmd_q, client_t* cl
client_t* client;
int listener_cnt = 0;
for(client = client_lst; client; client = client->next)
- if(client->heartbeat_listener && client->fd != fd) {
+ if(client->health_listener && client->fd != fd) {
send_response(client->fd, message);
listener_cnt++;
}
- log_printf(DEBUG, "sent heartbeat state to %d additional listeners", listener_cnt);
+ log_printf(DEBUG, "sent health info to %d additional listeners", listener_cnt);
}
}
else {
@@ -567,6 +564,12 @@ int process_cmd_heartbeat(const char* param, int fd, cmd_t **cmd_q, client_t* cl
return 0;
}
+int process_cmd_health(const char* param, int fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt)
+{
+ send_response(fd, "EEE: health not yet implemented!");
+ return 0;
+}
+
void process_cmd_listen(const char* param, int fd, client_t* client_lst)
{
client_t* listener = client_find(client_lst, fd);
@@ -579,7 +582,7 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst)
listener->oc_listener = 1;
listener->relay_listener = 1;
listener->silence_listener = 1;
- listener->heartbeat_listener = 1;
+ listener->health_listener = 1;
}
else {
if(!strncmp(param, "request", 7))
@@ -596,8 +599,8 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst)
listener->relay_listener = 1;
else if(!strncmp(param, "silence", 7))
listener->silence_listener = 1;
- else if(!strncmp(param, "heartbeat", 11))
- listener->heartbeat_listener = 1;
+ else if(!strncmp(param, "health", 6))
+ listener->health_listener = 1;
else if(!strncmp(param, "none", 4)) {
listener->request_listener = 0;
listener->mode_listener = 0;
@@ -606,7 +609,7 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst)
listener->oc_listener = 0;
listener->relay_listener = 0;
listener->silence_listener = 0;
- listener->heartbeat_listener = 0;
+ listener->health_listener = 0;
}
else {
log_printf(DEBUG, "unkown listener type '%s'", param);
@@ -642,6 +645,8 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
cmd_id = HEARTBEAT;
else if(!strncmp(cmd, "status", 6))
cmd_id = STATUS;
+ else if(!strncmp(cmd, "health", 6))
+ cmd_id = HEALTH;
else if(!strncmp(cmd, "log", 3))
cmd_id = LOG;
else if(!strncmp(cmd, "listen", 6))
@@ -707,6 +712,12 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
return ret;
break;
}
+ case HEALTH: {
+ int ret = process_cmd_health(param, fd, cmd_q, client_lst, opt);
+ if(ret)
+ return ret;
+ break;
+ }
case LOG: {
if(param && param[0])
log_printf(NOTICE, "ext msg: %s", param);