use zvariant::ObjectPath;
use crate::{
object_server::{Interface, InterfaceDeref, InterfaceDerefMut, SignalEmitter},
utils::block_on,
Error, Result,
};
pub struct InterfaceRef<I> {
azync: crate::object_server::InterfaceRef<I>,
}
impl<I> InterfaceRef<I>
where
I: 'static,
{
pub fn get(&self) -> InterfaceDeref<'_, I> {
block_on(self.azync.get())
}
pub fn get_mut(&self) -> InterfaceDerefMut<'_, I> {
block_on(self.azync.get_mut())
}
pub fn signal_emitter(&self) -> &SignalEmitter<'static> {
self.azync.signal_emitter()
}
}
#[derive(Debug, Clone)]
pub struct ObjectServer {
azync: crate::ObjectServer,
}
impl ObjectServer {
pub(crate) fn new(conn: &crate::Connection) -> Self {
Self {
azync: conn.object_server().clone(),
}
}
pub fn at<'p, P, I>(&self, path: P, iface: I) -> Result<bool>
where
I: Interface,
P: TryInto<ObjectPath<'p>>,
P::Error: Into<Error>,
{
block_on(self.azync.at(path, iface))
}
pub fn remove<'p, I, P>(&self, path: P) -> Result<bool>
where
I: Interface,
P: TryInto<ObjectPath<'p>>,
P::Error: Into<Error>,
{
block_on(self.azync.remove::<I, P>(path))
}
pub fn interface<'p, P, I>(&self, path: P) -> Result<InterfaceRef<I>>
where
I: Interface,
P: TryInto<ObjectPath<'p>>,
P::Error: Into<Error>,
{
Ok(InterfaceRef {
azync: block_on(self.azync.interface(path))?,
})
}
pub fn inner(&self) -> &crate::ObjectServer {
&self.azync
}
pub fn into_inner(self) -> crate::ObjectServer {
self.azync
}
}
impl From<crate::ObjectServer> for ObjectServer {
fn from(azync: crate::ObjectServer) -> Self {
Self { azync }
}
}