Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zbus 5.0 #209

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = ["Michael Connor Buchan <[email protected]>", "Tait Hoyem <tait
rust-version = "1.75.0"

[workspace.dependencies]
zbus = { version = "4.2", default-features = false }
zbus = { version = "5.1", default-features = false }
tracing = "0.1.37"
enumflags2 = "0.7.7"

Expand Down
8 changes: 4 additions & 4 deletions atspi-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ tokio = ["zbus/tokio"]
enumflags2 = "0.7.7"
serde = "1.0"
static_assertions = "1.1.0"
zbus-lockstep = "0.4.4"
zbus-lockstep-macros = "0.4.4"
zbus_names = "3.0"
zvariant = { version = "4.1", default-features = false }
zbus-lockstep = { git = "https://github.com/luukvanderduim/zbus-lockstep", branch = "0.5.0-rc1" }
zbus-lockstep-macros = { git = "https://github.com/luukvanderduim/zbus-lockstep", branch = "0.5.0-rc1" }
zbus_names = "4.0"
zvariant = { version = "5.1", default-features = false }
zbus = { workspace = true, optional = true, default-features = false }

[dev-dependencies]
Expand Down
7 changes: 5 additions & 2 deletions atspi-common/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ mod test {
use super::Action;
use zbus_lockstep::method_return_signature;
use zvariant::Type;

#[test]
fn validate_action_signature() {
// signature is of type `a(sss)`, where `(sss)` is the type we're validating.
let action_signature =
method_return_signature!(member: "GetActions", interface: "org.a11y.atspi.Action")
.slice(1..);
assert_eq!(Action::signature(), action_signature);
.to_string_no_parens()
.split_off(1);

assert_eq!(Action::SIGNATURE.to_string(), action_signature);
}
}
40 changes: 37 additions & 3 deletions atspi-common/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,39 @@ use crate::{InterfaceSet, ObjectRef, Role, StateSet};
use serde::{Deserialize, Serialize};
use zbus_lockstep_macros::validate;
use zbus_names::UniqueName;
use zvariant::{ObjectPath, Type};
use zvariant::{
signature::{Child, Fields},
ObjectPath, Signature, Type,
};

// ((so)(so)(so)iiassusau)
pub const CACHE_ITEM_SIGNATURE: &Signature = &Signature::static_structure(&[
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
&Signature::I32,
&Signature::I32,
&Signature::Array(Child::Static { child: &Signature::Str }),
&Signature::Str,
&Signature::U32,
&Signature::Str,
&Signature::Array(Child::Static { child: &Signature::U32 }),
]);
pub const LEGACY_CACHE_ITEM_SIGNATURE: &Signature = &Signature::static_structure(&[
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
&Signature::Array(Child::Static {
child: &Signature::Structure(Fields::Static {
fields: &[&Signature::Str, &Signature::ObjectPath],
}),
}),
&Signature::Array(Child::Static { child: &Signature::Str }),
&Signature::Str,
&Signature::U32,
&Signature::Str,
&Signature::Array(Child::Static { child: &Signature::U32 }),
]);

/// The item type provided by `Cache:Add` signals
#[allow(clippy::module_name_repetitions)]
Expand Down Expand Up @@ -123,8 +155,10 @@ impl Default for LegacyCacheItem {
#[cfg(test)]
#[test]
fn zvariant_type_signature_of_legacy_cache_item() {
use std::str::FromStr;
assert_eq!(
LegacyCacheItem::signature(),
zbus::zvariant::Signature::from_static_str("((so)(so)(so)a(so)assusau)").unwrap()
*<LegacyCacheItem as Type>::SIGNATURE,
zbus::zvariant::Signature::from_str("((so)(so)(so)a(so)assusau)").unwrap()
);
assert_eq!(<LegacyCacheItem as Type>::SIGNATURE, LEGACY_CACHE_ITEM_SIGNATURE,);
}
4 changes: 3 additions & 1 deletion atspi-common/src/events/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ pub struct AttributesChangedEvent {
pub item: crate::events::ObjectRef,
}

/// The focused page has changed. This event is usually sent only by document readers, signaling
/// The focused page has changed.
///
/// This event is usually sent only by document readers, signaling
/// that the _physical page equivalent is now different.
/// This event does not encode _which_ page is the new one, only that a new page is now the primary
/// one.
Expand Down
124 changes: 91 additions & 33 deletions atspi-common/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,43 @@ pub mod window;
// specific signal types with TryFrom implementations. See crate::[`identify`]
// EVENT_LISTENER_SIGNATURE is a type signature used to notify when events are registered or deregistered.
// CACHE_ADD_SIGNATURE and *_REMOVE have very different types
pub const ATSPI_EVENT_SIGNATURE: Signature<'_> =
Signature::from_static_str_unchecked("(siiva{sv})");
pub const QSPI_EVENT_SIGNATURE: Signature<'_> = Signature::from_static_str_unchecked("(siiv(so))");
pub const EVENT_LISTENER_SIGNATURE: Signature<'_> = Signature::from_static_str_unchecked("(ss)");
pub const CACHE_ADD_SIGNATURE: Signature<'_> =
Signature::from_static_str_unchecked("((so)(so)(so)iiassusau)");
// Same as "(siiva{sv})"
pub const ATSPI_EVENT_SIGNATURE: &Signature = &Signature::static_structure(&[
&Signature::Str,
&Signature::I32,
&Signature::I32,
&Signature::Variant,
&Signature::Dict {
key: Child::Static { child: &Signature::Str },
value: Child::Static { child: &Signature::Variant },
},
]);
pub const EVENT_NAME_SIGNATURE: &Signature =
&Signature::static_structure(&[&Signature::Str, &Signature::Str]);
// Same as "(siiv(so))"
pub const QSPI_EVENT_SIGNATURE: &Signature = &Signature::static_structure(&[
&Signature::Str,
&Signature::I32,
&Signature::I32,
&Signature::Variant,
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
]);
// Same as "(so)"
pub const EVENT_LISTENER_SIGNATURE: &Signature =
&Signature::static_structure(&[&Signature::Str, &Signature::ObjectPath]);
// Same as "((so)(so)(so)iiassusau)"
pub const CACHE_ADD_SIGNATURE: &Signature = &Signature::static_structure(&[
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
&Signature::Structure(Fields::Static { fields: &[&Signature::Str, &Signature::ObjectPath] }),
&Signature::I32,
&Signature::I32,
&Signature::Array(Child::Static { child: &Signature::Str }),
&Signature::Str,
&Signature::U32,
&Signature::Str,
&Signature::Array(Child::Static { child: &Signature::U32 }),
]);

use std::collections::HashMap;

Expand All @@ -31,7 +62,10 @@ use zbus_lockstep_macros::validate;
use zbus_names::{OwnedUniqueName, UniqueName};
#[cfg(feature = "zbus")]
use zvariant::OwnedObjectPath;
use zvariant::{ObjectPath, OwnedValue, Signature, Type, Value};
use zvariant::{
signature::{Child, Fields},
ObjectPath, OwnedValue, Signature, Type, Value,
};

use crate::{
cache::{CacheItem, LegacyCacheItem},
Expand Down Expand Up @@ -319,6 +353,7 @@ impl HasRegistryEventString for EventListenerEvents {
}

/// All events related to the `org.a11y.atspi.Cache` interface.
///
/// Note that these are not telling the client that an item *has been added* to a cache.
/// It is telling the client "here is a bunch of information to store it in your cache".
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Eq, Hash)]
Expand Down Expand Up @@ -568,7 +603,7 @@ impl TryFrom<&zbus::Message> for EventBodyOwned {

fn try_from(message: &zbus::Message) -> Result<Self, Self::Error> {
let body = message.body();
let signature = body.signature().ok_or_else(|| AtspiError::MissingSignature)?;
let signature = body.signature();

if signature == QSPI_EVENT_SIGNATURE {
let qt_body = body.deserialize::<EventBodyQT>()?;
Expand Down Expand Up @@ -797,8 +832,7 @@ impl TryFrom<&zbus::Message> for Event {
let body = msg.body();
let header = msg.header();

let body_signature = body.signature().ok_or(AtspiError::MissingSignature)?;
let body_signature_str = body_signature.as_str();
let body_signature = body.signature();

let member = header.member().ok_or(AtspiError::MissingMember)?;
let member_str = member.as_str();
Expand All @@ -810,48 +844,70 @@ impl TryFrom<&zbus::Message> for Event {
// parentheses are not included in the signature.
// However, `Cache` signals are often emitted with outer parentheses, so we also need to
// match against the same signature, but with outer parentheses.
match (interface_str, member_str, body_signature_str) {
("org.a11y.atspi.Socket", "Available", "so") => {
match (interface_str, member_str, body_signature) {
("org.a11y.atspi.Socket", "Available", sig)
if sig == crate::object_ref::OBJECT_REF_SIGNATURE =>
{
Ok(AvailableEvent::try_from(msg)?.into())
}
("org.a11y.atspi.Event.Object", _, "siiva{sv}" | "siiv(so)") => {
("org.a11y.atspi.Event.Object", _, sig)
if sig == ATSPI_EVENT_SIGNATURE || sig == QSPI_EVENT_SIGNATURE =>
{
Ok(Event::Object(ObjectEvents::try_from(msg)?))
}
("org.a11y.atspi.Event.Document", _, "siiva{sv}" | "siiv(so)") => {
("org.a11y.atspi.Event.Document", _, sig)
if sig == ATSPI_EVENT_SIGNATURE || sig == QSPI_EVENT_SIGNATURE =>
{
Ok(Event::Document(DocumentEvents::try_from(msg)?))
}
("org.a11y.atspi.Event.Window", _, "siiva{sv}" | "siiv(so)") => {
("org.a11y.atspi.Event.Window", _, sig)
if sig == ATSPI_EVENT_SIGNATURE || sig == QSPI_EVENT_SIGNATURE =>
{
Ok(Event::Window(WindowEvents::try_from(msg)?))
}
("org.a11y.atspi.Event.Terminal", _, "siiva{sv}" | "siiv(so)") => {
("org.a11y.atspi.Event.Terminal", _, sig)
if sig == ATSPI_EVENT_SIGNATURE || sig == QSPI_EVENT_SIGNATURE =>
{
Ok(Event::Terminal(TerminalEvents::try_from(msg)?))
}
("org.a11y.atspi.Event.Mouse", _, "siiva{sv}" | "siiv(so)") => {
("org.a11y.atspi.Event.Mouse", _, sig)
if sig == ATSPI_EVENT_SIGNATURE || sig == QSPI_EVENT_SIGNATURE =>
{
Ok(Event::Mouse(MouseEvents::try_from(msg)?))
}
("org.a11y.atspi.Event.Focus", _, "siiva{sv}" | "siiv(so)") => {
("org.a11y.atspi.Event.Focus", _, sig)
if sig == ATSPI_EVENT_SIGNATURE || sig == QSPI_EVENT_SIGNATURE =>
{
Ok(Event::Focus(FocusEvents::try_from(msg)?))
}
("org.a11y.atspi.Event.Keyboard", _, "siiva{sv}" | "siiv(so)") => {
("org.a11y.atspi.Event.Keyboard", _, sig)
if sig == ATSPI_EVENT_SIGNATURE || sig == QSPI_EVENT_SIGNATURE =>
{
Ok(Event::Keyboard(KeyboardEvents::try_from(msg)?))
}
("org.a11y.atspi.Registry", "EventListenerRegistered", "ss") => {
("org.a11y.atspi.Registry", "EventListenerRegistered", sig)
if sig == EVENT_NAME_SIGNATURE =>
{
Ok(EventListenerRegisteredEvent::try_from(msg)?.into())
}
("org.a11y.atspi.Registry", "EventListenerDeregistered", "ss") => {
("org.a11y.atspi.Registry", "EventListenerDeregistered", sig)
if sig == EVENT_NAME_SIGNATURE =>
{
Ok(EventListenerDeregisteredEvent::try_from(msg)?.into())
}
(
"org.a11y.atspi.Cache",
"AddAccessible",
"(so)(so)(so)iiassusau" | "((so)(so)(so)iiassusau)",
) => Ok(AddAccessibleEvent::try_from(msg)?.into()),
(
"org.a11y.atspi.Cache",
"AddAccessible",
"(so)(so)(so)a(so)assusau" | "((so)(so)(so)a(so)assusau)",
) => Ok(LegacyAddAccessibleEvent::try_from(msg)?.into()),
("org.a11y.atspi.Cache", "RemoveAccessible", "so" | "(so)") => {
("org.a11y.atspi.Cache", "AddAccessible", sig)
if sig == crate::cache::CACHE_ITEM_SIGNATURE =>
{
Ok(AddAccessibleEvent::try_from(msg)?.into())
}
("org.a11y.atspi.Cache", "AddAccessible", sig)
if sig == crate::cache::LEGACY_CACHE_ITEM_SIGNATURE =>
{
Ok(LegacyAddAccessibleEvent::try_from(msg)?.into())
}
("org.a11y.atspi.Cache", "RemoveAccessible", sig)
if sig == crate::object_ref::OBJECT_REF_SIGNATURE =>
{
Ok(RemoveAccessibleEvent::try_from(msg)?.into())
}
(_iface, _method, sig) => Err(AtspiError::UnknownBusSignature(sig.to_string())),
Expand Down Expand Up @@ -955,6 +1011,7 @@ pub trait BusProperties {
}

/// A specific trait *only* to define match rules.
///
/// This is useful for event wrappers like [`ObjectEvents`], which, while it does not have other
/// information required to implement the [`BusProperties`] trait, you can indeed add a match rule
/// to the `DBus` connection to capture all sub events of [`ObjectEvents`].
Expand All @@ -968,6 +1025,7 @@ pub trait HasMatchRule {
}

/// A specific trait *only* to define registry event matches.
///
/// This is useful for event wrappers like [`ObjectEvents`], which, while it does not have other
/// information required to implement the [`BusProperties`] trait, you can indeed add a match rule
/// to the AT-SPI connection to subscribe to all sub events of [`ObjectEvents`].
Expand All @@ -987,7 +1045,7 @@ mod tests {

#[test]
fn check_event_body_qt_signature() {
assert_eq!(&<EventBodyQT as Type>::signature(), &QSPI_EVENT_SIGNATURE);
assert_eq!(<EventBodyQT as Type>::SIGNATURE, QSPI_EVENT_SIGNATURE);
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions atspi-common/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ impl ser::Serialize for InterfaceSet {
}

impl Type for InterfaceSet {
fn signature() -> Signature<'static> {
<Vec<String> as Type>::signature()
}
const SIGNATURE: &'static Signature = <Vec<String> as Type>::SIGNATURE;
}

impl FromIterator<Interface> for InterfaceSet {
Expand Down
Loading
Loading