use std::{convert::TryInto, ops::Deref};
use static_assertions::assert_impl_all;
use zvariant::ObjectPath;
use crate::{
utils::block_on, Error, Interface, InterfaceDeref, InterfaceDerefMut, Result, SignalContext,
};
pub struct InterfaceRef<I> {
azync: crate::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_context(&self) -> &SignalContext<'static> {
self.azync.signal_context()
}
}
#[derive(Debug)]
pub struct ObjectServer {
azync: crate::ObjectServer,
}
assert_impl_all!(ObjectServer: Send, Sync, Unpin);
impl ObjectServer {
pub(crate) fn new(conn: &crate::Connection) -> Self {
Self {
azync: crate::ObjectServer::new(conn),
}
}
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 Deref for ObjectServer {
type Target = crate::ObjectServer;
fn deref(&self) -> &Self::Target {
self.inner()
}
}
impl From<crate::ObjectServer> for ObjectServer {
fn from(azync: crate::ObjectServer) -> Self {
Self { azync }
}
}