struct Debug<'a> {
msg: &'a [String],
}
#[cfg(feature = "enable_debug")]
macro_rules! debug_println {
($($arg:tt)*) => {
println!($($arg)*);
}
}
#[cfg(not(feature = "enable_debug"))]
macro_rules! debug_println {
($($arg:tt)*) => {};
}
extern "C" {
fn is_debug() -> bool;
}
impl<'a> Debug<'a> {
fn new() -> Debug<'a>
{
Debug { msg: &[] }
}
fn print_msg_arg(&self, msg: &'a [String]) -> Debug<'a> {
debug_println!("<------------- DEBUG -------------------->");
debug_println!("Arguments:");
for arg in msg {
debug_println!(" {}", arg);
}
Debug { msg: &[] }
}
#[cfg(not(windows))]
fn handle_dbus_connection(&self, connection: Result<Connection, dbus::Error>) -> Debug<'a> {
match connection {
Ok(_) => {
self.print("D-Bus connection successfully established.");
}
Err(err) => {
let error_message = format!("Failed to establish D-Bus connection {}", err);
self.error(&error_message);
}
}
Debug { msg: self.msg }
}
fn print(&self, arg: &'a str) -> Debug<'a> {
debug_println!("<------------- DEBUG -------------------->");
debug_println!("{}", arg);
Debug { msg: self.msg }
}
fn error(&self, arg: &'a str) -> Debug<'a> {
eprintln!("Error: {}", arg);
Debug { msg: self.msg }
}
}