#![deny(warnings, clippy::all)]
#![forbid(unsafe_code)]
use logcontrol::{LogControl1Error, LogLevel};
use zbus::dbus_interface;
fn to_fdo_error(error: LogControl1Error) -> zbus::fdo::Error {
use LogControl1Error::*;
match error {
UnsupportedLogLevel(_) | UnsupportedLogTarget(_) => {
zbus::fdo::Error::NotSupported(error.to_string())
}
InputOutputError(error) => zbus::fdo::Error::IOError(error.to_string()),
Failure(msg) => zbus::fdo::Error::Failed(msg),
}
}
pub struct LogControl1<C>
where
C: logcontrol::LogControl1 + Send + Sync,
{
control: C,
}
impl<C> LogControl1<C>
where
C: logcontrol::LogControl1 + Send + Sync + 'static,
{
pub fn new(control: C) -> Self {
Self { control }
}
}
#[dbus_interface(name = "org.freedesktop.LogControl1")]
impl<C> LogControl1<C>
where
C: logcontrol::LogControl1 + Send + Sync + 'static,
{
#[dbus_interface(property)]
fn log_level(&self) -> String {
self.control.level().to_string()
}
#[dbus_interface(property)]
fn set_log_level(&mut self, level: String) -> zbus::fdo::Result<()> {
let level = LogLevel::try_from(level.as_str())
.map_err(|error| zbus::fdo::Error::InvalidArgs(error.to_string()))?;
self.control.set_level(level).map_err(to_fdo_error)
}
#[dbus_interface(property)]
fn log_target(&self) -> String {
self.control.target().to_string()
}
#[dbus_interface(property)]
async fn set_log_target(&mut self, target: String) -> zbus::fdo::Result<()> {
self.control.set_target(target).map_err(to_fdo_error)
}
#[dbus_interface(property)]
fn syslog_identifier(&self) -> &str {
self.control.syslog_identifier()
}
}