Skip to content

Commit

Permalink
Merge pull request #151 from zeenix/zb-5-port
Browse files Browse the repository at this point in the history
👽️ Port to latest zbus main (upcoming 5.0 release)
  • Loading branch information
zeenix authored Oct 14, 2024
2 parents bf8f6e1 + da2ed7a commit c7f8bd2
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 146 deletions.
99 changes: 12 additions & 87 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ name = "busd"
path = "src/bin/busd.rs"

[dependencies]
#zbus = { git = "https://github.com/dbus2/zbus/", features = [
zbus = { version = "4.2.0", features = [
zbus = { git = "https://github.com/dbus2/zbus/", features = [
#zbus = { version = "4.2.0", features = [
"tokio",
"bus-impl",
], default-features = false }
Expand Down
8 changes: 4 additions & 4 deletions src/bus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use tracing::{debug, info, trace, warn};
use zbus::address::transport::{Unix, UnixSocket};
use zbus::{
address::{transport::Tcp, Transport},
connection::socket::BoxedSplit,
Address, AuthMechanism, Connection, ConnectionBuilder, Guid, OwnedGuid,
connection::{self, socket::BoxedSplit},
Address, AuthMechanism, Connection, Guid, OwnedGuid,
};

use crate::{
Expand Down Expand Up @@ -83,15 +83,15 @@ impl Bus {
// Create a peer for ourselves.
trace!("Creating self-dial connection.");
let (client_socket, peer_socket) = zbus::connection::socket::Channel::pair();
let service_conn = ConnectionBuilder::authenticated_socket(client_socket, guid.clone())?
let service_conn = connection::Builder::authenticated_socket(client_socket, guid.clone())?
.p2p()
.unique_name(fdo::BUS_NAME)?
.name(fdo::BUS_NAME)?
.serve_at(fdo::DBus::PATH, dbus)?
.serve_at(fdo::Monitoring::PATH, monitoring)?
.build()
.await?;
let peer_conn = ConnectionBuilder::authenticated_socket(peer_socket, guid.clone())?
let peer_conn = connection::Builder::authenticated_socket(peer_socket, guid.clone())?
.p2p()
.build()
.await?;
Expand Down
30 changes: 14 additions & 16 deletions src/fdo/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use zbus::{
fdo::{
ConnectionCredentials, Error, ReleaseNameReply, RequestNameFlags, RequestNameReply, Result,
},
interface,
interface, message,
names::{BusName, InterfaceName, OwnedBusName, OwnedUniqueName, UniqueName, WellKnownName},
object_server::{ResponseDispatchNotifier, SignalEmitter},
zvariant::Optional,
MessageHeader, OwnedGuid, OwnedMatchRule, ResponseDispatchNotifier, SignalContext,
OwnedGuid, OwnedMatchRule,
};

use super::msg_sender;
Expand All @@ -37,7 +38,7 @@ impl DBus {
}

/// Helper for D-Bus methods that call a function on a peer.
async fn call_mut_on_peer<F, R>(&self, func: F, hdr: MessageHeader<'_>) -> Result<R>
async fn call_mut_on_peer<F, R>(&self, func: F, hdr: message::Header<'_>) -> Result<R>
where
F: FnOnce(&mut Peer) -> Result<R>,
{
Expand All @@ -64,8 +65,8 @@ impl DBus {
/// This is already called & handled and we only need to handle it once.
async fn hello(
&self,
#[zbus(header)] hdr: MessageHeader<'_>,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
#[zbus(header)] hdr: message::Header<'_>,
#[zbus(signal_emitter)] emitter: SignalEmitter<'_>,
) -> Result<ResponseDispatchNotifier<OwnedUniqueName>> {
let name = msg_sender(&hdr);
let peers = self.peers()?;
Expand All @@ -80,7 +81,7 @@ impl DBus {
// 2. The `Hello` response to arrive before the `NameAcquired` signal.
let unique_name = peer.unique_name().clone();
let (response, listener) = ResponseDispatchNotifier::new(unique_name.clone());
let ctxt = ctxt.to_owned();
let ctxt = emitter.to_owned();
spawn(async move {
listener.await;
let owner = UniqueName::from(unique_name);
Expand Down Expand Up @@ -110,7 +111,7 @@ impl DBus {
&self,
name: WellKnownName<'_>,
flags: BitFlags<RequestNameFlags>,
#[zbus(header)] hdr: MessageHeader<'_>,
#[zbus(header)] hdr: message::Header<'_>,
) -> Result<RequestNameReply> {
let unique_name = msg_sender(&hdr);
let peers = self.peers()?;
Expand All @@ -133,7 +134,7 @@ impl DBus {
async fn release_name(
&self,
name: WellKnownName<'_>,
#[zbus(header)] hdr: MessageHeader<'_>,
#[zbus(header)] hdr: message::Header<'_>,
) -> Result<ReleaseNameReply> {
let unique_name = msg_sender(&hdr);
let peers = self.peers()?;
Expand Down Expand Up @@ -175,7 +176,7 @@ impl DBus {
async fn add_match(
&self,
rule: OwnedMatchRule,
#[zbus(header)] hdr: MessageHeader<'_>,
#[zbus(header)] hdr: message::Header<'_>,
) -> Result<()> {
self.call_mut_on_peer(
move |peer| {
Expand All @@ -192,7 +193,7 @@ impl DBus {
async fn remove_match(
&self,
rule: OwnedMatchRule,
#[zbus(header)] hdr: MessageHeader<'_>,
#[zbus(header)] hdr: message::Header<'_>,
) -> Result<()> {
self.call_mut_on_peer(move |peer| peer.remove_match_rule(rule), hdr)
.await
Expand Down Expand Up @@ -384,20 +385,17 @@ impl DBus {
/// It's also the signal to use to detect the appearance of new names on the bus.
#[zbus(signal)]
pub async fn name_owner_changed(
signal_ctxt: &SignalContext<'_>,
emitter: &SignalEmitter<'_>,
name: BusName<'_>,
old_owner: Optional<UniqueName<'_>>,
new_owner: Optional<UniqueName<'_>>,
) -> zbus::Result<()>;

/// This signal is sent to a specific application when it loses ownership of a name.
#[zbus(signal)]
pub async fn name_lost(signal_ctxt: &SignalContext<'_>, name: BusName<'_>) -> zbus::Result<()>;
pub async fn name_lost(emitter: &SignalEmitter<'_>, name: BusName<'_>) -> zbus::Result<()>;

/// This signal is sent to a specific application when it gains ownership of a name.
#[zbus(signal)]
pub async fn name_acquired(
signal_ctxt: &SignalContext<'_>,
name: BusName<'_>,
) -> zbus::Result<()>;
pub async fn name_acquired(emitter: &SignalEmitter<'_>, name: BusName<'_>) -> zbus::Result<()>;
}
4 changes: 2 additions & 2 deletions src/fdo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ mod dbus;
pub use dbus::*;
mod monitoring;
pub use monitoring::*;
use zbus::{names::UniqueName, MessageHeader};
use zbus::{message, names::UniqueName};

pub const BUS_NAME: &str = "org.freedesktop.DBus";

/// Helper for getting the peer name from a message header.
fn msg_sender<'h>(hdr: &'h MessageHeader<'h>) -> &'h UniqueName<'h> {
fn msg_sender<'h>(hdr: &'h message::Header<'h>) -> &'h UniqueName<'h> {
// SAFETY: The bus (that's us!) is supposed to ensure a valid sender on the message.
hdr.sender().expect("Missing `sender` header")
}
8 changes: 4 additions & 4 deletions src/fdo/monitoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use tokio::spawn;
use tracing::{debug, warn};
use zbus::{
fdo::{Error, Result},
interface,
interface, message,
object_server::{ResponseDispatchNotifier, SignalEmitter},
zvariant::Optional,
MessageHeader, ResponseDispatchNotifier, SignalContext,
};

use super::msg_sender;
Expand Down Expand Up @@ -34,8 +34,8 @@ impl Monitoring {
&self,
match_rules: MatchRules,
_flags: u32,
#[zbus(header)] hdr: MessageHeader<'_>,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
#[zbus(header)] hdr: message::Header<'_>,
#[zbus(signal_emitter)] ctxt: SignalEmitter<'_>,
) -> Result<ResponseDispatchNotifier<()>> {
let owner = msg_sender(&hdr).to_owned();
let peers = self
Expand Down
Loading

0 comments on commit c7f8bd2

Please sign in to comment.