On reformate le code ;-)
This commit is contained in:
@@ -4,25 +4,25 @@ use thiserror::Error;
|
||||
pub enum StateVariableError {
|
||||
#[error("Conversion error: {0}")]
|
||||
ConversionError(String),
|
||||
|
||||
|
||||
#[error("Validation error: {0}")]
|
||||
ValidationError(String),
|
||||
|
||||
|
||||
#[error("Range error: {0}")]
|
||||
RangeError(String),
|
||||
|
||||
|
||||
#[error("Type error: {0}")]
|
||||
TypeError(String),
|
||||
|
||||
|
||||
#[error("Parse error: {0}")]
|
||||
ParseError(String),
|
||||
|
||||
|
||||
#[error("Event condition error: {0}")]
|
||||
EventConditionError(String),
|
||||
|
||||
|
||||
#[error("Arithmetic error: {0}")]
|
||||
ArithmeticError(String),
|
||||
|
||||
|
||||
#[error("Unknown error: {0}")]
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ use chrono::{DateTime, Utc};
|
||||
use xmltree::Element;
|
||||
|
||||
use crate::{
|
||||
state_variables::{StateVarInstance, StateVariable, UpnpVariable},
|
||||
variable_types::StateValue,
|
||||
UpnpObject,
|
||||
UpnpObjectType
|
||||
UpnpObject, UpnpObjectType,
|
||||
state_variables::{StateVarInstance, StateVariable, UpnpVariable},
|
||||
variable_types::StateValue,
|
||||
};
|
||||
|
||||
impl UpnpVariable for StateVarInstance {
|
||||
@@ -35,7 +34,7 @@ impl StateVarInstance {
|
||||
value: from.get_default(),
|
||||
old_value: from.get_default(),
|
||||
last_modified: Utc::now(),
|
||||
last_notification: Utc::now()
|
||||
last_notification: Utc::now(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,5 +53,4 @@ impl StateVarInstance {
|
||||
pub fn last_modified(&self) -> DateTime<Utc> {
|
||||
self.last_modified
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,33 @@
|
||||
mod errors;
|
||||
mod variable_trait;
|
||||
mod variable_methods;
|
||||
mod instance_methods;
|
||||
mod variable_methods;
|
||||
mod variable_trait;
|
||||
|
||||
use std::{collections::HashMap, sync::{Arc, RwLock}};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
pub use crate::state_variables::variable_trait::UpnpVariable;
|
||||
use chrono::{DateTime, Utc};
|
||||
pub use errors::{StateVariableError};
|
||||
pub use crate::state_variables::variable_trait::UpnpVariable;
|
||||
pub use errors::StateVariableError;
|
||||
|
||||
|
||||
use crate::{value_ranges::ValueRange, variable_types::{StateValue, StateVarType}, UpnpObjectType};
|
||||
use crate::{
|
||||
UpnpObjectType,
|
||||
value_ranges::ValueRange,
|
||||
variable_types::{StateValue, StateVarType},
|
||||
};
|
||||
|
||||
/// Type pour les fonctions de condition d'événement
|
||||
pub type StateConditionFunc = Arc<dyn Fn(&StateVarInstance) -> bool + Send + Sync>;
|
||||
|
||||
/// Type pour les fonctions de parsing de valeurs depuis des chaînes
|
||||
pub type StringValueParser = Arc<dyn Fn(&str) -> Result<StateValue, StateVariableError> + Send + Sync>;
|
||||
pub type StringValueParser =
|
||||
Arc<dyn Fn(&str) -> Result<StateValue, StateVariableError> + Send + Sync>;
|
||||
|
||||
/// Type pour les fonctions de sérialisation de valeurs vers des chaînes
|
||||
pub type ValueSerializer = Arc<dyn Fn(&StateValue) -> Result<String, StateVariableError> + Send + Sync>;
|
||||
|
||||
pub type ValueSerializer =
|
||||
Arc<dyn Fn(&StateValue) -> Result<String, StateVariableError> + Send + Sync>;
|
||||
|
||||
pub struct StateVariable {
|
||||
object: UpnpObjectType,
|
||||
@@ -44,4 +51,4 @@ pub struct StateVarInstance {
|
||||
old_value: StateValue,
|
||||
last_modified: DateTime<Utc>,
|
||||
last_notification: DateTime<Utc>,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ impl UpnpObject for StateVariable {
|
||||
return &self.object;
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -65,11 +65,15 @@ fn to_xml_element(&self) -> Element {
|
||||
let mut range_elem = Element::new("allowedValueRange");
|
||||
|
||||
let mut min_elem = Element::new("minimum");
|
||||
min_elem.children.push(XMLNode::Text(range.get_minimum().to_string()));
|
||||
min_elem
|
||||
.children
|
||||
.push(XMLNode::Text(range.get_minimum().to_string()));
|
||||
range_elem.children.push(XMLNode::Element(min_elem));
|
||||
|
||||
let mut max_elem = Element::new("maximum");
|
||||
max_elem.children.push(XMLNode::Text(range.get_maximum().to_string()));
|
||||
max_elem
|
||||
.children
|
||||
.push(XMLNode::Text(range.get_maximum().to_string()));
|
||||
range_elem.children.push(XMLNode::Element(max_elem));
|
||||
|
||||
if let Some(step) = &self.step {
|
||||
|
||||
@@ -49,7 +49,7 @@ pub trait UpnpVariable {
|
||||
.clone()
|
||||
.unwrap_or_else(|| self.get_definition().as_state_var_type().default_value())
|
||||
}
|
||||
|
||||
|
||||
fn has_allowed_values(&self) -> bool {
|
||||
return self.get_definition().allowed_values.read().unwrap().len() > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user