Files
pmomusic/pmoupnp/src/state_variables/instance_methods.rs

57 lines
1.4 KiB
Rust
Raw Normal View History

2025-09-16 21:07:44 +02:00
use chrono::{DateTime, Utc};
use xmltree::Element;
use crate::{
2025-10-01 07:42:16 +02:00
UpnpObject, UpnpObjectType,
state_variables::{StateVarInstance, StateVariable, UpnpVariable},
variable_types::StateValue,
2025-09-16 21:07:44 +02:00
};
impl UpnpVariable for StateVarInstance {
fn get_definition(&self) -> &StateVariable {
return &self.definition;
}
}
impl UpnpObject for StateVarInstance {
fn as_upnp_object_type(&self) -> &UpnpObjectType {
return &self.object;
}
fn to_xml_element(&self) -> Element {
self.get_definition().to_xml_element()
}
}
impl StateVarInstance {
pub fn new(from: &StateVariable) -> Self {
Self {
object: UpnpObjectType {
name: from.object.name.clone(),
object_type: "StateVarInstance".to_string(),
},
definition: from.clone(),
value: from.get_default(),
old_value: from.get_default(),
last_modified: Utc::now(),
2025-10-01 07:42:16 +02:00
last_notification: Utc::now(),
2025-09-16 21:07:44 +02:00
}
}
pub fn set_value(&mut self, new_value: StateValue) {
self.old_value = self.value.clone();
self.value = new_value;
self.last_modified = Utc::now(); // mise à jour automatique
}
/// Accès à la valeur
pub fn value(&self) -> &StateValue {
&self.value
}
/// Accès au timestamp
pub fn last_modified(&self) -> DateTime<Utc> {
self.last_modified
}
}