1use crate::{InterfaceSet, ObjectRef, Role, StateSet};
5use serde::{Deserialize, Serialize};
6use zbus_lockstep_macros::validate;
7use zbus_names::UniqueName;
8use zvariant::{ObjectPath, Type};
9
10#[allow(clippy::module_name_repetitions)]
12#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
13#[validate(signal: "AddAccessible")]
14pub struct CacheItem {
15 pub object: ObjectRef,
17 pub app: ObjectRef,
19 pub parent: ObjectRef,
21 pub index: i32,
23 pub children: i32,
25 pub ifaces: InterfaceSet,
27 pub short_name: String,
29 pub role: Role,
31 pub name: String,
33 pub states: StateSet,
35}
36
37impl Default for CacheItem {
38 fn default() -> Self {
39 Self {
40 object: ObjectRef {
41 name: UniqueName::from_static_str(":0.0").unwrap().into(),
42 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/object")
43 .unwrap()
44 .into(),
45 },
46 app: ObjectRef {
47 name: UniqueName::from_static_str(":0.0").unwrap().into(),
48 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/application")
49 .unwrap()
50 .into(),
51 },
52 parent: ObjectRef {
53 name: UniqueName::from_static_str(":0.0").unwrap().into(),
54 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/parent")
55 .unwrap()
56 .into(),
57 },
58 index: 0,
59 children: 0,
60 ifaces: InterfaceSet::empty(),
61 short_name: String::default(),
62 role: Role::Invalid,
63 name: String::default(),
64 states: StateSet::empty(),
65 }
66 }
67}
68
69#[allow(clippy::module_name_repetitions)]
71#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
72pub struct LegacyCacheItem {
73 pub object: ObjectRef,
75 pub app: ObjectRef,
77 pub parent: ObjectRef,
79 pub children: Vec<ObjectRef>,
81 pub ifaces: InterfaceSet,
83 pub short_name: String,
85 pub role: Role,
87 pub name: String,
89 pub states: StateSet,
91}
92impl Default for LegacyCacheItem {
93 fn default() -> Self {
94 Self {
95 object: ObjectRef {
96 name: UniqueName::from_static_str(":0.0").unwrap().into(),
97 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/object")
98 .unwrap()
99 .into(),
100 },
101 app: ObjectRef {
102 name: UniqueName::from_static_str(":0.0").unwrap().into(),
103 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/application")
104 .unwrap()
105 .into(),
106 },
107 parent: ObjectRef {
108 name: UniqueName::from_static_str(":0.0").unwrap().into(),
109 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/parent")
110 .unwrap()
111 .into(),
112 },
113 children: Vec::new(),
114 ifaces: InterfaceSet::empty(),
115 short_name: String::default(),
116 role: Role::Invalid,
117 name: String::default(),
118 states: StateSet::empty(),
119 }
120 }
121}
122
123#[cfg(test)]
124#[test]
125fn zvariant_type_signature_of_legacy_cache_item() {
126 use std::str::FromStr;
127 assert_eq!(
128 *<LegacyCacheItem as Type>::SIGNATURE,
129 zbus::zvariant::Signature::from_str("((so)(so)(so)a(so)assusau)").unwrap()
130 );
131}