From d5064ae281b186247da1d48a54740c13515cf964 Mon Sep 17 00:00:00 2001 From: primardj Date: Mon, 15 Apr 2024 23:09:15 +0100 Subject: [PATCH] add o command and solve some littles problems with prints. --- .../sv-rustit/src/executor/sent_signal.rs | 34 +++++++++---------- .../src/executor/sent_signal/misc.rs | 26 ++++++++++++++ 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs b/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs index 761ae3d..0c6b121 100644 --- a/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs +++ b/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs @@ -21,23 +21,7 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_ // case where command is up if sv.sent_signal(b"u") { if verbose == 1 { - loop { - let status = sv.update_status(); - if status == 1 { - return 1; - } - if sv.is_up() == true { - misc::print_status(sv); - return 0 - } - if time_wait >= svwait_var { - println!("timeout: {}", sv.get_status_string()); - return 1 - } - - time_wait += 1; - sleep(Duration::from_secs(1)); - } + return misc::run_verbose(svwait_var, sv); } else { return 0; } @@ -56,7 +40,7 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_ return 1; } if sv.is_up() == false { - misc::print_status(sv); + println!("{}", sv.get_status_string()); return 0 } if time_wait >= svwait_var { @@ -75,8 +59,22 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_ } } + if command == "o" { + // case where command is run once. + if sv.sent_signal(b"o") { + if verbose == 1 { + return misc::run_verbose(svwait_var, sv); + } else { + return 0; + } + } else { + return 1; + } + } + println!("Error, command not implemented."); return 1; } + diff --git a/01_phase_rust_src/sv-rustit/src/executor/sent_signal/misc.rs b/01_phase_rust_src/sv-rustit/src/executor/sent_signal/misc.rs index 7a8e2a5..2addb04 100644 --- a/01_phase_rust_src/sv-rustit/src/executor/sent_signal/misc.rs +++ b/01_phase_rust_src/sv-rustit/src/executor/sent_signal/misc.rs @@ -1,6 +1,9 @@ use crate::status_obj; +use std::thread::sleep; +use std::time::Duration; + pub fn print_status(mut sv: status_obj::StatusObj) -> i32 { // The status code is the one who will be let mut status_sv = sv.get_status_string(); @@ -19,3 +22,26 @@ pub fn print_status(mut sv: status_obj::StatusObj) -> i32 { println!("{}", status_sv); return 0; } + + +pub fn run_verbose(svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 { + let mut time_wait = 0; + loop { + let status = sv.update_status(); + if status == 1 { + return 1; + } + if sv.is_up() == true { + println!("ok: {}", sv.get_status_string()); + return 0 + } + if time_wait >= svwait_var { + println!("timeout: {}", sv.get_status_string()); + return 1 + } + + time_wait += 1; + sleep(Duration::from_secs(1)); + } + +}