use super::OnvifClient;
use crate::error::OnvifError;
use crate::soap::{find_response, parse_soap_body};
use crate::types::{
FocusMove, ImagingMoveOptions, ImagingOptions, ImagingSettings, ImagingStatus, xml_escape,
};
impl OnvifClient {
pub async fn get_imaging_settings(
&self,
imaging_url: &str,
video_source_token: &str,
) -> Result<ImagingSettings, OnvifError> {
const ACTION: &str = "http://www.onvif.org/ver20/imaging/wsdl/GetImagingSettings";
let video_source_token = xml_escape(video_source_token);
let body = format!(
"<timg:GetImagingSettings>\
<timg:VideoSourceToken>{video_source_token}</timg:VideoSourceToken>\
</timg:GetImagingSettings>"
);
let xml = self.call(imaging_url, ACTION, &body).await?;
let body_node = parse_soap_body(&xml)?;
let resp = find_response(&body_node, "GetImagingSettingsResponse")?;
ImagingSettings::from_xml(resp)
}
pub async fn set_imaging_settings(
&self,
imaging_url: &str,
video_source_token: &str,
settings: &ImagingSettings,
) -> Result<(), OnvifError> {
const ACTION: &str = "http://www.onvif.org/ver20/imaging/wsdl/SetImagingSettings";
let video_source_token = xml_escape(video_source_token);
let body = format!(
"<timg:SetImagingSettings>\
<timg:VideoSourceToken>{video_source_token}</timg:VideoSourceToken>\
{settings_xml}\
<timg:ForcePersistence>true</timg:ForcePersistence>\
</timg:SetImagingSettings>",
settings_xml = settings.to_xml_body()
);
let xml = self.call(imaging_url, ACTION, &body).await?;
let body_node = parse_soap_body(&xml)?;
find_response(&body_node, "SetImagingSettingsResponse")?;
Ok(())
}
pub async fn get_imaging_options(
&self,
imaging_url: &str,
video_source_token: &str,
) -> Result<ImagingOptions, OnvifError> {
const ACTION: &str = "http://www.onvif.org/ver20/imaging/wsdl/GetOptions";
let video_source_token = xml_escape(video_source_token);
let body = format!(
"<timg:GetOptions>\
<timg:VideoSourceToken>{video_source_token}</timg:VideoSourceToken>\
</timg:GetOptions>"
);
let xml = self.call(imaging_url, ACTION, &body).await?;
let body_node = parse_soap_body(&xml)?;
let resp = find_response(&body_node, "GetOptionsResponse")?;
ImagingOptions::from_xml(resp)
}
pub async fn imaging_move(
&self,
imaging_url: &str,
video_source_token: &str,
focus: &FocusMove,
) -> Result<(), OnvifError> {
const ACTION: &str = "http://www.onvif.org/ver20/imaging/wsdl/Move";
let video_source_token = xml_escape(video_source_token);
let body = format!(
"<timg:Move>\
<timg:VideoSourceToken>{video_source_token}</timg:VideoSourceToken>\
<timg:Focus>{}</timg:Focus>\
</timg:Move>",
focus.to_xml_body()
);
let xml = self.call(imaging_url, ACTION, &body).await?;
let body_node = parse_soap_body(&xml)?;
find_response(&body_node, "MoveResponse")?;
Ok(())
}
pub async fn imaging_stop(
&self,
imaging_url: &str,
video_source_token: &str,
) -> Result<(), OnvifError> {
const ACTION: &str = "http://www.onvif.org/ver20/imaging/wsdl/Stop";
let video_source_token = xml_escape(video_source_token);
let body = format!(
"<timg:Stop>\
<timg:VideoSourceToken>{video_source_token}</timg:VideoSourceToken>\
</timg:Stop>"
);
let xml = self.call(imaging_url, ACTION, &body).await?;
let body_node = parse_soap_body(&xml)?;
find_response(&body_node, "StopResponse")?;
Ok(())
}
pub async fn imaging_get_move_options(
&self,
imaging_url: &str,
video_source_token: &str,
) -> Result<ImagingMoveOptions, OnvifError> {
const ACTION: &str = "http://www.onvif.org/ver20/imaging/wsdl/GetMoveOptions";
let video_source_token = xml_escape(video_source_token);
let body = format!(
"<timg:GetMoveOptions>\
<timg:VideoSourceToken>{video_source_token}</timg:VideoSourceToken>\
</timg:GetMoveOptions>"
);
let xml = self.call(imaging_url, ACTION, &body).await?;
let body_node = parse_soap_body(&xml)?;
let resp = find_response(&body_node, "GetMoveOptionsResponse")?;
ImagingMoveOptions::from_xml(resp)
}
pub async fn imaging_get_status(
&self,
imaging_url: &str,
video_source_token: &str,
) -> Result<ImagingStatus, OnvifError> {
const ACTION: &str = "http://www.onvif.org/ver20/imaging/wsdl/GetStatus";
let video_source_token = xml_escape(video_source_token);
let body = format!(
"<timg:GetStatus>\
<timg:VideoSourceToken>{video_source_token}</timg:VideoSourceToken>\
</timg:GetStatus>"
);
let xml = self.call(imaging_url, ACTION, &body).await?;
let body_node = parse_soap_body(&xml)?;
let resp = find_response(&body_node, "GetStatusResponse")?;
ImagingStatus::from_xml(resp)
}
}