diff options
author | Christian Pointner <equinox@helsinki.at> | 2010-01-19 13:20:43 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2010-01-19 13:20:43 (GMT) |
commit | 57c708218fc8384acefd942e38d54bad881f53d7 (patch) | |
tree | 98b6605dc3f4edd10021adbf4ce6d98ac9b44da2 | |
parent | f940c6741d6e7c8fcc682d733a15ca7aecd46ddc (diff) |
improved mail output at mode_watch.lua
active channel of both system is now watched
-rw-r--r-- | mode-watch.lua | 11 | ||||
-rw-r--r-- | options.c | 15 | ||||
-rw-r--r-- | options.h | 3 | ||||
-rw-r--r-- | switchctl.c | 65 |
4 files changed, 61 insertions, 33 deletions
diff --git a/mode-watch.lua b/mode-watch.lua index 05d3567..abea7b9 100644 --- a/mode-watch.lua +++ b/mode-watch.lua @@ -47,7 +47,7 @@ function send_mail(address, subject, bodytext) fp:close() end -current_mode = "master" +current_mode = nil function process_cmd(message) log.printf(log.DEBUG, "received message: '%s'", message) @@ -72,8 +72,13 @@ function process_cmd(message) if(new_mode and new_mode ~= current_mode) then log.printf(log.NOTICE, "mode is now " .. new_mode) - send_mail("logs@helsinki.at", "[RHCTL] mode changed to " .. new_mode, - "RHCTL just switched from " .. current_mode .. " to " .. new_mode) + if(current_mode == nil) then + send_mail("logs@helsinki.at", "[RHCTL] (re)started mode is now " .. new_mode, + "RHCTL just (re)started current mode is " .. new_mode) + else + send_mail("logs@helsinki.at", "[RHCTL] mode changed to " .. new_mode, + "RHCTL just switched from " .. current_mode .. " to " .. new_mode) + end current_mode = new_mode end @@ -218,10 +218,14 @@ int options_parse(options_t* opt, int argc, char* argv[]) } if(channel) { - if(!strcmp(channel, "main")) - opt->channel_ = CHAN_MAIN; - else if(!strcmp(channel, "music")) - opt->channel_ = CHAN_MUSIC; + if(!strcmp(channel, "main")) { + opt->channel_master_ = CHAN_MAIN; + opt->channel_standby_ = CHAN_MAIN; + } + else if(!strcmp(channel, "music")) { + opt->channel_master_ = CHAN_MUSIC; + opt->channel_standby_ = CHAN_MUSIC; + } else { free(channel); return -4; @@ -319,7 +323,8 @@ void options_default(options_t* opt) /* switchctl */ opt->mode_ = MODE_MASTER; - opt->channel_ = CHAN_MAIN; + opt->channel_master_ = CHAN_MAIN; + opt->channel_standby_ = CHAN_MAIN; opt->conf_file_ = strdup("/etc/rhctl/switchctl.conf"); opt->switch_dev_ = strdup("/dev/audioswitch"); key_value_storage_init(&opt->alias_table_); @@ -49,7 +49,8 @@ struct options_struct { /* switchctl */ mode_t mode_; - channel_t channel_; + channel_t channel_master_; + channel_t channel_standby_; char* conf_file_; char* switch_dev_; key_value_storage_t alias_table_; 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); |