Files
pmomusic/pmoupnp/src/actions/action_instance.rs

73 lines
1.7 KiB
Rust
Raw Normal View History

2025-10-02 18:39:32 +02:00
use std::sync::Arc;
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-02 18:39:32 +02:00
impl UpnpObject for ActionInstance {
async fn to_xml_element(&self) -> Element {
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;
elem.children.push(XMLNode::Element(args_container));
elem
}
}
2025-10-02 18:39:32 +02:00
impl UpnpTyped for ActionInstance {
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-02 18:39:32 +02:00
fn new(action: &Action) -> Self {
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
}
pub fn arguments_set(&self) -> &ArgumentSet {
&self.model.arguments
}
}