2025-10-02 18:39:32 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2025-10-01 15:44:52 +02:00
|
|
|
use xmltree::{Element, XMLNode};
|
|
|
|
|
|
|
|
|
|
use crate::actions::Action;
|
|
|
|
|
use crate::actions::Argument;
|
|
|
|
|
use crate::actions::ArgumentSet;
|
|
|
|
|
use crate::actions::ActionInstance;
|
2025-10-02 18:39:32 +02:00
|
|
|
use crate::UpnpInstance;
|
|
|
|
|
use crate::UpnpObject;
|
|
|
|
|
use crate::UpnpTyped;
|
|
|
|
|
use crate::UpnpTypedInstance;
|
|
|
|
|
use crate::{UpnpTypedObject, UpnpObjectType};
|
2025-10-01 15:44:52 +02:00
|
|
|
|
2025-10-02 18:39:32 +02:00
|
|
|
impl UpnpObject for ActionInstance {
|
|
|
|
|
async fn to_xml_element(&self) -> Element {
|
2025-10-01 15:44:52 +02:00
|
|
|
let mut elem = Element::new("action");
|
|
|
|
|
|
|
|
|
|
// <name>
|
|
|
|
|
let mut name_elem = Element::new("name");
|
|
|
|
|
name_elem.children.push(XMLNode::Text(self.get_name().clone()));
|
|
|
|
|
elem.children.push(XMLNode::Element(name_elem));
|
|
|
|
|
|
|
|
|
|
// déplacer tous les enfants de args_elem dans un nouvel Element
|
2025-10-02 18:39:32 +02:00
|
|
|
let args_container = self.arguments_set().to_xml_element().await;
|
2025-10-01 15:44:52 +02:00
|
|
|
elem.children.push(XMLNode::Element(args_container));
|
|
|
|
|
|
|
|
|
|
elem
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-02 18:39:32 +02:00
|
|
|
|
|
|
|
|
impl UpnpTyped for ActionInstance {
|
2025-10-01 15:44:52 +02:00
|
|
|
fn as_upnp_object_type(&self) -> &UpnpObjectType {
|
|
|
|
|
return &self.object;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-02 18:39:32 +02:00
|
|
|
impl UpnpInstance for ActionInstance {
|
|
|
|
|
|
|
|
|
|
type Model = Action;
|
2025-10-01 15:44:52 +02:00
|
|
|
|
2025-10-02 18:39:32 +02:00
|
|
|
fn new(action: &Action) -> Self {
|
2025-10-01 15:44:52 +02:00
|
|
|
Self {
|
|
|
|
|
object: UpnpObjectType {
|
|
|
|
|
name: action.get_name().clone(),
|
|
|
|
|
object_type: "ActionInstance".to_string(),
|
|
|
|
|
},
|
|
|
|
|
model: action.clone(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-02 18:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl UpnpTypedInstance for ActionInstance {
|
|
|
|
|
|
|
|
|
|
fn get_model(&self) -> &Self::Model {
|
|
|
|
|
&self.model
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ActionInstance {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn arguments(&self, name: &str) -> Option<Arc<Argument>> {
|
|
|
|
|
self.model.arguments.get_by_name(name).await
|
2025-10-01 15:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn arguments_set(&self) -> &ArgumentSet {
|
|
|
|
|
&self.model.arguments
|
|
|
|
|
}
|
|
|
|
|
}
|