atspi_common/events/
cache.rs

1use crate::{
2	cache::{CacheItem, LegacyCacheItem},
3	events::{BusProperties, ObjectRef},
4	EventProperties,
5};
6#[cfg(feature = "zbus")]
7use crate::{
8	error::AtspiError,
9	events::{MessageConversion, MessageConversionExt},
10};
11use serde::{Deserialize, Serialize};
12use zbus_names::UniqueName;
13use zvariant::ObjectPath;
14
15/// Type that contains the `zbus::Message` for meta information and
16/// the [`crate::cache::LegacyCacheItem`]
17#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]
18pub struct LegacyAddAccessibleEvent {
19	/// The [`ObjectRef`] the event applies to.
20	pub item: ObjectRef,
21	/// A cache item to add to the internal cache.
22	pub node_added: LegacyCacheItem,
23}
24
25event_test_cases!(LegacyAddAccessibleEvent, Explicit);
26impl_from_dbus_message!(LegacyAddAccessibleEvent, Explicit);
27impl_event_properties!(LegacyAddAccessibleEvent);
28impl_to_dbus_message!(LegacyAddAccessibleEvent);
29
30impl BusProperties for LegacyAddAccessibleEvent {
31	const REGISTRY_EVENT_STRING: &'static str = "Cache:Add";
32	const MATCH_RULE_STRING: &'static str =
33		"type='signal',interface='org.a11y.atspi.Cache',member='AddAccessible'";
34	const DBUS_MEMBER: &'static str = "AddAccessible";
35	const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Cache";
36}
37
38#[cfg(feature = "zbus")]
39impl MessageConversion for LegacyAddAccessibleEvent {
40	type Body = LegacyCacheItem;
41
42	fn from_message_unchecked_parts(item: ObjectRef, body: Self::Body) -> Result<Self, AtspiError> {
43		Ok(Self { item, node_added: body })
44	}
45	fn from_message_unchecked(msg: &zbus::Message) -> Result<Self, AtspiError> {
46		let item = msg.try_into()?;
47		let body = msg.body().deserialize()?;
48		Self::from_message_unchecked_parts(item, body)
49	}
50
51	fn body(&self) -> Self::Body {
52		self.node_added.clone()
53	}
54}
55
56/// Type that contains the `zbus::Message` for meta information and
57/// the [`crate::cache::CacheItem`]
58#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]
59pub struct AddAccessibleEvent {
60	/// The [`ObjectRef`] the event applies to.
61	pub item: ObjectRef,
62	/// A cache item to add to the internal cache.
63	pub node_added: CacheItem,
64}
65
66event_test_cases!(AddAccessibleEvent, Explicit);
67
68impl BusProperties for AddAccessibleEvent {
69	const REGISTRY_EVENT_STRING: &'static str = "Cache:Add";
70	const MATCH_RULE_STRING: &'static str =
71		"type='signal',interface='org.a11y.atspi.Cache',member='AddAccessible'";
72	const DBUS_MEMBER: &'static str = "AddAccessible";
73	const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Cache";
74}
75
76#[cfg(feature = "zbus")]
77impl MessageConversion for AddAccessibleEvent {
78	type Body = CacheItem;
79
80	fn from_message_unchecked_parts(item: ObjectRef, body: Self::Body) -> Result<Self, AtspiError> {
81		Ok(Self { item, node_added: body })
82	}
83	fn from_message_unchecked(msg: &zbus::Message) -> Result<Self, AtspiError> {
84		let item = msg.try_into()?;
85		let body = msg.body().deserialize()?;
86		Self::from_message_unchecked_parts(item, body)
87	}
88
89	fn body(&self) -> Self::Body {
90		self.node_added.clone()
91	}
92}
93
94impl_from_dbus_message!(AddAccessibleEvent, Explicit);
95impl_event_properties!(AddAccessibleEvent);
96impl_to_dbus_message!(AddAccessibleEvent);
97
98/// `Cache::RemoveAccessible` signal event type.
99#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]
100pub struct RemoveAccessibleEvent {
101	/// The application that emitted the signal TODO Check Me
102	/// The [`ObjectRef`] the event applies to.
103	pub item: ObjectRef,
104	/// The node that was removed from the application tree  TODO Check Me
105	pub node_removed: ObjectRef,
106}
107
108event_test_cases!(RemoveAccessibleEvent, Explicit);
109
110impl BusProperties for RemoveAccessibleEvent {
111	const REGISTRY_EVENT_STRING: &'static str = "Cache:Remove";
112	const MATCH_RULE_STRING: &'static str =
113		"type='signal',interface='org.a11y.atspi.Cache',member='RemoveAccessible'";
114	const DBUS_MEMBER: &'static str = "RemoveAccessible";
115	const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Cache";
116}
117
118#[cfg(feature = "zbus")]
119impl MessageConversion for RemoveAccessibleEvent {
120	type Body = ObjectRef;
121
122	fn from_message_unchecked_parts(item: ObjectRef, body: Self::Body) -> Result<Self, AtspiError> {
123		Ok(Self { item, node_removed: body })
124	}
125	fn from_message_unchecked(msg: &zbus::Message) -> Result<Self, AtspiError> {
126		let item = msg.try_into()?;
127		let body = msg.body().deserialize()?;
128		Self::from_message_unchecked_parts(item, body)
129	}
130	fn body(&self) -> Self::Body {
131		self.node_removed.clone()
132	}
133}
134
135impl_from_dbus_message!(RemoveAccessibleEvent, Explicit);
136impl_event_properties!(RemoveAccessibleEvent);
137impl_to_dbus_message!(RemoveAccessibleEvent);