1 | // Copyright 2022 The AccessKit Authors. All rights reserved. |
2 | // Licensed under the Apache License, Version 2.0 (found in |
3 | // the LICENSE-APACHE file) or the MIT license (found in |
4 | // the LICENSE-MIT file), at your option. |
5 | |
6 | use atspi::Accessible; |
7 | use serde::{Deserialize, Serialize}; |
8 | use zbus::{ |
9 | names::{OwnedUniqueName, UniqueName}, |
10 | zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Type, Value}, |
11 | }; |
12 | |
13 | const NULL_PATH: &str = "/org/a11y/atspi/null" ; |
14 | |
15 | #[derive (Clone, Debug, Serialize, Deserialize, PartialEq, Eq, OwnedValue, Type, Value)] |
16 | pub(crate) struct OwnedObjectAddress { |
17 | bus_name: OwnedUniqueName, |
18 | path: OwnedObjectPath, |
19 | } |
20 | |
21 | impl OwnedObjectAddress { |
22 | pub(crate) fn new(bus_name: OwnedUniqueName, path: OwnedObjectPath) -> Self { |
23 | Self { bus_name, path } |
24 | } |
25 | |
26 | pub(crate) fn null(bus_name: OwnedUniqueName) -> Self { |
27 | Self { |
28 | bus_name, |
29 | path: ObjectPath::from_str_unchecked(NULL_PATH).into(), |
30 | } |
31 | } |
32 | } |
33 | |
34 | impl From<Accessible> for OwnedObjectAddress { |
35 | fn from(object: Accessible) -> Self { |
36 | Self { |
37 | bus_name: OwnedUniqueName::from(UniqueName::from_string_unchecked(object.name)), |
38 | path: object.path, |
39 | } |
40 | } |
41 | } |
42 | |