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

Stricten type of ObjectRef::name #186

Merged
merged 6 commits into from
May 24, 2024
Merged
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
14 changes: 7 additions & 7 deletions atspi-common/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::{InterfaceSet, ObjectRef, Role, StateSet};
use serde::{Deserialize, Serialize};
use zbus_lockstep_macros::validate;
use zbus_names::BusName;
use zbus_names::UniqueName;
use zvariant::{ObjectPath, Type};

/// The item type provided by `Cache:Add` signals
Expand Down Expand Up @@ -38,19 +38,19 @@ impl Default for CacheItem {
fn default() -> Self {
Self {
object: ObjectRef {
name: BusName::from_static_str(":0.0").unwrap().into(),
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/object")
.unwrap()
.into(),
},
app: ObjectRef {
name: BusName::from_static_str(":0.0").unwrap().into(),
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/application")
.unwrap()
.into(),
},
parent: ObjectRef {
name: BusName::from_static_str(":0.0").unwrap().into(),
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/parent")
.unwrap()
.into(),
Expand Down Expand Up @@ -93,19 +93,19 @@ impl Default for LegacyCacheItem {
fn default() -> Self {
Self {
object: ObjectRef {
name: BusName::from_static_str(":0.0").unwrap().into(),
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/object")
.unwrap()
.into(),
},
app: ObjectRef {
name: BusName::from_static_str(":0.0").unwrap().into(),
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/application")
.unwrap()
.into(),
},
parent: ObjectRef {
name: BusName::from_static_str(":0.0").unwrap().into(),
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/parent")
.unwrap()
.into(),
Expand Down
4 changes: 2 additions & 2 deletions atspi-common/src/events/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties,
};
use zbus_names::BusName;
use zbus_names::UniqueName;
use zvariant::{ObjectPath, OwnedValue};

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -76,7 +76,7 @@ impl EventProperties for DocumentEvents {
Self::PageChanged(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::LoadComplete(inner) => inner.sender(),
Self::Reload(inner) => inner.sender(),
Expand Down
4 changes: 2 additions & 2 deletions atspi-common/src/events/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties,
};
use zbus_names::BusName;
use zbus_names::UniqueName;
use zvariant::{ObjectPath, OwnedValue};

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -41,7 +41,7 @@ impl EventProperties for FocusEvents {
Self::Focus(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::Focus(inner) => inner.sender(),
}
Expand Down
4 changes: 2 additions & 2 deletions atspi-common/src/events/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties,
};
use zbus_names::BusName;
use zbus_names::UniqueName;
use zvariant::{ObjectPath, OwnedValue};

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -41,7 +41,7 @@ impl EventProperties for KeyboardEvents {
Self::Modifiers(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::Modifiers(inner) => inner.sender(),
}
Expand Down
17 changes: 8 additions & 9 deletions atspi-common/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use zbus_lockstep_macros::validate;
use zbus_names::{BusName, OwnedBusName, OwnedUniqueName, UniqueName};
use zbus_names::{OwnedUniqueName, UniqueName};
#[cfg(feature = "zbus")]
use zvariant::OwnedObjectPath;
use zvariant::{ObjectPath, OwnedValue, Signature, Type, Value};
Expand Down Expand Up @@ -60,7 +60,7 @@ pub struct EventBody<'a, T> {
/// Map of string to an any type.
/// This is not used for anything, but it is defined by AT-SPI.
#[serde(borrow)]
pub properties: HashMap<BusName<'a>, Value<'a>>,
pub properties: HashMap<UniqueName<'a>, Value<'a>>,
}

impl<T> Type for EventBody<'_, T> {
Expand Down Expand Up @@ -120,7 +120,7 @@ pub struct EventBodyOwned {
pub any_data: OwnedValue,
/// A map of properties.
/// Not in use.
pub properties: HashMap<OwnedBusName, OwnedValue>,
pub properties: HashMap<OwnedUniqueName, OwnedValue>,
}

impl From<EventBodyQT> for EventBodyOwned {
Expand Down Expand Up @@ -301,7 +301,7 @@ impl EventProperties for Event {
Self::Listener(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::Document(inner) => inner.sender(),
Self::Focus(inner) => inner.sender(),
Expand Down Expand Up @@ -387,7 +387,7 @@ impl EventProperties for CacheEvents {
Self::Remove(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::Add(inner) => inner.sender(),
Self::LegacyAdd(inner) => inner.sender(),
Expand Down Expand Up @@ -572,8 +572,7 @@ impl TryFrom<&zbus::Message> for ObjectRef {
let owned_path: OwnedObjectPath = path.clone().into();

let sender: UniqueName<'_> = header.sender().expect("No sender in header").into();
let bus_name: BusName<'_> = sender.into();
let name: OwnedBusName = bus_name.to_owned().into();
let name: OwnedUniqueName = sender.to_owned().into();

Ok(ObjectRef { name, path: owned_path })
}
Expand Down Expand Up @@ -670,7 +669,7 @@ impl EventProperties for EventListenerEvents {
Self::Deregistered(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::Registered(inner) => inner.sender(),
Self::Deregistered(inner) => inner.sender(),
Expand Down Expand Up @@ -921,7 +920,7 @@ assert_obj_safe!(EventTypeProperties);
///
/// This trait *is* object-safe.
pub trait EventProperties {
fn sender(&self) -> BusName<'_>;
fn sender(&self) -> UniqueName<'_>;
fn path(&self) -> ObjectPath<'_>;
fn object_ref(&self) -> ObjectRef {
ObjectRef { name: self.sender().into(), path: self.path().into() }
Expand Down
4 changes: 2 additions & 2 deletions atspi-common/src/events/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties,
};
use zbus_names::BusName;
use zbus_names::UniqueName;
use zvariant::ObjectPath;

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -55,7 +55,7 @@ impl EventProperties for MouseEvents {
Self::Button(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::Abs(inner) => inner.sender(),
Self::Rel(inner) => inner.sender(),
Expand Down
4 changes: 2 additions & 2 deletions atspi-common/src/events/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties, State,
};
use zbus_names::BusName;
use zbus_names::UniqueName;
use zvariant::{ObjectPath, OwnedValue, Value};

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -190,7 +190,7 @@ impl EventProperties for ObjectEvents {
Self::TextCaretMoved(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::PropertyChange(inner) => inner.sender(),
Self::BoundsChanged(inner) => inner.sender(),
Expand Down
4 changes: 2 additions & 2 deletions atspi-common/src/events/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties,
};
use zbus_names::BusName;
use zbus_names::UniqueName;
use zvariant::ObjectPath;

/// All events related to the `org.a11y.atspi.Event.Terminal` interface.
Expand Down Expand Up @@ -70,7 +70,7 @@ impl EventProperties for TerminalEvents {
Self::CharWidthChanged(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::LineChanged(inner) => inner.sender(),
Self::ColumnCountChanged(inner) => inner.sender(),
Expand Down
4 changes: 2 additions & 2 deletions atspi-common/src/events/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties,
};
use zbus_names::BusName;
use zbus_names::UniqueName;
use zvariant::ObjectPath;

/// All events on the `org.a11y.atspi.Event.Window` interface.
Expand Down Expand Up @@ -168,7 +168,7 @@ impl EventProperties for WindowEvents {
Self::Restyle(inner) => inner.path(),
}
}
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
match self {
Self::PropertyChange(inner) => inner.sender(),
Self::Minimize(inner) => inner.sender(),
Expand Down
8 changes: 4 additions & 4 deletions atspi-common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
///
/// ```ignore
/// impl EventProperties for TextCaretMovedEvent {
/// fn sender(&self) -> BusName<'_> {
/// fn sender(&self) -> UniqueName<'_> {
/// self.item.name.as_ref()
/// }
/// fn path(&self) -> ObjectPath<'_> {
Expand All @@ -20,7 +20,7 @@
macro_rules! impl_event_properties {
($type:ty) => {
impl EventProperties for $type {
fn sender(&self) -> BusName<'_> {
fn sender(&self) -> UniqueName<'_> {
self.item.name.as_ref()
}
fn path(&self) -> ObjectPath<'_> {
Expand Down Expand Up @@ -118,9 +118,9 @@ macro_rules! impl_from_user_facing_event_for_interface_event_enum {

/// Expands to a conversion given two arguments,
/// 1. the user facing event type `(inner_type)`
/// which relies on a conversion to its interface variant enum type variant.
/// which relies on a conversion to its interface variant enum type variant.
/// 2. the outer `Event::<Interface(<InterfaceEnum>)>` wrapper.,
/// the enum type and outtermost variant.
/// the enum type and outtermost variant.
///
/// ```ignore user facing type, outer event variant
/// impl_from_user_facing_type_for_event_enum!(StateChangedEvent, Event::Object);
Expand Down
6 changes: 3 additions & 3 deletions atspi-common/src/object_ref.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use zbus_lockstep_macros::validate;
use zbus_names::{BusName, OwnedBusName};
use zbus_names::{OwnedUniqueName, UniqueName};
use zvariant::{ObjectPath, OwnedObjectPath, Signature, Type};

pub const OBJECT_REF_SIGNATURE: Signature<'_> = Signature::from_static_str_unchecked("(so)");
Expand All @@ -16,14 +16,14 @@ pub const OBJECT_REF_SIGNATURE: Signature<'_> = Signature::from_static_str_unche
#[validate(signal: "Available")]
#[derive(Debug, Clone, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
pub struct ObjectRef {
pub name: OwnedBusName,
pub name: OwnedUniqueName,
pub path: OwnedObjectPath,
}

impl Default for ObjectRef {
fn default() -> Self {
ObjectRef {
name: BusName::from_static_str(":0.0").unwrap().into(),
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/null")
.unwrap()
.into(),
Expand Down
4 changes: 2 additions & 2 deletions atspi-common/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use atspi_connection::AccessibilityConnection;
use std::time::Duration;
use tokio_stream::StreamExt;
use zbus::Message;
use zbus_names::OwnedBusName;
use zbus_names::OwnedUniqueName;
use zvariant::OwnedObjectPath;

#[tokio::test]
Expand All @@ -19,7 +19,7 @@ async fn test_recv_remove_accessible() {

let msg = {
let remove_body = ObjectRef {
name: OwnedBusName::try_from(":69.420").unwrap(),
name: OwnedUniqueName::try_from(":69.420").unwrap(),
path: OwnedObjectPath::try_from("/org/a11y/atspi/accessible/remove").unwrap(),
};

Expand Down
6 changes: 3 additions & 3 deletions atspi-proxies/src/accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
type Error = AtspiError;
fn try_from(proxy: AccessibleProxy<'_>) -> Result<ObjectRef, Self::Error> {
Ok(ObjectRef {
name: proxy.inner().destination().to_owned().into(),
name: proxy.inner().destination().as_str().try_into()?,

Check warning on line 236 in atspi-proxies/src/accessible.rs

View check run for this annotation

Codecov / codecov/patch

atspi-proxies/src/accessible.rs#L236

Added line #L236 was not covered by tests
path: proxy.inner().path().to_string().try_into()?,
})
}
Expand All @@ -243,7 +243,7 @@
type Error = AtspiError;
fn try_from(proxy: &AccessibleProxy<'_>) -> Result<ObjectRef, Self::Error> {
Ok(ObjectRef {
name: proxy.inner().destination().to_owned().into(),
name: proxy.inner().destination().as_str().try_into()?,

Check warning on line 246 in atspi-proxies/src/accessible.rs

View check run for this annotation

Codecov / codecov/patch

atspi-proxies/src/accessible.rs#L246

Added line #L246 was not covered by tests
path: proxy.inner().path().to_string().try_into()?,
})
}
Expand All @@ -254,7 +254,7 @@
///
/// # Errors
///
/// `BusName` or `ObjectPath` are assumed to be valid because they are obtained from a valid `ObjectRef`.
/// `UniqueName` or `ObjectPath` are assumed to be valid because they are obtained from a valid `ObjectRef`.
/// If the builder is lacking the necessary parameters to build a proxy. See [`zbus::ProxyBuilder::build`].
/// If this method fails, you may want to check the `AccessibleProxy` default values for missing / invalid parameters.
fn as_accessible_proxy(
Expand Down
3 changes: 1 addition & 2 deletions atspi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ tracing = ["atspi-connection/tracing"]
atspi-common = { path = "../atspi-common", version = "0.5.0", default-features = false }
atspi-connection = { path = "../atspi-connection", version = "0.5.0", default-features = false, optional = true }
atspi-proxies = { path = "../atspi-proxies", version = "0.5.0", default-features = false, optional = true }
zbus = { workspace = true, optional = true }

zbus = { workspace = true, default-features = false, optional = true }

[[bench]]
name = "event_parsing"
Expand Down
Loading