Fin du debuggage

This commit is contained in:
2025-10-03 21:19:14 +02:00
parent 68faea2758
commit a4d618c09c
20 changed files with 116 additions and 139 deletions

View File

@@ -1,11 +1,14 @@
use std::fmt;
use chrono::{DateTime, Utc};
use tokio::sync::RwLock;
use std::sync::RwLock;
use xmltree::Element;
use crate::{
object_trait::{UpnpInstance, UpnpObject}, state_variables::{StateVarInstance, StateVariable, UpnpVariable}, variable_types::{StateValue, StateValueError, UpnpVarType}, UpnpObjectType, UpnpTyped, UpnpTypedInstance, UpnpTypedObject
object_trait::{UpnpInstance, UpnpObject},
state_variables::{StateVarInstance, StateVariable, UpnpVariable},
variable_types::{StateValue, StateValueError, UpnpVarType},
UpnpObjectType, UpnpTyped, UpnpTypedInstance
};
impl UpnpVariable for StateVarInstance {
@@ -15,8 +18,8 @@ impl UpnpVariable for StateVarInstance {
}
impl UpnpObject for StateVarInstance {
async fn to_xml_element(&self) -> Element {
self.get_definition().to_xml_element().await
fn to_xml_element(&self) -> Element {
self.get_definition().to_xml_element()
}
}
@@ -76,10 +79,10 @@ impl Clone for StateVarInstance {
Self {
object: self.object.clone(),
model: self.model.clone(),
value: RwLock::new(self.value.blocking_read().clone()),
old_value: RwLock::new(self.old_value.blocking_read().clone()),
last_modified: RwLock::new(self.last_modified.blocking_read().clone()),
last_notification: RwLock::new(self.last_notification.blocking_read().clone()),
value: RwLock::new(self.value.read().unwrap().clone()),
old_value: RwLock::new(self.old_value.read().unwrap().clone()),
last_modified: RwLock::new(self.last_modified.read().unwrap().clone()),
last_notification: RwLock::new(self.last_notification.read().unwrap().clone()),
}
}
}
@@ -94,9 +97,9 @@ impl StateVarInstance {
}
// Mise à jour avec les locks
let mut old_val = self.old_value.write().await;
let mut val = self.value.write().await;
let mut modified = self.last_modified.write().await;
let mut old_val = self.old_value.write().unwrap();
let mut val = self.value.write().unwrap();
let mut modified = self.last_modified.write().unwrap();
*old_val = val.clone();
*val = new_value;
@@ -106,11 +109,11 @@ impl StateVarInstance {
}
/// Accès à la valeur
pub fn value(&self) -> StateValue {
self.value.blocking_read().clone()
self.value.read().unwrap().clone()
}
/// Accès au timestamp
pub fn last_modified(&self) -> DateTime<Utc> {
self.last_modified.blocking_read().clone()
self.last_modified.read().unwrap().clone()
}
}

View File

@@ -14,10 +14,12 @@ pub use crate::state_variables::variable_trait::UpnpVariable;
use bevy_reflect::Reflect;
use chrono::{DateTime, Utc};
pub use errors::StateVariableError;
use tokio::sync::RwLock;
use std::sync::RwLock;
use crate::{
value_ranges::ValueRange, variable_types::{StateValue, StateVarType}, UpnpObjectSet, UpnpObjectType, UpnpSet
value_ranges::ValueRange,
variable_types::{StateValue, StateVarType},
UpnpObjectSet, UpnpObjectType,
};
/// Type pour les fonctions de condition d'événement

View File

