summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-03-20 21:06:14 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-03-20 21:06:14 (GMT)
commit16842a01fa7785f240677687a2212ed575b384e2 (patch)
treea1cda7284986a0ec54bd39b88bfeb155c9eac043
parent25a74bf11ccd8c90d365038e80e57c9a621569df (diff)
allow type setting only once
-rw-r--r--client_list.c13
-rw-r--r--client_list.h1
-rw-r--r--switchctl.c38
3 files changed, 36 insertions, 16 deletions
diff --git a/client_list.c b/client_list.c
index 51c50fa..92f7b91 100644
--- a/client_list.c
+++ b/client_list.c
@@ -25,6 +25,19 @@
#include "client_list.h"
#include "datatypes.h"
+char* client_type_tostring(client_type_t type)
+{
+ switch(type)
+ {
+ case MASTER: return "master";
+ case STANDBY: return "standby";
+ case MASTER_HB: return "master_hb";
+ case STANDBY_HB: return "standby_hb";
+ case DEFAULT: return "unspecified";
+ }
+ return "<invalid>";
+}
+
client_t* client_get_last(client_t* first)
{
if(!first)
diff --git a/client_list.h b/client_list.h
index 9ff5754..a23e76e 100644
--- a/client_list.h
+++ b/client_list.h
@@ -26,6 +26,7 @@
enum client_type_enum { DEFAULT, MASTER, STANDBY, MASTER_HB, STANDBY_HB };
typedef enum client_type_enum client_type_t;
+char* client_type_tostring(client_type_t);
struct client_struct {
int fd;
diff --git a/switchctl.c b/switchctl.c
index 7390e0a..37fae8b 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -88,7 +88,7 @@ void send_usage(int fd)
send_response(fd, "Usage: ");
send_response(fd, " help prints this");
- send_response(fd, " type set client type, one of: master, standby, heartbeat");
+ 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");
@@ -348,24 +348,30 @@ void process_cmd_type(const char* param, int fd, client_t* client_lst)
if(param) {
client_t* client = client_find(client_lst, fd);
if(client) {
- if(!strncmp(param, "master", 6)) {
- client->type = MASTER;
- client->gpi_listener = 1;
- }
- else if(!strncmp(param, "standby", 7)) {
- client->type = STANDBY;
- client->gpi_listener = 1;
+ if(client->type == DEFAULT) {
+ if(!strncmp(param, "master", 6)) {
+ client->type = MASTER;
+ client->gpi_listener = 1;
+ }
+ else if(!strncmp(param, "standby", 7)) {
+ 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 {
+ log_printf(DEBUG, "unkown client type '%s'", param);
+ send_response(fd, "EEE: type: unknown client type");
+ return;
+ }
+ log_printf(DEBUG, "client %d type set to %s", fd, param);
}
- else if(!strncmp(param, "master_hb", 9))
- client->type = MASTER_HB;
- else if(!strncmp(param, "standby_hb", 10))
- client->type = STANDBY_HB;
else {
- log_printf(DEBUG, "unkown client type '%s'", param);
- send_response(fd, "EEE: type: unknown client type");
- return;
+ log_printf(ERROR, "unable to set client type for %d: type already set to %s", fd, client_type_tostring(client->type));
+ send_response(fd, "EEE: type: type already set");
}
- log_printf(DEBUG, "client %d type set to %s", fd, param);
}
else {
log_printf(ERROR, "unable to set client type for %d: client not found", fd);