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

Big Trait Changes #206

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
015ccc2
Split BusProperties into two traits
TTWNO Jun 27, 2024
dd10886
use new trait in sending event code
TTWNO Jun 27, 2024
6151aa5
Feature gate new MessageConversion trait behind 'zbus'
TTWNO Jun 28, 2024
a3f596f
Merge new event and body behaviour
TTWNO Jul 3, 2024
fe46a31
from_message_parts_unchecked -> try_from_message_unchecked
TTWNO Jun 28, 2024
5ad158f
Pass &Message to new try_from_message_unchecked
TTWNO Jun 28, 2024
bc865fe
Add macro to implement From<ObjectRef>
TTWNO Jun 28, 2024
6ad6a16
Fix missing doc link
TTWNO Jun 28, 2024
fe9da31
Auto-implement MessageConversion for trivial case.
TTWNO Jun 28, 2024
5add99d
Remove now unused From<UFET> for EventBodyOwned
TTWNO Jun 28, 2024
8578f85
Use full message to check tests
TTWNO Jun 28, 2024
1b2a734
Make sure to check signature validity before calling _unchecked
TTWNO Jun 28, 2024
0aa7380
Fix import
TTWNO Jun 28, 2024
e86643c
Fix additional imports
TTWNO Jun 28, 2024
5f52f93
Using a struct in a doc item is not considered 'using' it
TTWNO Jun 28, 2024
3368b83
Change trait bound to be more generic
TTWNO Jul 3, 2024
a9bb246
Use options instead of values
TTWNO Jul 5, 2024
a47aaf4
UnknownBusSignature -> SignatureMatch
TTWNO Jul 5, 2024
c4e0c1e
Add HasInterfaceName trait
TTWNO Jul 5, 2024
1b3791d
Use HasInterfaceName for ObjectEvents
TTWNO Jul 5, 2024
123e47d
Test specific errors instead of just any error
TTWNO Jul 5, 2024
df1e36b
Add new tests around message conversion
TTWNO Jul 5, 2024
e4359f2
Error order coherency
TTWNO Jul 5, 2024
e5a0374
Use and validate correct error types
TTWNO Jul 5, 2024
c9857a1
Add blanket impl for HasInterfaceName for T: BusProperties
TTWNO Jul 5, 2024
ad74e27
Use _unchecked in more places
TTWNO Jul 5, 2024
791dad3
Move CacheEvents and vairants into their own file
TTWNO Jul 5, 2024
5107e2c
Fix imports in test
TTWNO Jul 5, 2024
2ff735f
impl EventWrapperMessageConversion for FocusEvents
TTWNO Jul 5, 2024
9052cf5
Auto-impl interface checking
TTWNO Jul 5, 2024
d9204b6
Flag zbus-only trait imports
TTWNO Jul 5, 2024
c3bbdd2
Use unchecked interface when possible
TTWNO Jul 5, 2024
1b1f76c
Use constants instead of &str to match members, interfaces
TTWNO Jul 5, 2024
370c295
try_from_message_unchecked -> try_from_validated_message
TTWNO Jul 5, 2024
45d6cd0
Auto-impl MessageConversion::try_from_message for all event types
TTWNO Jul 5, 2024
855d4df
Use auto-impl for TryFrom<&Message>
TTWNO Jul 5, 2024
c7a657e
Add a test for try_from_validated_message; check it does not validate
TTWNO Jul 5, 2024
73c17b0
Test *AccessibleEvent with explicit bodies
TTWNO Jul 5, 2024
ba2df3b
Add new methods on trait `MessageConversion`
TTWNO Jul 5, 2024
96387e8
Modify macros to work with new decomposed event system
TTWNO Jul 5, 2024
866415b
impl try_from_validated_message_parts for any event that needs it
TTWNO Jul 5, 2024
31abd35
Make clippy happy
TTWNO Jul 5, 2024
cb70e23
Fix docs
TTWNO Jul 5, 2024
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
1 change: 1 addition & 0 deletions atspi-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ tokio-stream = { version = "0.1", default-features = false, features = ["time"]
tokio = { version = "1", default-features = false, features = ["macros", "rt-multi-thread"] }
tokio-test = "0.4.2"
zbus = { workspace = true }
assert_matches = "1.5.0"
6 changes: 3 additions & 3 deletions atspi-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
KindMatch(String),

/// To indicate a match or equality test on a signal body signature failed.
UnknownBusSignature(String),
SignatureMatch(String),

/// When matching on an unknown interface
UnknownInterface,
Expand Down Expand Up @@ -85,8 +85,8 @@
Self::KindMatch(e) => {
f.write_str(format!("atspi: kind mismatch in conversion: {e}").as_str())
}
Self::UnknownBusSignature(e) => {
f.write_str(format!("atspi: Unknown bus body signature: {e:?}").as_str())
Self::SignatureMatch(e) => {
f.write_str(format!("atspi: body signature mismatch in conversion: {e:?}").as_str())

Check warning on line 89 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L88-L89

Added lines #L88 - L89 were not covered by tests
}
Self::UnknownInterface => f.write_str("Unknown interface."),
Self::MissingInterface => f.write_str("Missing interface."),
Expand Down
286 changes: 286 additions & 0 deletions atspi-common/src/events/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
#[cfg(feature = "zbus")]
use crate::events::{EventWrapperMessageConversion, MessageConversion, TryFromMessage};
use crate::{
cache::{CacheItem, LegacyCacheItem},
error::AtspiError,
events::{BusProperties, HasInterfaceName, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties,
};
use serde::{Deserialize, Serialize};
use zbus_names::UniqueName;
use zvariant::ObjectPath;

/// 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)]

Check warning on line 16 in atspi-common/src/events/cache.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/events/cache.rs#L16

Added line #L16 was not covered by tests
#[allow(clippy::module_name_repetitions)]
pub enum CacheEvents {
/// See: [`AddAccessibleEvent`].
Add(AddAccessibleEvent),
/// See: [`LegacyAddAccessibleEvent`].
LegacyAdd(LegacyAddAccessibleEvent),
/// See: [`RemoveAccessibleEvent`].
Remove(RemoveAccessibleEvent),
}

impl HasMatchRule for CacheEvents {
const MATCH_RULE_STRING: &'static str = "type='signal',interface='org.a11y.atspi.Cache'";
}

impl HasRegistryEventString for CacheEvents {
const REGISTRY_EVENT_STRING: &'static str = "Cache";
}

impl HasInterfaceName for CacheEvents {
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Cache";
}

impl EventTypeProperties for CacheEvents {
fn member(&self) -> &'static str {
match self {
Self::Add(inner) => inner.member(),
Self::LegacyAdd(inner) => inner.member(),
Self::Remove(inner) => inner.member(),
}
}
fn interface(&self) -> &'static str {
match self {
Self::Add(inner) => inner.interface(),
Self::LegacyAdd(inner) => inner.interface(),
Self::Remove(inner) => inner.interface(),
}
}
fn match_rule(&self) -> &'static str {
match self {
Self::Add(inner) => inner.match_rule(),
Self::LegacyAdd(inner) => inner.match_rule(),
Self::Remove(inner) => inner.match_rule(),
}
}
fn registry_string(&self) -> &'static str {
match self {
Self::Add(inner) => inner.registry_string(),
Self::LegacyAdd(inner) => inner.registry_string(),
Self::Remove(inner) => inner.registry_string(),
}
}
}

