implem_command #9

Merged
statzitz merged 13 commits from implem_command into main 2024-04-18 01:30:48 +02:00
2 changed files with 26 additions and 45 deletions
Showing only changes of commit 14b762520f - Show all commits

View file

@ -13,39 +13,15 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
}, },
"u" => { "u" => {
// case where command is up // case where command is up
if sv.sent_signal(b"u") { return misc::run_verbose(sv.sent_signal(b"u"), true, verbose, svwait_var, sv);
if verbose == 1 {
return misc::run_verbose(true, svwait_var, sv);
} else {
return 0;
}
} else {
return 1;
}
}, },
"d" => { "d" => {
// case where command is up // case where command is up
if sv.sent_signal(b"d") { return misc::run_verbose(sv.sent_signal(b"d"), false, verbose, svwait_var, sv);
if verbose == 1 {
return misc::run_verbose(false, svwait_var, sv);
} else {
return 0;
}
} else {
return 1;
}
}, },
"o" => { "o" => {
// case where command is run once. // case where command is run once.
if sv.sent_signal(b"o") { return misc::run_verbose(sv.sent_signal(b"o"), true, verbose, svwait_var, sv);
if verbose == 1 {
return misc::run_verbose(true, svwait_var, sv);
} else {
return 0;
}
} else {
return 1;
}
}, },
other => { other => {
println!("Error, command {} not implemented.", other); // TODO : Put the real error println!("Error, command {} not implemented.", other); // TODO : Put the real error

View file

@ -24,9 +24,10 @@ pub fn print_status(mut sv: status_obj::StatusObj) -> i32 {
} }
pub fn run_verbose(state: bool, svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 { pub fn run_verbose(sent_signal: bool, state: bool, verbose: i8, svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 {
// if the state is true, wait for the service to run. // if the state is true, wait for the service to run.
// If the state is false, wait for the service to down. // If the state is false, wait for the service to down.
if sent_signal && verbose == 1 {
let mut time_wait = 0; let mut time_wait = 0;
loop { loop {
let status = sv.update_status(); let status = sv.update_status();
@ -41,9 +42,13 @@ pub fn run_verbose(state: bool, svwait_var: i32, mut sv: status_obj::StatusObj)
println!("timeout: {}", sv.get_status_string()); println!("timeout: {}", sv.get_status_string());
return 1 return 1
} }
time_wait += 1; time_wait += 1;
sleep(Duration::from_secs(1)); sleep(Duration::from_secs(1));
} }
} else if sent_signal && verbose == 0 {
return 0
} else {
// Case sent_signal != true.
return 1
}
} }