1use std::fmt;
2
3macro_rules! object_type {
5 ($( ($x:ident, $version:ident) ),*) => {
6 #[derive(Debug, Eq, PartialEq, Clone)]
7 pub enum ObjectType {
8 $($x,)*
9 Other(String),
10 }
11
12 impl ObjectType {
13 pub(crate) fn from_str(s: &str) -> ObjectType {
14 match s {
15 $(
16 concat!("PipeWire:Interface:", stringify!($x)) => ObjectType::$x,
17 )*
18 s => ObjectType::Other(s.to_string()),
19 }
20 }
21
22 pub fn to_str(&self) -> &str {
23 match self {
24 $(
25 ObjectType::$x => concat!("PipeWire:Interface:", stringify!($x)),
26 )*
27 ObjectType::Other(s) => s,
28 }
29 }
30
31 pub(crate) fn client_version(&self) -> u32 {
32 match self {
33 $(
34 ObjectType::$x => pw_sys::$version,
35 )*
36 ObjectType::Other(_) => panic!("Invalid object type"),
37 }
38 }
39 }
40
41 impl fmt::Display for ObjectType {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 write!(f, "{}", self.to_str())
44 }
45 }
46 };
47}
48
49object_type![
50 (Client, PW_VERSION_CLIENT),
52 (ClientEndpoint, PW_VERSION_CLIENT_ENDPOINT),
53 (ClientNode, PW_VERSION_CLIENT_NODE),
54 (ClientSession, PW_VERSION_CLIENT_SESSION),
55 (Core, PW_VERSION_CORE),
56 (Device, PW_VERSION_DEVICE),
57 (Endpoint, PW_VERSION_ENDPOINT),
58 (EndpointLink, PW_VERSION_ENDPOINT_LINK),
59 (EndpointStream, PW_VERSION_ENDPOINT_STREAM),
60 (Factory, PW_VERSION_FACTORY),
61 (Link, PW_VERSION_LINK),
62 (Metadata, PW_VERSION_METADATA),
63 (Module, PW_VERSION_MODULE),
64 (Node, PW_VERSION_NODE),
65 (Port, PW_VERSION_PORT),
66 (Profiler, PW_VERSION_PROFILER),
67 (Registry, PW_VERSION_REGISTRY),
68 (Session, PW_VERSION_SESSION)
69];