impl EventProperties for CacheEvents {
fn path(&self) -> ObjectPath<'_> {
match self {
Self::Add(inner) => inner.path(),
Self::LegacyAdd(inner) => inner.path(),
Self::Remove(inner) => inner.path(),
}
}
fn sender(&self) -> UniqueName<'_> {
match self {
Self::Add(inner) => inner.sender(),
Self::LegacyAdd(inner) => inner.sender(),
Self::Remove(inner) => inner.sender(),
}
}
}

#[cfg(feature = "zbus")]
impl EventWrapperMessageConversion for CacheEvents {
fn try_from_message_interface_checked(msg: &zbus::Message) -> Result<Self, AtspiError> {
let header = msg.header();
let member = header.member().ok_or(AtspiError::MissingMember)?;
match member.as_str() {
AddAccessibleEvent::DBUS_MEMBER => {
let body = msg.body();
let sig = body.signature().ok_or(AtspiError::MissingSignature)?;
match sig.as_str() {
"(so)(so)(so)iiassusau" => {
Ok(CacheEvents::Add(AddAccessibleEvent::try_from_validated_message(msg)?))
}
"(so)(so)(so)a(so)assusau" => Ok(CacheEvents::LegacyAdd(
LegacyAddAccessibleEvent::try_from_validated_message(msg)?,
)),
_ => Err(AtspiError::SignatureMatch(format!(
"No matching event for signature {} in interface {}",
sig.as_str(),
Self::DBUS_INTERFACE
))),

Check warning on line 107 in atspi-common/src/events/cache.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/events/cache.rs#L103-L107

Added lines #L103 - L107 were not covered by tests
}
}
RemoveAccessibleEvent::DBUS_MEMBER => {
Ok(CacheEvents::Remove(RemoveAccessibleEvent::try_from_validated_message(msg)?))
}
_ => Err(AtspiError::MemberMatch(format!(
"No member {} in {}",
member.as_str(),
Self::DBUS_INTERFACE
))),

Check warning on line 117 in atspi-common/src/events/cache.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/events/cache.rs#L113-L117

Added lines #L113 - L117 were not covered by tests
}
}
}