@@ -1,18 +1,18 @@
use std::collections::HashMap;
use tokio::sync::RwLock;
use std::sync::RwLock;
use xmltree::{Element, XMLNode};
use crate::{state_variables::{StateVarInstance, StateVarInstanceSet, StateVariableSet}, UpnInstanceSet, UpnpObject, UpnpTyped};
use crate::{state_variables::{StateVarInstanceSet, StateVariableSet}, UpnpObject};
use crate::UpnpInstance;
impl UpnpObject for StateVarInstanceSet {
async fn to_xml_element(&self) -> Element {
fn to_xml_element(&self) -> Element {
let mut elem = Element::new("serviceStateTable");
for state_var in self.all().await {
let state_var_elem = state_var.to_xml_element().await; // retourne un <stateVariable> complet
for state_var in self.all() {
let state_var_elem = state_var.to_xml_element(); // retourne un <stateVariable> complet
elem.children.push(XMLNode::Element(state_var_elem));
}

View File

@@ -1,15 +1,15 @@
use xmltree::{Element, XMLNode};
use crate::{object_trait::UpnpModel, state_variables::{StateVarInstanceSet, StateVariableSet}, UpnInstanceSet, UpnpObject};
use crate::{object_trait::UpnpModel, state_variables::{StateVarInstanceSet, StateVariableSet}, UpnpObject};
impl UpnpObject for StateVariableSet {
async fn to_xml_element(&self) -> Element {
fn to_xml_element(&self) -> Element {
let mut elem = Element::new("serviceStateTable");
for state_var in self.get_all() {
let state_var_elem = state_var.to_xml_element().await; // retourne un <stateVariable> complet
for state_var in self.all() {
let state_var_elem = state_var.to_xml_element(); // retourne un <stateVariable> complet
elem.children.push(XMLNode::Element(state_var_elem));
}

View File

@@ -4,7 +4,7 @@ use std::{
sync::Arc,
};
use tokio::sync::RwLock;
use std::sync::RwLock;
use xmltree::{Element, XMLNode};
use crate::{
@@ -31,7 +31,7 @@ impl UpnpVarType for StateVariable {
}
impl UpnpObject for StateVariable {
async fn to_xml_element(&self) -> Element {
fn to_xml_element(&self) -> Element {
// Création de l'élément racine <stateVariable>
let mut root = Element::new("stateVariable");
root.attributes.insert(
@@ -59,7 +59,7 @@ impl UpnpObject for StateVariable {
}
// <allowedValueList> si défini
let av = self.allowed_values.read().await;
let av = self.allowed_values.read().unwrap();
if !av.is_empty() {
let mut list_elem = Element::new("allowedValueList");
for val in av.iter() {
@@ -114,7 +114,7 @@ impl Clone for StateVariable {
// si le lock est "poisoned" on panic - tu peux adapter la gestion si tu veux
let guard = self
.event_conditions
.blocking_read();
.read().unwrap();
// nécessite que Key: Clone, Value: Clone
Arc::new(RwLock::new(guard.clone()))
};
@@ -122,7 +122,7 @@ impl Clone for StateVariable {
let allowed_values_clone = {
let guard = self
.allowed_values
.blocking_read();
.read().unwrap();
Arc::new(RwLock::new(guard.clone()))
};
@@ -156,7 +156,7 @@ impl fmt::Debug for StateVariable {
"event_conditions",
&format_args!(
"len={}",
self.event_conditions.blocking_read().len()
self.event_conditions.read().unwrap().len()
),
)
.field("description", &self.description)
@@ -166,7 +166,7 @@ impl fmt::Debug for StateVariable {
"allowed_values",
&format_args!(
"len={}",
self.allowed_values.blocking_read().len()
self.allowed_values.read().unwrap().len()
),
)
.field("send_events", &self.send_events)
@@ -298,18 +298,18 @@ impl StateVariable {
pub fn add_event_condition(&self, name: String, func: StateConditionFunc) {
// on lock en écriture
let mut guard = self.event_conditions.blocking_write();
let mut guard = self.event_conditions.write().unwrap();
guard.insert(name, func);
// le lock est automatiquement relâché ici (RAII)
}
pub fn remove_event_condition(&self, name: &str) {
let mut guard = self.event_conditions.blocking_write();
let mut guard = self.event_conditions.write().unwrap();
guard.remove(name);
}
pub fn clear_event_conditions(&mut self) {
let mut guard = self.event_conditions.blocking_write();
let mut guard = self.event_conditions.write().unwrap();
guard.clear()
}
@@ -334,7 +334,7 @@ impl StateVariable {
pub fn extend_allowed_values(&mut self, values: &[StateValue]) -> Result<(), StateValueError> {
let mut av = self
.allowed_values
.blocking_write();
.write().unwrap();
for v in values {
if self.as_state_var_type() == v.as_state_var_type() {
@@ -352,7 +352,7 @@ impl StateVariable {
pub fn push_allowed_value(&mut self, value: &StateValue) -> Result<(), StateValueError> {
let mut av = self
.allowed_values
.blocking_write();
.write().unwrap();
if self.as_state_var_type() == value.as_state_var_type() {
av.push(value.clone());

View File

@@ -124,7 +124,7 @@ pub trait UpnpVariable {
///
/// Retourne `false` si le lock est empoisonné (poisoned).
fn has_event_conditions(&self) -> bool {
let guard = self.get_definition().event_conditions.blocking_read();
let guard = self.get_definition().event_conditions.read().unwrap();
!guard.is_empty()
}
@@ -142,7 +142,7 @@ pub trait UpnpVariable {
///
/// Retourne `false` si le lock est empoisonné (poisoned).
fn has_event_condition(&self, name: &String) -> bool {
let guard = self.get_definition().event_conditions.blocking_read();
let guard = self.get_definition().event_conditions.read().unwrap();
guard.contains_key(name)
}
@@ -218,7 +218,7 @@ pub trait UpnpVariable {
fn has_allowed_values(&self) -> bool {
let guard = self.get_definition()
.allowed_values
.blocking_read();
.read().unwrap();
!guard.is_empty()
}
@@ -252,7 +252,7 @@ pub trait UpnpVariable {
fn is_an_allowed_value(&self, value: &StateValue) -> bool {
let guard = self.get_definition()
.allowed_values
.blocking_read();
.read().unwrap();
guard.contains(value)
}