diff --git a/PMOMusic/src/main.rs b/PMOMusic/src/main.rs index e1c7d4ce..570f8f3c 100644 --- a/PMOMusic/src/main.rs +++ b/PMOMusic/src/main.rs @@ -47,7 +47,7 @@ async fn main() { server.add_redirect("/", "/app").await; - info!("{}",SETAVTRANSPORTURI.to_markdown().await); + info!("{}",SETAVTRANSPORTURI.to_markdown()); server.start().await; server.wait().await; diff --git a/pmoupnp/src/actions/action_instance.rs b/pmoupnp/src/actions/action_instance.rs index a3c2435f..428b819c 100644 --- a/pmoupnp/src/actions/action_instance.rs +++ b/pmoupnp/src/actions/action_instance.rs @@ -10,10 +10,10 @@ use crate::UpnpInstance; use crate::UpnpObject; use crate::UpnpTyped; use crate::UpnpTypedInstance; -use crate::{UpnpTypedObject, UpnpObjectType}; +use crate::UpnpObjectType; impl UpnpObject for ActionInstance { -async fn to_xml_element(&self) -> Element { +fn to_xml_element(&self) -> Element { let mut elem = Element::new("action"); // @@ -22,7 +22,7 @@ async fn to_xml_element(&self) -> Element { elem.children.push(XMLNode::Element(name_elem)); // déplacer tous les enfants de args_elem dans un nouvel Element - let args_container = self.arguments_set().to_xml_element().await; + let args_container = self.arguments_set().to_xml_element(); elem.children.push(XMLNode::Element(args_container)); elem @@ -62,8 +62,8 @@ impl UpnpTypedInstance for ActionInstance { impl ActionInstance { - pub async fn arguments(&self, name: &str) -> Option> { - self.model.arguments.get_by_name(name).await + pub fn arguments(&self, name: &str) -> Option> { + self.model.arguments.get_by_name(name) } pub fn arguments_set(&self) -> &ArgumentSet { diff --git a/pmoupnp/src/actions/action_instance_set.rs b/pmoupnp/src/actions/action_instance_set.rs index 6d5455f3..ec2725ca 100644 --- a/pmoupnp/src/actions/action_instance_set.rs +++ b/pmoupnp/src/actions/action_instance_set.rs @@ -1,5 +1,5 @@ use crate::{ - UpnpTypedObject, UpnpObject, + UpnpObject, actions::{ActionInstanceSet}, }; @@ -7,11 +7,11 @@ use xmltree::{Element,XMLNode}; impl UpnpObject for ActionInstanceSet { // Méthode pour convertir en XML (à implémenter avec une librairie XML) - async fn to_xml_element(&self) -> Element { + fn to_xml_element(&self) -> Element { let mut elem = Element::new("actionList"); - for action in self.all().await { - let action_elem = action.to_xml_element().await; // retourne un complet + for action in self.all() { + let action_elem = action.to_xml_element(); // retourne un complet elem.children.push(XMLNode::Element(action_elem)); } diff --git a/pmoupnp/src/actions/action_methods.rs b/pmoupnp/src/actions/action_methods.rs index 064da331..2ac95758 100644 --- a/pmoupnp/src/actions/action_methods.rs +++ b/pmoupnp/src/actions/action_methods.rs @@ -1,18 +1,19 @@ use std::sync::Arc; -use xmltree::{Element,XMLNode}; +use xmltree::{Element, XMLNode}; -use crate::actions::ActionInstance; use crate::UpnpModel; use crate::UpnpObject; +use crate::UpnpObjectSetError; +use crate::UpnpObjectType; +use crate::UpnpTyped; use crate::actions::Action; +use crate::actions::ActionInstance; use crate::actions::Argument; use crate::actions::ArgumentSet; -use crate::UpnpTyped; -use crate::{UpnpTypedObject, UpnpObjectType}; impl UpnpObject for Action { - async fn to_xml_element(&self) -> Element { + fn to_xml_element(&self) -> Element { let mut action_elem = Element::new("action"); // @@ -23,7 +24,7 @@ impl UpnpObject for Action { action_elem.children.push(XMLNode::Element(name_elem)); // - let args_elem = self.arguments.to_xml_element().await; + let args_elem = self.arguments.to_xml_element(); action_elem.children.push(XMLNode::Element(args_elem)); action_elem @@ -31,11 +32,9 @@ impl UpnpObject for Action { } impl UpnpModel for Action { - type Instance = ActionInstance; } - impl UpnpTyped for Action { fn as_upnp_object_type(&self) -> &UpnpObjectType { return &self.object; @@ -53,8 +52,8 @@ impl Action { } } - pub fn add_argument(&mut self, arg: Arc) { - self.arguments.insert(arg); + pub fn add_argument(&mut self, arg: Arc) -> Result<(), UpnpObjectSetError> { + self.arguments.insert(arg) } pub fn arguments(&self) -> &ArgumentSet { diff --git a/pmoupnp/src/actions/action_set_methods.rs b/pmoupnp/src/actions/action_set_methods.rs index 5acafe7b..ab387b6b 100644 --- a/pmoupnp/src/actions/action_set_methods.rs +++ b/pmoupnp/src/actions/action_set_methods.rs @@ -1,18 +1,14 @@ -use std::collections::HashMap; use xmltree::{Element, XMLNode}; -use crate::actions::Action; use crate::actions::ActionSet; -use crate::actions::errors::ActionError; -use crate::UpnpTypedObject; use crate::UpnpObject; impl UpnpObject for ActionSet { - async fn to_xml_element(&self) -> Element { + fn to_xml_element(&self) -> Element { let mut elem = Element::new("actionList"); - for action in self.all().await { - let action_elem = action.to_xml_element().await; // retourne un complet + for action in self.all() { + let action_elem = action.to_xml_element(); // retourne un complet elem.children.push(XMLNode::Element(action_elem)); } diff --git a/pmoupnp/src/actions/arg_inst_set_methods.rs b/pmoupnp/src/actions/arg_inst_set_methods.rs index e8bde8bc..92bc0f84 100644 --- a/pmoupnp/src/actions/arg_inst_set_methods.rs +++ b/pmoupnp/src/actions/arg_inst_set_methods.rs @@ -1,18 +1,18 @@ use std::collections::HashMap; -use tokio::sync::RwLock; +use std::sync::RwLock; use xmltree::{Element, XMLNode}; -use crate::{actions::{ArgInstanceSet, ArgumentSet}, state_variables::StateVariableSet, UpnpObject}; +use crate::{actions::{ArgInstanceSet, ArgumentSet}, UpnpObject}; use crate::UpnpInstance; impl UpnpObject for ArgInstanceSet { - 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 complet + for state_var in self.all() { + let state_var_elem = state_var.to_xml_element(); // retourne un complet elem.children.push(XMLNode::Element(state_var_elem)); } diff --git a/pmoupnp/src/actions/arg_instance_methods.rs b/pmoupnp/src/actions/arg_instance_methods.rs index ca9c4bc6..443b7a8f 100644 --- a/pmoupnp/src/actions/arg_instance_methods.rs +++ b/pmoupnp/src/actions/arg_instance_methods.rs @@ -4,8 +4,8 @@ use crate::{actions::{Argument, ArgumentInstance}, UpnpInstance, UpnpObject, Upn impl UpnpObject for ArgumentInstance { - async fn to_xml_element(&self) -> Element { - self.get_model().to_xml_element().await + fn to_xml_element(&self) -> Element { + self.get_model().to_xml_element() } } diff --git a/pmoupnp/src/actions/arg_set_methods.rs b/pmoupnp/src/actions/arg_set_methods.rs index 91c1ed32..a8f7cae5 100644 --- a/pmoupnp/src/actions/arg_set_methods.rs +++ b/pmoupnp/src/actions/arg_set_methods.rs @@ -1,11 +1,9 @@ use crate::actions::ArgInstanceSet; -use crate::{UpnpModel, UpnpTypedObject}; +use crate::UpnpModel; use crate::{ UpnpObject, actions::{ArgumentSet}, }; -use std::collections::HashMap; -use std::sync::RwLock; use xmltree::Element; impl UpnpObject for ArgumentSet { diff --git a/pmoupnp/src/actions/argument_methods.rs b/pmoupnp/src/actions/argument_methods.rs index e43bf7d0..84e6e69a 100644 --- a/pmoupnp/src/actions/argument_methods.rs +++ b/pmoupnp/src/actions/argument_methods.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use xmltree::{Element, XMLNode}; use crate::{ - actions::{Argument, ArgumentInstance}, state_variables::StateVariable, UpnpInstance, UpnpModel, UpnpObject, UpnpObjectType, UpnpTyped, UpnpTypedObject + actions::{Argument, ArgumentInstance}, state_variables::StateVariable, UpnpModel, UpnpObject, UpnpObjectType, UpnpTyped }; impl UpnpTyped for Argument { @@ -13,7 +13,7 @@ impl UpnpTyped for Argument { } impl UpnpObject for Argument { - async fn to_xml_element(&self) -> Element { + fn to_xml_element(&self) -> Element { let mut parent = Element::new("argumentList"); if self.is_in() && self.is_out() { diff --git a/pmoupnp/src/lib.rs b/pmoupnp/src/lib.rs index 7d6dfa9d..3e4c248d 100644 --- a/pmoupnp/src/lib.rs +++ b/pmoupnp/src/lib.rs @@ -12,7 +12,7 @@ pub mod variable_types; use std::{collections::HashMap, sync::Arc}; -use tokio::sync::RwLock; +use std::sync::RwLock; pub use crate::object_trait::*; diff --git a/pmoupnp/src/object_set.rs b/pmoupnp/src/object_set.rs index dd8ad820..2d99ebec 100644 --- a/pmoupnp/src/object_set.rs +++ b/pmoupnp/src/object_set.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, sync::Arc}; -use tokio::sync::RwLock; +use std::sync::RwLock; use crate::{UpnpDeepClone, UpnpObjectSet, UpnpObjectSetError, UpnpTypedObject}; @@ -11,7 +11,7 @@ use crate::{UpnpDeepClone, UpnpObjectSet, UpnpObjectSetError, UpnpTypedObject}; /// Les modifications sur l'un des sets n'affectent pas l'autre. impl UpnpDeepClone for UpnpObjectSet { fn deep_clone(&self) -> Self { - let guard = self.objects.blocking_read(); + let guard = self.objects.read().unwrap(); let cloned_map: HashMap> = guard .iter() @@ -38,7 +38,7 @@ impl UpnpDeepClone for UpnpObjectSet { /// seront visibles depuis les deux sets. impl Clone for UpnpObjectSet { fn clone(&self) -> Self { - let guard = self.objects.blocking_read(); + let guard = self.objects.read().unwrap(); Self { objects: RwLock::new(guard.clone()), @@ -47,14 +47,19 @@ impl Clone for UpnpObjectSet { } impl UpnpObjectSet { - + /// Crée un nouveau `UpnpObjectSet` vide. + /// + /// # Examples + /// + /// ``` + /// let set: UpnpObjectSet = UpnpObjectSet::new(); + /// ``` pub fn new() -> Self { Self { objects: RwLock::new(HashMap::new()), } } - /// Insère un objet dans le set. /// /// # Arguments @@ -71,10 +76,10 @@ impl UpnpObjectSet { /// ``` /// let mut set = UpnpObjectSet::new(); /// let obj = Arc::new(MyObject::new("test")); - /// set.insert(obj).await?; + /// set.insert(obj)?; /// ``` - pub async fn insert(&mut self, object: Arc) -> Result<(), UpnpObjectSetError> { - let mut guard = self.objects.write().await; + pub fn insert(&mut self, object: Arc) -> Result<(), UpnpObjectSetError> { + let mut guard = self.objects.write().unwrap(); let key = object.get_name().to_string(); if guard.contains_key(&key) { @@ -100,11 +105,11 @@ impl UpnpObjectSet { /// let obj1 = Arc::new(MyObject::new("test")); /// let obj2 = Arc::new(MyObject::new("test")); // Même nom /// - /// set.insert_or_replace(obj1).await; - /// set.insert_or_replace(obj2).await; // Remplace obj1 + /// set.insert_or_replace(obj1); + /// set.insert_or_replace(obj2); // Remplace obj1 /// ``` - pub async fn insert_or_replace(&mut self, object: Arc) { - let mut guard = self.objects.write().await; + pub fn insert_or_replace(&mut self, object: Arc) { + let mut guard = self.objects.write().unwrap(); let key: String = object.get_name().to_string(); guard.insert(key, object); @@ -128,18 +133,18 @@ impl UpnpObjectSet { /// let set = UpnpObjectSet::new(); /// let obj = Arc::new(MyObject::new("test")); /// - /// if set.contains(obj.clone()).await { + /// if set.contains(obj.clone()) { /// println!("L'objet existe déjà"); /// } /// ``` - pub async fn contains(&self, object: Arc) -> bool { - let guard = self.objects.read().await; + pub fn contains(&self, object: Arc) -> bool { + let guard = self.objects.read().unwrap(); let key: String = object.get_name().to_string(); guard.contains_key(&key) } - /// Récupère un objet par son nom (version asynchrone). + /// Récupère un objet par son nom. /// /// # Arguments /// @@ -155,16 +160,16 @@ impl UpnpObjectSet { /// ``` /// let set = UpnpObjectSet::new(); /// - /// if let Some(obj) = set.get_by_name("test").await { + /// if let Some(obj) = set.get_by_name("test") { /// println!("Objet trouvé: {}", obj.get_name()); /// } /// ``` - pub async fn get_by_name(&self, name: &str) -> Option> { - let guard = self.objects.read().await; + pub fn get_by_name(&self, name: &str) -> Option> { + let guard = self.objects.read().unwrap(); guard.get(name).cloned() } - /// Retourne tous les objets du set (version asynchrone). + /// Retourne tous les objets du set. /// /// # Returns /// @@ -176,43 +181,17 @@ impl UpnpObjectSet { /// ``` /// let set = UpnpObjectSet::new(); /// - /// for obj in set.all().await { - /// println!("Objet: {}", obj.get_name()); - /// } - /// ``` - pub async fn all(&self) -> Vec> { - let guard = self.objects.read().await; - guard.values().cloned().collect() - } - - /// Retourne tous les objets du set (version synchrone bloquante). - /// - /// Cette méthode bloque le thread appelant jusqu'à ce que le verrou de lecture - /// soit obtenu. Utilisez cette version uniquement dans du code synchrone. - /// Pour du code asynchrone, préférez [`all()`](Self::all). - /// - /// # Returns - /// - /// Un vecteur contenant des clones des `Arc` pointant vers tous les objets du set. - /// L'ordre des éléments n'est pas garanti. - /// - /// # Examples - /// - /// ``` - /// let set = UpnpObjectSet::new(); - /// - /// // Dans un contexte synchrone - /// for obj in set.get_all() { + /// for obj in set.all() { /// println!("Objet: {}", obj.get_name()); /// } /// ``` /// - /// # Avertissement + /// # Thread-safety /// - /// N'appelez pas cette méthode depuis un contexte asynchrone car elle peut - /// bloquer l'executor Tokio. Utilisez [`all()`](Self::all) à la place. - pub fn get_all(&self) -> Vec> { - let guard = self.objects.blocking_read(); + /// Cette méthode acquiert un verrou de lecture. Plusieurs threads peuvent + /// appeler cette méthode simultanément sans blocage. + pub fn all(&self) -> Vec> { + let guard = self.objects.read().unwrap(); guard.values().cloned().collect() } } \ No newline at end of file diff --git a/pmoupnp/src/object_trait.rs b/pmoupnp/src/object_trait.rs index 91a44856..99c151e9 100644 --- a/pmoupnp/src/object_trait.rs +++ b/pmoupnp/src/object_trait.rs @@ -79,7 +79,7 @@ pub trait UpnpObject: Clone + Debug { /// # Returns /// /// Un [`Element`] xmltree représentant l'objet. - async fn to_xml_element(&self) -> Element; + fn to_xml_element(&self) -> Element; /// Convertit l'objet en chaîne XML formatée. /// @@ -101,8 +101,8 @@ pub trait UpnpObject: Clone + Debug { /// // value /// // /// ``` - async fn to_xml(&self) -> String { - let elem = self.to_xml_element().await; + fn to_xml(&self) -> String { + let elem = self.to_xml_element(); let config = EmitterConfig::new() .perform_indent(true) @@ -144,8 +144,8 @@ pub trait UpnpObject: Clone + Debug { /// // - **element** /// // - **child**: `value` /// ``` - async fn to_markdown(&self) -> String { - let elem = self.to_xml_element().await; + fn to_markdown(&self) -> String { + let elem = self.to_xml_element(); let mut md = String::new(); fn is_url(s: &str) -> bool { diff --git a/pmoupnp/src/services/mod.rs b/pmoupnp/src/services/mod.rs index 3567a698..24f94855 100644 --- a/pmoupnp/src/services/mod.rs +++ b/pmoupnp/src/services/mod.rs @@ -9,7 +9,7 @@ use axum::{ http::{StatusCode, HeaderMap}, body::Body, }; -use tokio::sync::RwLock; +use std::sync::RwLock; use tokio::time; use tracing::{info, warn, debug, error}; diff --git a/pmoupnp/src/state_variables/instance_methods.rs b/pmoupnp/src/state_variables/instance_methods.rs index 693f691c..46b74d40 100644 --- a/pmoupnp/src/state_variables/instance_methods.rs +++ b/pmoupnp/src/state_variables/instance_methods.rs @@ -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 { - self.last_modified.blocking_read().clone() + self.last_modified.read().unwrap().clone() } } diff --git a/pmoupnp/src/state_variables/mod.rs b/pmoupnp/src/state_variables/mod.rs index 2f991bbe..0e8660ea 100644 --- a/pmoupnp/src/state_variables/mod.rs +++ b/pmoupnp/src/state_variables/mod.rs @@ -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 diff --git a/pmoupnp/src/state_variables/var_inst_set_methods.rs b/pmoupnp/src/state_variables/var_inst_set_methods.rs index 7c4b65e7..e5d55dc3 100644 --- a/pmoupnp/src/state_variables/var_inst_set_methods.rs +++ b/pmoupnp/src/state_variables/var_inst_set_methods.rs @@ -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 complet + for state_var in self.all() { + let state_var_elem = state_var.to_xml_element(); // retourne un complet elem.children.push(XMLNode::Element(state_var_elem)); } diff --git a/pmoupnp/src/state_variables/var_set_methods.rs b/pmoupnp/src/state_variables/var_set_methods.rs index 646b7d64..14b8c836 100644 --- a/pmoupnp/src/state_variables/var_set_methods.rs +++ b/pmoupnp/src/state_variables/var_set_methods.rs @@ -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 complet + for state_var in self.all() { + let state_var_elem = state_var.to_xml_element(); // retourne un complet elem.children.push(XMLNode::Element(state_var_elem)); } diff --git a/pmoupnp/src/state_variables/variable_methods.rs b/pmoupnp/src/state_variables/variable_methods.rs index 27206053..3bda6759 100644 --- a/pmoupnp/src/state_variables/variable_methods.rs +++ b/pmoupnp/src/state_variables/variable_methods.rs @@ -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 let mut root = Element::new("stateVariable"); root.attributes.insert( @@ -59,7 +59,7 @@ impl UpnpObject for StateVariable { } // 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()); diff --git a/pmoupnp/src/state_variables/variable_trait.rs b/pmoupnp/src/state_variables/variable_trait.rs index 52a2f19a..07b19a48 100644 --- a/pmoupnp/src/state_variables/variable_trait.rs +++ b/pmoupnp/src/state_variables/variable_trait.rs @@ -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) } diff --git a/pmoutils/src/ip_utils.rs b/pmoutils/src/ip_utils.rs index 590b27bc..d85c89ab 100644 --- a/pmoutils/src/ip_utils.rs +++ b/pmoutils/src/ip_utils.rs @@ -76,7 +76,7 @@ pub fn guess_local_ip() -> String { /// - Seules les adresses IPv4 sont retournées /// - Les adresses de loopback (127.x.x.x) sont filtrées /// - Les adresses IPv6 sont ignorées -fn list_all_ips() -> std::collections::HashMap> { +pub fn list_all_ips() -> std::collections::HashMap> { let mut result = std::collections::HashMap::new(); if let Ok(interfaces) = get_if_addrs() {