#[cfg(feature = "zbus")]
impl TryFrom<&zbus::Message> for CacheEvents {
type Error = AtspiError;
fn try_from(msg: &zbus::Message) -> Result<Self, Self::Error> {
Self::try_from_message(msg)
}

Check warning on line 127 in atspi-common/src/events/cache.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/events/cache.rs#L125-L127

Added lines #L125 - L127 were not covered by tests
}

/// Type that contains the `zbus::Message` for meta information and
/// the [`crate::cache::LegacyCacheItem`]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]

Check warning on line 132 in atspi-common/src/events/cache.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/events/cache.rs#L132

Added line #L132 was not covered by tests
pub struct LegacyAddAccessibleEvent {
/// The [`ObjectRef`] the event applies to.
pub item: ObjectRef,
/// A cache item to add to the internal cache.
pub node_added: LegacyCacheItem,
}

impl_from_user_facing_event_for_interface_event_enum!(
LegacyAddAccessibleEvent,
CacheEvents,
CacheEvents::LegacyAdd
);
impl_from_user_facing_type_for_event_enum!(LegacyAddAccessibleEvent, Event::Cache);
impl_try_from_event_for_user_facing_type!(
LegacyAddAccessibleEvent,
CacheEvents::LegacyAdd,
Event::Cache
);
event_test_cases!(LegacyAddAccessibleEvent, Explicit);
impl_from_dbus_message!(LegacyAddAccessibleEvent, Explicit);
impl_event_properties!(LegacyAddAccessibleEvent);
impl_to_dbus_message!(LegacyAddAccessibleEvent);

impl BusProperties for LegacyAddAccessibleEvent {
const REGISTRY_EVENT_STRING: &'static str = "Cache:Add";
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Cache',member='AddAccessible'";
const DBUS_MEMBER: &'static str = "AddAccessible";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Cache";
}

#[cfg(feature = "zbus")]
impl MessageConversion for LegacyAddAccessibleEvent {
type Body = LegacyCacheItem;

fn try_from_validated_message_parts(
item: ObjectRef,
body: Self::Body,
) -> Result<Self, AtspiError> {
Ok(Self { item, node_added: body })
}
fn try_from_validated_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = msg.try_into()?;
let body = msg.body().deserialize()?;
Self::try_from_validated_message_parts(item, body)
}

