Skip to content

Commit

Permalink
Merge pull request #410 from elmarco/ns
Browse files Browse the repository at this point in the history
Some code shuffling
  • Loading branch information
elmarco authored Jul 29, 2023
2 parents 2228e5e + 3bc385c commit 74174f3
Show file tree
Hide file tree
Showing 41 changed files with 873 additions and 697 deletions.
2 changes: 1 addition & 1 deletion book-1.0/src/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ loop {
dbg!(&msg);
match msg_header.message_type()? {
zbus::MessageType::MethodCall => {
zbus::message::Type::MethodCall => {
// real code would check msg_header path(), interface() and member()
// handle invalid calls, introspection, errors etc
let arg: &str = msg.body()?;
Expand Down
4 changes: 2 additions & 2 deletions book/src/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ However, you can disabling caching for specific properties:
- Add the `#[dbus_proxy(property(emits_changed_signal = "false"))]` annotation to the property
for which you desire to disable caching on.

- Use `ProxyBuilder` to build your proxy instance and use `ProxyBuilder::uncached_properties` method
- Use `proxy::Builder` to build your proxy instance and use `proxy::Builder::uncached_properties` method
to list all properties you wish to disable caching for.

- In order to disable caching for either type of proxy use the `ProxyBuilder::cache_properites`
- In order to disable caching for either type of proxy use the `proxy::Builder::cache_properites`
method.

For more information about all the possible values for `emits_changed_signal` refer
Expand Down
4 changes: 2 additions & 2 deletions book/src/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ while let Some(msg) = stream.try_next().await? {
dbg!(&msg);
match msg_header.message_type()? {
zbus::MessageType::MethodCall => {
zbus::message::Type::MethodCall => {
// real code would check msg_header path(), interface() and member()
// handle invalid calls, introspection, errors etc
let arg: &str = msg.body()?;
Expand Down Expand Up @@ -206,7 +206,7 @@ synchronize with the interface handlers from outside, thanks to the `event_liste
(this is just one of the many ways).

```rust,no_run
# use zbus::{SignalContext, ConnectionBuilder, dbus_interface, fdo, Result};
# use zbus::{object_server::SignalContext, ConnectionBuilder, dbus_interface, fdo, Result};
#
use event_listener::Event;
Expand Down
15 changes: 13 additions & 2 deletions zbus/src/address.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//! D-Bus address handling.
//!
//! Server addresses consist of a transport name followed by a colon, and then an optional,
//! comma-separated list of keys and values in the form key=value.
//!
//! See also:
//!
//! * [Server addresses] in the D-Bus specification.
//!
//! [Server addresses]: https://dbus.freedesktop.org/doc/dbus-specification.html#addresses

#[cfg(target_os = "macos")]
use crate::process::run;
#[cfg(windows)]
Expand Down Expand Up @@ -695,8 +706,8 @@ impl TryFrom<&str> for Address {

#[cfg(test)]
mod tests {
use super::Address;
use crate::{Error, TcpAddress, TcpAddressFamily};
use super::{Address, TcpAddress, TcpAddressFamily};
use crate::Error;
use std::str::FromStr;
use test_log::test;

Expand Down
5 changes: 3 additions & 2 deletions zbus/src/blocking/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use zvariant::ObjectPath;
use crate::{
blocking::ObjectServer,
fdo::{ConnectionCredentials, RequestNameFlags, RequestNameReply},
message::Message,
utils::block_on,
DBusError, Error, Message, Result,
DBusError, Error, Result,
};

/// A blocking wrapper of [`zbus::Connection`].
Expand Down Expand Up @@ -167,7 +168,7 @@ impl Connection {
/// Returns the message serial number.
pub fn reply_dbus_error(
&self,
call: &zbus::MessageHeader<'_>,
call: &zbus::message::Header<'_>,
err: impl DBusError,
) -> Result<u32> {
block_on(self.inner.reply_dbus_error(call, err))
Expand Down
3 changes: 2 additions & 1 deletion zbus/src/blocking/connection_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use crate::{
address::Address,
blocking::Connection,
names::{UniqueName, WellKnownName},
object_server::Interface,
utils::block_on,
AuthMechanism, Error, Guid, Interface, Result,
AuthMechanism, Error, Guid, Result,
};

/// A builder for [`zbus::blocking::Connection`].
Expand Down
6 changes: 4 additions & 2 deletions zbus/src/blocking/message_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use futures_util::StreamExt;
use static_assertions::assert_impl_all;
use std::{convert::TryInto, sync::Arc};

use crate::{blocking::Connection, utils::block_on, MatchRule, Message, OwnedMatchRule, Result};
use crate::{
blocking::Connection, message::Message, utils::block_on, MatchRule, OwnedMatchRule, Result,
};

/// A blocking wrapper of [`crate::MessageStream`].
///
Expand Down Expand Up @@ -45,7 +47,7 @@ impl MessageIterator {
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let conn = Connection::session()?;
/// let rule = MatchRule::builder()
/// .msg_type(zbus::MessageType::Signal)
/// .msg_type(zbus::message::Type::Signal)
/// .sender("org.freedesktop.DBus")?
/// .interface("org.freedesktop.DBus")?
/// .member("NameOwnerChanged")?
Expand Down
31 changes: 25 additions & 6 deletions zbus/src/blocking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,29 @@ mod connection_builder;
pub use connection_builder::*;
mod message_iterator;
pub use message_iterator::*;
mod object_server;
pub use object_server::*;
mod proxy;
pub use proxy::*;
mod proxy_builder;
pub use proxy_builder::*;
pub mod object_server;
pub use object_server::ObjectServer;
pub mod proxy;
pub use proxy::Proxy;

#[deprecated(note = "Use `proxy::Builder` instead")]
#[doc(hidden)]
pub use proxy::Builder as ProxyBuilder;
#[deprecated(note = "Use `proxy::OwnerChangedIterator` instead")]
#[doc(hidden)]
pub use proxy::OwnerChangedIterator;
#[deprecated(note = "Use `proxy::PropertyChanged` instead")]
#[doc(hidden)]
pub use proxy::PropertyChanged;
#[deprecated(note = "Use `proxy::PropertyIterator` instead")]
#[doc(hidden)]
pub use proxy::PropertyIterator;
#[deprecated(note = "Use `proxy::SignalIterator` instead")]
#[doc(hidden)]
pub use proxy::SignalIterator;

#[deprecated(note = "Use `object_server::InterfaceRef` instead")]
#[doc(hidden)]
pub use object_server::InterfaceRef;

pub mod fdo;
8 changes: 6 additions & 2 deletions zbus/src/blocking/object_server.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
//! The object server API.

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,
object_server::{Interface, InterfaceDeref, InterfaceDerefMut, SignalContext},
utils::block_on,
Error, Result,
};

/// Wrapper over an interface, along with its corresponding `SignalContext`
/// instance. A reference to the underlying interface may be obtained via
/// [`InterfaceRef::get`] and [`InterfaceRef::get_mut`].
pub struct InterfaceRef<I> {
azync: crate::InterfaceRef<I>,
azync: crate::object_server::InterfaceRef<I>,
}

impl<I> InterfaceRef<I>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ use static_assertions::assert_impl_all;
use zbus_names::{BusName, InterfaceName};
use zvariant::ObjectPath;

use crate::{blocking::Connection, utils::block_on, CacheProperties, Error, Result};
use crate::{blocking::Connection, proxy::CacheProperties, utils::block_on, Error, Result};

pub use crate::ProxyDefault;
pub use crate::proxy::ProxyDefault;

/// Builder for proxies.
#[derive(Debug, Clone)]
pub struct ProxyBuilder<'a, T = ()>(crate::ProxyBuilder<'a, T>);
pub struct Builder<'a, T = ()>(crate::proxy::Builder<'a, T>);

assert_impl_all!(ProxyBuilder<'_>: Send, Sync, Unpin);
assert_impl_all!(Builder<'_>: Send, Sync, Unpin);

impl<'a, T> ProxyBuilder<'a, T> {
/// Create a new [`ProxyBuilder`] for the given connection.
impl<'a, T> Builder<'a, T> {
/// Create a new [`Builder`] for the given connection.
#[must_use]
pub fn new_bare(conn: &Connection) -> Self {
Self(crate::ProxyBuilder::new_bare(&conn.clone().into()))
Self(crate::proxy::Builder::new_bare(&conn.clone().into()))
}
}

impl<'a, T> ProxyBuilder<'a, T> {
impl<'a, T> Builder<'a, T> {
/// Set the proxy destination address.
pub fn destination<D>(self, destination: D) -> Result<Self>
where
D: TryInto<BusName<'a>>,
D::Error: Into<Error>,
{
crate::ProxyBuilder::destination(self.0, destination).map(Self)
crate::proxy::Builder::destination(self.0, destination).map(Self)
}

/// Set the proxy path.
Expand All @@ -38,7 +38,7 @@ impl<'a, T> ProxyBuilder<'a, T> {
P: TryInto<ObjectPath<'a>>,
P::Error: Into<Error>,
{
crate::ProxyBuilder::path(self.0, path).map(Self)
crate::proxy::Builder::path(self.0, path).map(Self)
}

/// Set the proxy interface.
Expand All @@ -47,7 +47,7 @@ impl<'a, T> ProxyBuilder<'a, T> {
I: TryInto<InterfaceName<'a>>,
I::Error: Into<Error>,
{
crate::ProxyBuilder::interface(self.0, interface).map(Self)
crate::proxy::Builder::interface(self.0, interface).map(Self)
}

/// Set whether to cache properties.
Expand Down Expand Up @@ -75,13 +75,13 @@ impl<'a, T> ProxyBuilder<'a, T> {
}
}

impl<'a, T> ProxyBuilder<'a, T>
impl<'a, T> Builder<'a, T>
where
T: ProxyDefault,
{
/// Create a new [`ProxyBuilder`] for the given connection.
/// Create a new [`Builder`] for the given connection.
#[must_use]
pub fn new(conn: &Connection) -> Self {
Self(crate::ProxyBuilder::new(&conn.clone().into()))
Self(crate::proxy::Builder::new(&conn.clone().into()))
}
}
17 changes: 12 additions & 5 deletions zbus/src/blocking/proxy.rs → zbus/src/blocking/proxy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! The client-side proxy API.

use enumflags2::BitFlags;
use futures_util::StreamExt;
use static_assertions::assert_impl_all;
Expand All @@ -9,10 +11,15 @@ use std::{
use zbus_names::{BusName, InterfaceName, MemberName, UniqueName};
use zvariant::{ObjectPath, OwnedValue, Value};

use crate::{blocking::Connection, utils::block_on, Error, Message, MethodFlags, Result};
use crate::{
blocking::Connection, message::Message, proxy::MethodFlags, utils::block_on, Error, Result,
};

use crate::fdo;

mod builder;
pub use builder::Builder;

/// A blocking wrapper of [`crate::Proxy`].
///
/// This API is mostly the same as [`crate::Proxy`], except that all its methods block to
Expand Down Expand Up @@ -378,7 +385,7 @@ impl std::ops::Drop for Proxy<'_> {
///
/// Use [`Proxy::receive_signal`] to create an instance of this type.
#[derive(Debug)]
pub struct SignalIterator<'a>(Option<crate::SignalStream<'a>>);
pub struct SignalIterator<'a>(Option<crate::proxy::SignalStream<'a>>);

impl<'a> SignalIterator<'a> {
/// The signal name.
Expand Down Expand Up @@ -410,7 +417,7 @@ impl std::ops::Drop for SignalIterator<'_> {
/// An [`std::iter::Iterator`] implementation that yields property change notifications.
///
/// Use [`Proxy::receive_property_changed`] to create an instance of this type.
pub struct PropertyIterator<'a, T>(crate::PropertyStream<'a, T>);
pub struct PropertyIterator<'a, T>(crate::proxy::PropertyStream<'a, T>);

impl<'a, T> std::iter::Iterator for PropertyIterator<'a, T>
where
Expand All @@ -426,7 +433,7 @@ where
/// A property changed event.
///
/// The property changed event generated by [`PropertyIterator`].
pub struct PropertyChanged<'a, T>(crate::PropertyChanged<'a, T>);
pub struct PropertyChanged<'a, T>(crate::proxy::PropertyChanged<'a, T>);

// split this out to avoid the trait bound on `name` method
impl<'a, T> PropertyChanged<'a, T> {
Expand Down Expand Up @@ -463,7 +470,7 @@ where
/// An [`std::iter::Iterator`] implementation that yields owner change notifications.
///
/// Use [`Proxy::receive_owner_changed`] to create an instance of this type.
pub struct OwnerChangedIterator<'a>(crate::OwnerChangedStream<'a>);
pub struct OwnerChangedIterator<'a>(crate::proxy::OwnerChangedStream<'a>);

impl OwnerChangedIterator<'_> {
/// The bus name being tracked.
Expand Down
Loading

0 comments on commit 74174f3

Please sign in to comment.