summaryrefslogtreecommitdiff
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
parent9112bdaafb2f5af0c9a426ede0278853f32c7dde (diff)
heartbeat vs health listeners
added new command health (not yet implemented)
-rw-r--r--client_list.c2
-rw-r--r--client_list.h2
-rw-r--r--command_queue.h2
-rw-r--r--switchctl.c47
4 files changed, 32 insertions, 21 deletions
diff --git a/client_list.c b/client_list.c
index 0e4bb34..141a3a4 100644
--- a/client_list.c
+++ b/client_list.c
@@ -68,7 +68,7 @@ int client_add(client_t** first, int fd)
new_client->oc_listener = 0;
new_client->relay_listener = 0;
new_client->silence_listener = 0;
- new_client->heartbeat_listener = 0;
+ new_client->health_listener = 0;
new_client->next = NULL;
new_client->buffer.offset = 0;
diff --git a/client_list.h b/client_list.h
index 0a71f65..2f3d5f2 100644
--- a/client_list.h
+++ b/client_list.h
@@ -38,7 +38,7 @@ struct client_struct {
int oc_listener;
int relay_listener;
int silence_listener;
- int heartbeat_listener;
+ int health_listener;
struct client_struct* next;
read_buffer_t buffer;
};
diff --git a/command_queue.h b/command_queue.h
index cba799a..4cdcf9f 100644
--- a/command_queue.h
+++ b/command_queue.h
@@ -24,7 +24,7 @@
#include <sys/time.h>
-enum cmd_id_enum { SWITCH, CHANNEL, TYPE, MODE, HEARTBEAT, STATUS, LOG, LISTEN };
+enum cmd_id_enum { SWITCH, CHANNEL, TYPE, MODE, HEARTBEAT, STATUS, HEALTH, LOG, LISTEN };
typedef enum cmd_id_enum cmd_id_t;
struct cmd_struct {
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);