summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-03-20 23:05:47 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-03-20 23:05:47 (GMT)
commit5da1e9f2c0830a532673da9bc2da36f6f6e05ea1 (patch)
tree83c0277c5f3a2aca2b06587a50e7809cf3581c93 /switchctl.c
parent11f70f400d8f54721ec05c1adfd11915e6c2a905 (diff)
moved mode change to own function
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c119
1 files changed, 61 insertions, 58 deletions
diff --git a/switchctl.c b/switchctl.c
index 4896f15..d18883b 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -401,6 +401,65 @@ void process_cmd_type(const char* param, int fd, client_t* client_lst)
}
}
+int change_mode(switchctl_mode_t old_mode, int fd, cmd_t **cmd_q, options_t* opt, client_t* client_lst)
+{
+ char* ch_from = NULL;
+ if(old_mode == MODE_MASTER && state_.channel_master_ == CHAN_MAIN)
+ ch_from = "master_main";
+ else if(old_mode == MODE_MASTER && state_.channel_master_ == CHAN_MUSIC)
+ ch_from = "master_music";
+ else if(old_mode == MODE_STANDBY && state_.channel_standby_ == CHAN_MAIN)
+ ch_from = "standby_main";
+ else if(old_mode == MODE_STANDBY && state_.channel_standby_ == CHAN_MUSIC)
+ ch_from = "standby_music";
+ else {
+ state_.mode_ = old_mode;
+ log_printf(ERROR, "EEE: mode: old config is illegal?!");
+ return 0;
+ }
+
+ char* ch_to = NULL;
+ if(state_.mode_ == MODE_MASTER && state_.channel_master_ == CHAN_MAIN)
+ ch_to = "master_main";
+ else if(state_.mode_ == MODE_MASTER && state_.channel_master_ == CHAN_MUSIC)
+ ch_to = "master_music";
+ else if(state_.mode_ == MODE_STANDBY && state_.channel_standby_ == CHAN_MAIN)
+ ch_to = "standby_main";
+ else if(state_.mode_ == MODE_STANDBY && state_.channel_standby_ == CHAN_MUSIC)
+ ch_to = "standby_music";
+ else {
+ state_.mode_ = old_mode;
+ log_printf(ERROR, "EEE: mode: current config is illegal?!");
+ return 0;
+ }
+
+ int ret = crossfade(ch_from, ch_to, fd, cmd_q, opt);
+ if(ret) {
+ state_.mode_ = old_mode;
+ if(ret > 0)
+ return 0;
+
+ return ret;
+ }
+
+ char* mode_str;
+ int len = asprintf(&mode_str, "new Mode: %s", state_.mode_ == MODE_MASTER ? "master" : "standby");
+ if(len > 0) {
+ log_printf(NOTICE, "%s", mode_str);
+ client_t* client;
+ int listener_cnt = 0;
+ for(client = client_lst; client; client = client->next)
+ if(client->mode_listener && client->fd != fd) {
+ send_response(client->fd, mode_str);
+ listener_cnt++;
+ }
+ free(mode_str);
+ log_printf(DEBUG, "sent new mode to %d additional listeners", listener_cnt);
+ }
+
+ return 0;
+}
+
int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, client_t* client_lst)
{
switchctl_mode_t old_mode = state_.mode_;
@@ -417,70 +476,14 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c
}
// swap master with standby channels only when mode has changed
- if(old_mode != state_.mode_) {
- char* ch_from = NULL;
- if(old_mode == MODE_MASTER && state_.channel_master_ == CHAN_MAIN)
- ch_from = "master_main";
- else if(old_mode == MODE_MASTER && state_.channel_master_ == CHAN_MUSIC)
- ch_from = "master_music";
- else if(old_mode == MODE_STANDBY && state_.channel_standby_ == CHAN_MAIN)
- ch_from = "standby_main";
- else if(old_mode == MODE_STANDBY && state_.channel_standby_ == CHAN_MUSIC)
- ch_from = "standby_music";
- else {
- state_.mode_ = old_mode;
- log_printf(ERROR, "EEE: mode: old config is illegal?!");
- return 0;
- }
-
- char* ch_to = NULL;
- if(state_.mode_ == MODE_MASTER && state_.channel_master_ == CHAN_MAIN)
- ch_to = "master_main";
- else if(state_.mode_ == MODE_MASTER && state_.channel_master_ == CHAN_MUSIC)
- ch_to = "master_music";
- else if(state_.mode_ == MODE_STANDBY && state_.channel_standby_ == CHAN_MAIN)
- ch_to = "standby_main";
- else if(state_.mode_ == MODE_STANDBY && state_.channel_standby_ == CHAN_MUSIC)
- ch_to = "standby_music";
- else {
- state_.mode_ = old_mode;
- log_printf(ERROR, "EEE: mode: current config is illegal?!");
- return 0;
- }
-
- int ret = crossfade(ch_from, ch_to, fd, cmd_q, opt);
- if(ret) {
- state_.mode_ = old_mode;
- if(ret > 0)
- return 0;
-
- return ret;
- }
- }
+ if(old_mode != state_.mode_)
+ return change_mode(old_mode, fd, cmd_q, opt, client_lst);
}
else {
log_printf(ERROR, "unable to set mode: empty parameter");
send_response(fd, "EEE: mode: missing parameter");
}
- if(old_mode != state_.mode_) {
- char* mode_str;
- int len = asprintf(&mode_str, "new Mode: %s", state_.mode_ == MODE_MASTER ? "master" : "standby");
- if(len > 0) {
- log_printf(NOTICE, "%s", mode_str);
- client_t* client;
- int listener_cnt = 0;
- for(client = client_lst; client; client = client->next)
- if(client->mode_listener && client->fd != fd) {
- send_response(client->fd, mode_str);
- listener_cnt++;
- }
- free(mode_str);
- log_printf(DEBUG, "sent new mode to %d additional listeners", listener_cnt);
- }
-
- }
-
return 0;
}