Skip to main content

onvif_server/traits/
device.rs

1use crate::error::{not_implemented, OnvifError};
2use crate::generated::types::{
3    DeviceInfo, HostnameInformation, NetworkInterface, Scope, ScopeDefinition,
4};
5use async_trait::async_trait;
6
7/// ONVIF Device Management Service (Profile S core).
8///
9/// All methods default to sensible values or `not_implemented()` — implementors
10/// override only the operations their device supports. Trait is object-safe:
11/// store as `Arc<dyn DeviceService>`.
12///
13/// NOTE: GetCapabilities and GetServices are framework-level — the handler
14/// constructs those internally from the bound xaddr. Do NOT add them to this trait.
15#[async_trait]
16pub trait DeviceService: Send + Sync + 'static {
17    /// Returns the current UTC time. Defaults to `chrono::Utc::now()`.
18    async fn get_system_date_and_time(&self) -> Result<chrono::DateTime<chrono::Utc>, OnvifError> {
19        Ok(chrono::Utc::now())
20    }
21
22    /// Returns manufacturer, model, firmware version, serial number, hardware ID.
23    async fn get_device_information(&self) -> Result<DeviceInfo, OnvifError> {
24        not_implemented()
25    }
26
27    /// Returns the scopes used for WS-Discovery advertisement.
28    async fn get_scopes(&self) -> Result<Vec<Scope>, OnvifError> {
29        Ok(vec![
30            Scope {
31                scope_def: ScopeDefinition::Fixed,
32                scope_item: "onvif://www.onvif.org/type/video_encoder".into(),
33            },
34            Scope {
35                scope_def: ScopeDefinition::Fixed,
36                scope_item: "onvif://www.onvif.org/Profile/Streaming".into(),
37            },
38        ])
39    }
40
41    /// Returns the hostname of the device.
42    async fn get_hostname(&self) -> Result<HostnameInformation, OnvifError> {
43        Ok(HostnameInformation {
44            from_dhcp: false,
45            name: Some("onvif-device".into()),
46        })
47    }
48
49    /// Returns network interface configurations.
50    async fn get_network_interfaces(&self) -> Result<Vec<NetworkInterface>, OnvifError> {
51        not_implemented()
52    }
53}