summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client_list.h2
-rw-r--r--command_queue.h2
-rw-r--r--options.c1
-rw-r--r--options.h4
-rw-r--r--switchctl.c46
5 files changed, 52 insertions, 3 deletions
diff --git a/client_list.h b/client_list.h
index d54a853..8c1d5af 100644
--- a/client_list.h
+++ b/client_list.h
@@ -24,7 +24,7 @@
#include "datatypes.h"
-enum client_type_enum { DEFAULT, MASTER, STANDBY };
+enum client_type_enum { DEFAULT, MASTER, STANDBY, HEARTBEAT };
typedef enum client_type_enum client_type_t;
struct client_struct {
diff --git a/command_queue.h b/command_queue.h
index a97462f..7a475fd 100644
--- a/command_queue.h
+++ b/command_queue.h
@@ -24,7 +24,7 @@
#include <sys/time.h>
-enum cmd_id_enum { SWITCH, STATUS, LOG, LISTEN };
+enum cmd_id_enum { SWITCH, TYPE, MODE, STATUS, LOG, LISTEN };
typedef enum cmd_id_enum cmd_id_t;
struct cmd_struct {
diff --git a/options.c b/options.c
index 05ea50a..37064c6 100644
--- a/options.c
+++ b/options.c
@@ -230,6 +230,7 @@ void options_default(options_t* opt)
opt->pid_file_ = NULL;
string_list_init(&opt->log_targets_);
+ opt->mode_ = MODE_MASTER;
opt->conf_file_ = strdup("/etc/rhctl/switchctl.conf");
opt->command_sock_ = strdup("/var/run/rhctl/switchctl.sock");
opt->switch_dev_ = strdup("/dev/audioswitch");
diff --git a/options.h b/options.h
index 1c17809..e8e3930 100644
--- a/options.h
+++ b/options.h
@@ -25,6 +25,9 @@
#include "string_list.h"
#include "key_value_storage.h"
+enum mode_enum { MODE_MASTER, MODE_STANDBY };
+typedef enum mode_enum mode_t;
+
struct options_struct {
char* progname_;
int daemonize_;
@@ -34,6 +37,7 @@ struct options_struct {
char* pid_file_;
string_list_t log_targets_;
+ mode_t mode_;
char* conf_file_;
char* command_sock_;
char* switch_dev_;
diff --git a/switchctl.c b/switchctl.c
index f961f31..9bf0612 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -86,6 +86,10 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
cmd_id_t cmd_id;
if(!strncmp(cmd, "switch", 6))
cmd_id = SWITCH;
+ else if(!strncmp(cmd, "type", 4))
+ cmd_id = TYPE;
+ else if(!strncmp(cmd, "mode", 4))
+ cmd_id = MODE;
else if(!strncmp(cmd, "status", 6))
cmd_id = STATUS;
else if(!strncmp(cmd, "log", 3))
@@ -121,7 +125,7 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
}
switch(cmd_id) {
- case SWITCH:
+ case SWITCH:
case STATUS: {
char* tmp = key_value_storage_find(&opt->alias_table_, param);
int ret = cmd_push(cmd_q, fd, cmd_id, tmp != NULL ? tmp : param);
@@ -131,6 +135,46 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
log_printf(NOTICE, "command: %s", cmd);
break;
}
+ case TYPE: {
+ if(param) {
+ client_t* client = client_find(client_lst, fd);
+ if(client) {
+ if(!strncmp(param, "master", 6))
+ client->type = MASTER;
+ else if(!strncmp(param, "standby", 7))
+ client->type = STANDBY;
+ else if(!strncmp(param, "heartbeat", 9))
+ client->type = HEARTBEAT;
+ else {
+ log_printf(DEBUG, "unkown client type '%s'", param);
+ break;
+ }
+ 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);
+ }
+ else
+ log_printf(ERROR, "unable to set client type for %d: empty parameter", fd);
+
+ break;
+ }
+ case MODE: {
+ if(param) {
+ if(!strncmp(param, "master", 6))
+ opt->mode_ = MODE_MASTER;
+ else if(!strncmp(param, "standby", 7))
+ opt->mode_ = MODE_STANDBY;
+ else {
+ log_printf(DEBUG, "unkown mode '%s'", param);
+ break;
+ }
+ }
+ else
+ log_printf(ERROR, "unable to set mode: empty parameter", fd);
+
+ break;
+ }
case LOG: {
if(param && param[0])
log_printf(NOTICE, "ext msg: %s", param);