error server_control_executor::notify_icat_and_local_servers_preop( const std::string& _cmd_name, const std::string& _cmd_option, const std::string& _wait_option, const size_t& _wait_seconds, const host_list_t& _cmd_hosts, std::string& _output ) { if ( SERVER_CONTROL_RESUME != _cmd_name ) { return SUCCESS(); } error ret = SUCCESS(); const bool is_all_opt = ( SERVER_CONTROL_ALL_OPT == _cmd_option ); const bool found_my_host = is_host_in_list( my_host_name_, _cmd_hosts ); const bool found_icat_host = is_host_in_list( icat_host_name_, _cmd_hosts ); const bool is_icat_host = compare_host_names( my_host_name_, icat_host_name_ ); // for pause or shutdown: pre-op forwards to the ies first, // then to myself, then others // for resume: we skip doing work here (we'll go last in post-op) if ( found_icat_host || is_all_opt ) { ret = forward_command( _cmd_name, icat_host_name_, CFG_SERVER_CONTROL_PLANE_PORT, _wait_option, _wait_seconds, _output ); // takes sec, microsec ctrl_plane_sleep( 0, SERVER_CONTROL_FWD_SLEEP_TIME_MILLI_SEC ); } // pre-op forwards to the local server second // such as for resume if ( !is_icat_host && ( found_my_host || is_all_opt ) ) { ret = forward_command( _cmd_name, my_host_name_, CFG_SERVER_CONTROL_PLANE_PORT, _wait_option, _wait_seconds, _output ); } return ret; } // notify_icat_and_local_servers_preop
error server_control_executor::notify_icat_and_local_servers_postop( const std::string& _cmd_name, const std::string& _cmd_option, const std::string& _wait_option, const size_t& _wait_seconds, const host_list_t& _cmd_hosts, std::string& _output ) { error ret = SUCCESS(); if ( SERVER_CONTROL_RESUME == _cmd_name ) { return SUCCESS(); } bool is_all_opt = ( SERVER_CONTROL_ALL_OPT == _cmd_option ); const bool found_my_host = is_host_in_list( my_host_name_, _cmd_hosts ); const bool found_icat_host = is_host_in_list( icat_host_name_, _cmd_hosts ); const bool is_icat_host = compare_host_names( my_host_name_, icat_host_name_ ); // post-op forwards to the local server first // then the icat such as for shutdown if ( !is_icat_host && ( found_my_host || is_all_opt ) ) { ret = forward_command( _cmd_name, my_host_name_, CFG_SERVER_CONTROL_PLANE_PORT, _wait_option, _wait_seconds, _output ); } // post-op forwards to the ies last if ( found_icat_host || is_all_opt ) { ret = forward_command( _cmd_name, icat_host_name_, CFG_SERVER_CONTROL_PLANE_PORT, _wait_option, _wait_seconds, _output ); } return ret; } // notify_icat_and_local_servers_postop
// try to broadcast buf to destination dest char *try_broadcast(char *dest, char *buf, char *unique) { print_try_broadcast(dest, buf); char *r = forward_command(dest, buf, unique); if (r == NULL) print_failed_broadcast(dest); return r; }
error server_control_executor::process_host_list( const std::string& _cmd_name, const std::string& _wait_option, const size_t& _wait_seconds, const host_list_t& _hosts, std::string& _output ) { if ( _hosts.empty() ) { return SUCCESS(); } error fwd_err = SUCCESS(); host_list_t::const_iterator itr; for ( itr = _hosts.begin(); itr != _hosts.end(); ++itr ) { if ( "localhost" == *itr ) { continue; } std::string output; if ( compare_host_names( *itr, my_host_name_ ) ) { error ret = op_map_[ _cmd_name ]( _wait_option, _wait_seconds, output ); if ( !ret.ok() ) { fwd_err = PASS( ret ); } _output += output; } else { error ret = forward_command( _cmd_name, *itr, port_prop_, _wait_option, _wait_seconds, output ); if ( !ret.ok() ) { log( PASS( ret ) ); fwd_err = PASS( ret ); } else { _output += output; } } } // for itr return fwd_err; } // process_host_list
static void run_command(void) { if (command <= CMD_FADE_DOWN) { switch (command) { case CMD_NONE: case CMD_NO1: case CMD_NO2: case CMD_NO3: break; case CMD_MAINS_ON: PORTD |= _BV(PD4); break; case CMD_MAINS_OFF: PORTD &= ~_BV(PD4); break; case CMD_LIGHT_ON: light = L_ON; TCCR0A = TCCR0B = 0; PORTD |= _BV(PD5); break; case CMD_LIGHT_OFF: light = L_OFF; TCCR0A = TCCR0B = 0; PORTD &= ~_BV(PD5); break; case CMD_LIGHT_10P: light = L_10P; OCR0B = 26; TCCR0A = _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(CS00); break; case CMD_LIGHT_20P: light = L_20P; OCR0B = 52; TCCR0A = _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(CS00); break; case CMD_LIGHT_40P: light = L_40P; OCR0B = 104; TCCR0A = _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(CS00); break; case CMD_LIGHT_60P: light = L_60P; OCR0B = 156; TCCR0A = _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(CS00); break; case CMD_LIGHT_STROBE: light = L_STROBE; OCR0B = 128; TCCR0A = _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(CS02); break; case CMD_FADE_UP: light = L_FUP; OCR0B = 0; TCCR0A = _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(CS00); break; case CMD_FADE_DOWN: light = L_FDOWN; OCR0B = 255; TCCR0A = _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(CS00); break; } } else { forward_command(); } command = CMD_NONE; }