1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum Service {
7 AVTransport,
9
10 RenderingControl,
12
13 GroupRenderingControl,
15
16 ZoneGroupTopology,
18
19 GroupManagement,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct ServiceInfo {
26 pub endpoint: &'static str,
28
29 pub service_uri: &'static str,
31
32 pub event_endpoint: &'static str,
34}
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
38pub enum ServiceScope {
39 PerSpeaker,
41 PerNetwork,
43 PerCoordinator,
45}
46
47impl Service {
48 pub fn name(&self) -> &'static str {
53 match self {
54 Service::AVTransport => "AVTransport",
55 Service::RenderingControl => "RenderingControl",
56 Service::GroupRenderingControl => "GroupRenderingControl",
57 Service::ZoneGroupTopology => "ZoneGroupTopology",
58 Service::GroupManagement => "GroupManagement",
59 }
60 }
61
62 pub fn info(&self) -> ServiceInfo {
67 match self {
68 Service::AVTransport => ServiceInfo {
69 endpoint: "MediaRenderer/AVTransport/Control",
70 service_uri: "urn:schemas-upnp-org:service:AVTransport:1",
71 event_endpoint: "MediaRenderer/AVTransport/Event",
72 },
73 Service::RenderingControl => ServiceInfo {
74 endpoint: "MediaRenderer/RenderingControl/Control",
75 service_uri: "urn:schemas-upnp-org:service:RenderingControl:1",
76 event_endpoint: "MediaRenderer/RenderingControl/Event",
77 },
78 Service::GroupRenderingControl => ServiceInfo {
79 endpoint: "MediaRenderer/GroupRenderingControl/Control",
80 service_uri: "urn:schemas-upnp-org:service:GroupRenderingControl:1",
81 event_endpoint: "MediaRenderer/GroupRenderingControl/Event",
82 },
83 Service::ZoneGroupTopology => ServiceInfo {
84 endpoint: "ZoneGroupTopology/Control",
85 service_uri: "urn:schemas-upnp-org:service:ZoneGroupTopology:1",
86 event_endpoint: "ZoneGroupTopology/Event",
87 },
88 Service::GroupManagement => ServiceInfo {
89 endpoint: "GroupManagement/Control",
90 service_uri: "urn:schemas-upnp-org:service:GroupManagement:1",
91 event_endpoint: "GroupManagement/Event",
92 },
93 }
94 }
95
96 pub fn scope(&self) -> ServiceScope {
102 match self {
103 Service::AVTransport => ServiceScope::PerSpeaker,
104 Service::RenderingControl => ServiceScope::PerSpeaker,
105 Service::GroupRenderingControl => ServiceScope::PerCoordinator,
106 Service::ZoneGroupTopology => ServiceScope::PerNetwork,
107 Service::GroupManagement => ServiceScope::PerCoordinator,
108 }
109 }
110}
111
112#[cfg(test)]
113mod scope_tests {
114 use super::*;
115
116 #[test]
117 fn test_service_scopes() {
118 assert_eq!(Service::AVTransport.scope(), ServiceScope::PerSpeaker);
119 assert_eq!(Service::RenderingControl.scope(), ServiceScope::PerSpeaker);
120 assert_eq!(
121 Service::GroupRenderingControl.scope(),
122 ServiceScope::PerCoordinator
123 );
124 assert_eq!(Service::ZoneGroupTopology.scope(), ServiceScope::PerNetwork);
125 assert_eq!(
126 Service::GroupManagement.scope(),
127 ServiceScope::PerCoordinator
128 );
129 }
130
131 #[test]
132 fn test_all_services_have_scope() {
133 let services = [
135 Service::AVTransport,
136 Service::RenderingControl,
137 Service::GroupRenderingControl,
138 Service::ZoneGroupTopology,
139 Service::GroupManagement,
140 ];
141
142 for service in services {
143 let _scope = service.scope(); }
145 }
146}