fn body(&self) -> Self::Body {
self.node_added.clone()
}
}

/// Type that contains the `zbus::Message` for meta information and
/// the [`crate::cache::CacheItem`]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]

Check warning on line 187 in atspi-common/src/events/cache.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/events/cache.rs#L187

Added line #L187 was not covered by tests
pub struct AddAccessibleEvent {
/// The [`ObjectRef`] the event applies to.
pub item: ObjectRef,
/// A cache item to add to the internal cache.
pub node_added: CacheItem,
}

impl_from_user_facing_event_for_interface_event_enum!(
AddAccessibleEvent,
CacheEvents,
CacheEvents::Add
);
impl_from_user_facing_type_for_event_enum!(AddAccessibleEvent, Event::Cache);
impl_try_from_event_for_user_facing_type!(AddAccessibleEvent, CacheEvents::Add, Event::Cache);
event_test_cases!(AddAccessibleEvent, Explicit);

impl BusProperties for AddAccessibleEvent {
const REGISTRY_EVENT_STRING: &'static str = "Cache:Add";
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Cache',member='AddAccessible'";
const DBUS_MEMBER: &'static str = "AddAccessible";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Cache";
}

#[cfg(feature = "zbus")]
impl MessageConversion for AddAccessibleEvent {
type Body = CacheItem;

fn try_from_validated_message_parts(
item: ObjectRef,
body: Self::Body,
) -> Result<Self, AtspiError> {
Ok(Self { item, node_added: body })
}
fn try_from_validated_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = msg.try_into()?;
let body = msg.body().deserialize()?;
Self::try_from_validated_message_parts(item, body)
}

fn body(&self) -> Self::Body {
self.node_added.clone()
}
}

impl_from_dbus_message!(AddAccessibleEvent, Explicit);
impl_event_properties!(AddAccessibleEvent);
impl_to_dbus_message!(AddAccessibleEvent);

/// `Cache::RemoveAccessible` signal event type.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]

Check warning on line 238 in atspi-common/src/events/cache.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/events/cache.rs#L238

Added line #L238 was not covered by tests
pub struct RemoveAccessibleEvent {
/// The application that emitted the signal TODO Check Me
/// The [`ObjectRef`] the event applies to.
pub item: ObjectRef,
/// The node that was removed from the application tree TODO Check Me
pub node_removed: ObjectRef,
}

impl_from_user_facing_event_for_interface_event_enum!(
RemoveAccessibleEvent,
CacheEvents,
CacheEvents::Remove
);
impl_from_user_facing_type_for_event_enum!(RemoveAccessibleEvent, Event::Cache);
impl_try_from_event_for_user_facing_type!(RemoveAccessibleEvent, CacheEvents::Remove, Event::Cache);
event_test_cases!(RemoveAccessibleEvent, Explicit);

impl BusProperties for RemoveAccessibleEvent {
const REGISTRY_EVENT_STRING: &'static str = "Cache:Remove";
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Cache',member='RemoveAccessible'";
const DBUS_MEMBER: &'static str = "RemoveAccessible";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Cache";
}

#[cfg(feature = "zbus")]
impl MessageConversion for RemoveAccessibleEvent {
type Body = ObjectRef;

fn try_from_validated_message_parts(
item: ObjectRef,
body: Self::Body,
) -> Result<Self, AtspiError> {
Ok(Self { item, node_removed: body })
}
fn try_from_validated_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = msg.try_into()?;
let body = msg.body().deserialize()?;
Self::try_from_validated_message_parts(item, body)
}
fn body(&self) -> Self::Body {
self.node_removed.clone()
}
}

impl_from_dbus_message!(RemoveAccessibleEvent, Explicit);
impl_event_properties!(RemoveAccessibleEvent);
impl_to_dbus_message!(RemoveAccessibleEvent);
Loading
Loading