diff options
Diffstat (limited to 'switchctl.c')
-rw-r--r-- | switchctl.c | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/switchctl.c b/switchctl.c index ca71d42..d603fc2 100644 --- a/switchctl.c +++ b/switchctl.c @@ -189,7 +189,9 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int char buf[2][30]; snprintf(buf[0], 30, "Current Mode: %s", opt->mode_ == MODE_MASTER ? "Master" : "Standby"); send_response(fd, buf[0]); - snprintf(buf[1], 30, "Current Channel: %s", opt->channel_ == CHAN_MAIN ? "Main" : "Music"); + snprintf(buf[1], 30, "Master Channel: %s", opt->channel_master_ == CHAN_MAIN ? "Main" : "Music"); + send_response(fd, buf[1]); + snprintf(buf[1], 30, "Standby Channel: %s", opt->channel_standby_ == CHAN_MAIN ? "Main" : "Music"); send_response(fd, buf[1]); client_t* client; int listener_cnt = 0; @@ -254,20 +256,18 @@ int process_cmd_channel(const char* cmd, const char* param, int fd, cmd_t **cmd_ return 0; } - if((opt->mode_ == MODE_MASTER && c->type == STANDBY )|| - (opt->mode_ == MODE_STANDBY && c->type == MASTER )) - { - log_printf(INFO, "silently ignoring request from inactive system (%s)", c->type == MASTER ? "master" : "standby"); - return 0; - } - if(!param) { log_printf(INFO, "ignoring channel command without parameter"); send_response(fd, "EEE: channel: missing parameter"); return 0; } - channel_t old_channel = opt->channel_; + channel_t old_channel; + if(c->type == MASTER) + old_channel = opt->channel_master_; + else + old_channel = opt->channel_standby_; + char* ch_from = NULL; char* ch_to = NULL; if(!strcmp(param, "main")) { @@ -279,7 +279,10 @@ int process_cmd_channel(const char* cmd, const char* param, int fd, cmd_t **cmd_ ch_from = "standby_music"; ch_to = "standby_main"; } - opt->channel_ = CHAN_MAIN; + if(c->type == MASTER) + opt->channel_master_ = CHAN_MAIN; + else + opt->channel_standby_ = CHAN_MAIN; } else if(!strcmp(param, "music")) { if(opt->mode_ == MODE_MASTER) { @@ -290,12 +293,26 @@ int process_cmd_channel(const char* cmd, const char* param, int fd, cmd_t **cmd_ ch_from = "standby_main"; ch_to = "standby_music"; } - opt->channel_ = CHAN_MUSIC; + if(c->type == MASTER) + opt->channel_master_ = CHAN_MUSIC; + else + opt->channel_standby_ = CHAN_MUSIC; + } + + if((opt->mode_ == MODE_MASTER && c->type == STANDBY )|| + (opt->mode_ == MODE_STANDBY && c->type == MASTER )) + { + log_printf(INFO, "no crossfade for inactive system (%s), just updated channel info", c->type == MASTER ? "master" : "standby"); + return 0; } int ret = crossfade(ch_from, ch_to, fd, cmd_q, opt); if(ret) { - opt->channel_ = old_channel; + if(c->type == MASTER) + opt->channel_master_ = old_channel; + else + opt->channel_standby_ = old_channel; + if(ret > 0) return 0; @@ -358,13 +375,13 @@ 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 != opt->mode_) { char* ch_from = NULL; - if(old_mode == MODE_MASTER && opt->channel_ == CHAN_MAIN) + if(old_mode == MODE_MASTER && opt->channel_master_ == CHAN_MAIN) ch_from = "master_main"; - else if(old_mode == MODE_MASTER && opt->channel_ == CHAN_MUSIC) + else if(old_mode == MODE_MASTER && opt->channel_master_ == CHAN_MUSIC) ch_from = "master_music"; - else if(old_mode == MODE_STANDBY && opt->channel_ == CHAN_MAIN) + else if(old_mode == MODE_STANDBY && opt->channel_standy_ == CHAN_MAIN) ch_from = "standby_main"; - else if(old_mode == MODE_STANDBY && opt->channel_ == CHAN_MUSIC) + else if(old_mode == MODE_STANDBY && opt->channel_standby_ == CHAN_MUSIC) ch_from = "standby_music"; else { opt->mode_ = old_mode; @@ -373,13 +390,13 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c } char* ch_to = NULL; - if(opt->mode_ == MODE_MASTER && opt->channel_ == CHAN_MAIN) + if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MAIN) ch_to = "master_main"; - else if(opt->mode_ == MODE_MASTER && opt->channel_ == CHAN_MUSIC) + else if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MUSIC) ch_to = "master_music"; - else if(opt->mode_ == MODE_STANDBY && opt->channel_ == CHAN_MAIN) + else if(opt->mode_ == MODE_STANDBY && opt->channel_standby_ == CHAN_MAIN) ch_to = "standby_main"; - else if(opt->mode_ == MODE_STANDBY && opt->channel_ == CHAN_MUSIC) + else if(opt->mode_ == MODE_STANDBY && opt->channel_standby_ == CHAN_MUSIC) ch_to = "standby_music"; else { opt->mode_ = old_mode; @@ -691,10 +708,10 @@ int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt) int return_value = 0; char* channel; - if(opt->mode_ == MODE_MASTER && opt->channel_ == CHAN_MAIN) channel = "master_main"; - else if(opt->mode_ == MODE_MASTER && opt->channel_ == CHAN_MUSIC) channel = "master_music"; - else if(opt->mode_ == MODE_STANDBY && opt->channel_ == CHAN_MAIN) channel = "standby_main"; - else if(opt->mode_ == MODE_STANDBY && opt->channel_ == CHAN_MUSIC) channel = "standby_music"; + if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MAIN) channel = "master_main"; + else if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MUSIC) channel = "master_music"; + else if(opt->mode_ == MODE_STANDBY && opt->channel_standby_ == CHAN_MAIN) channel = "standby_main"; + else if(opt->mode_ == MODE_STANDBY && opt->channel_standby_ == CHAN_MUSIC) channel = "standby_music"; char* cmd_param = strdup("*0M1*0ii1"); char* ch_nr = key_value_storage_find(&opt->alias_table_, channel); |