diwic / dbus-rs

D-Bus binding for the Rust language
Other
589 stars 133 forks source link

Update monitor example to match dbus-monitor a little better #435

Closed acheronfail closed 1 year ago

acheronfail commented 1 year ago

This updates the monitor.rs example to more closely match dbus-monitor.

dbus-monitor's source can be found here.

acheronfail commented 1 year ago

Testing with the MatchRule set to:

MatchRule::new()
  .with_interface("org.freedesktop.NetworkManager")
  .with_type(dbus::MessageType::Signal)

Provides this:

❯ cargo run --example monitor -- --system
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/examples/monitor --system`
Failed to BecomeMonitor: 'Rejected send message, 1 matched rules; type="method_call", sender=":1.101" (uid=1000 pid=24838 comm="target/debug/examples/monitor --system") interface="org.freedesktop.DBus.Monitoring" member="BecomeMonitor" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)', falling back to eavesdrop
Failed to eavesdrop: 'rejected attempt to call AddMatch by connection :1.101 (uid=1000 pid=24838 comm="target/debug/examples/monitor --system") with uid 1000', trying without it
Got message: Message { Type: Signal, Path: "/org/freedesktop/NetworkManager", Interface: "org.freedesktop.NetworkManager", Member: "StateChanged", Sender: ":1.5", Serial: 1512, Args: [50] }
Got message: Message { Type: Signal, Path: "/org/freedesktop/NetworkManager", Interface: "org.freedesktop.NetworkManager", Member: "StateChanged", Sender: ":1.5", Serial: 1541, Args: [20] }
Got message: Message { Type: Signal, Path: "/org/freedesktop/NetworkManager", Interface: "org.freedesktop.NetworkManager", Member: "StateChanged", Sender: ":1.5", Serial: 1588, Args: [40] }
Got message: Message { Type: Signal, Path: "/org/freedesktop/NetworkManager", Interface: "org.freedesktop.NetworkManager", Member: "StateChanged", Sender: ":1.5", Serial: 1644, Args: [60] }
Got message: Message { Type: Signal, Path: "/org/freedesktop/NetworkManager", Interface: "org.freedesktop.NetworkManager", Member: "StateChanged", Sender: ":1.5", Serial: 1665, Args: [70] }

which mimics the behaviour of dbus-monitor in these edge cases.