On continue l'implementation de pmoupnp

This commit is contained in:
2025-10-01 15:44:52 +02:00
parent a23d9bf845
commit 92ef3271d6
15 changed files with 618 additions and 31 deletions

View File

@@ -3,6 +3,7 @@ use xmltree::Element;
use crate::{
UpnpObject, UpnpObjectType,
object_trait::UpnpXml,
state_variables::{StateVarInstance, StateVariable, UpnpVariable},
variable_types::StateValue,
};
@@ -13,14 +14,16 @@ impl UpnpVariable for StateVarInstance {
}
}
impl UpnpXml for StateVarInstance {
fn to_xml_element(&self) -> Element {
self.get_definition().to_xml_element()
}
}
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 {

View File

@@ -1,6 +1,7 @@
mod errors;
mod instance_methods;
mod variable_methods;
mod var_set_methods;
mod variable_trait;
use std::{
@@ -44,6 +45,11 @@ pub struct StateVariable {
marshal: Option<ValueSerializer>,
}
#[derive(Debug, Default, Clone)]
pub struct StateVariableSet {
instances: HashMap<String, StateVariable>,
}
pub struct StateVarInstance {
object: UpnpObjectType,
definition: StateVariable,

View File

@@ -0,0 +1,34 @@
use std::collections::HashMap;
use crate::{state_variables::{StateVariable, StateVariableSet}, UpnpObject};
impl StateVariableSet {
pub fn new() -> Self {
Self {
instances: HashMap::new(),
}
}
pub fn insert(&mut self, instance: StateVariable) {
self.instances.insert(instance.get_name().clone(), instance);
}
pub fn contains(&self, name: &str) -> bool {
self.instances.contains_key(name)
}
pub fn get(&self, name: &str) -> Option<&StateVariable> {
self.instances.get(name)
}
pub fn iter(&self) -> impl Iterator<Item = &StateVariable> {
self.instances.values()
}
pub fn all(&self) -> Vec<&StateVariable> {
self.instances.values().collect()
}
}

View File

@@ -1,25 +1,16 @@
use std::{
collections::HashMap,
sync::{Arc, RwLock},
collections::HashMap, fmt, sync::{Arc, RwLock}
};
use xmltree::{Element, XMLNode};
use crate::{
UpnpObject, UpnpObjectType,
state_variables::{
StateConditionFunc, StateVariable, StringValueParser, ValueSerializer,
variable_trait::UpnpVariable,
},
value_ranges::ValueRange,
variable_types::{StateValue, StateValueError, StateVarType, UpnpVarType},
object_trait::UpnpXml, state_variables::{
variable_trait::UpnpVariable, StateConditionFunc, StateVariable, StringValueParser, ValueSerializer
}, value_ranges::ValueRange, variable_types::{StateValue, StateValueError, StateVarType, UpnpVarType}, UpnpObject, UpnpObjectType
};
impl UpnpObject for StateVariable {
fn as_upnp_object_type(&self) -> &UpnpObjectType {
return &self.object;
}
impl UpnpXml for StateVariable {
fn to_xml_element(&self) -> Element {
// Création de l'élément racine <stateVariable>
let mut root = Element::new("stateVariable");
@@ -91,6 +82,13 @@ impl UpnpObject for StateVariable {
root
}
}
impl UpnpObject for StateVariable {
fn as_upnp_object_type(&self) -> &UpnpObjectType {
return &self.object;
}
}
impl Clone for StateVariable {
@@ -133,6 +131,37 @@ impl Clone for StateVariable {
}
}
impl fmt::Debug for StateVariable {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("StateVariable")
.field("object", &self.object)
.field("value_type", &self.value_type)
.field("step", &self.step)
.field("modifiable", &self.modifiable)
.field(
"event_conditions",
&format_args!(
"len={}",
self.event_conditions.read().map(|m| m.len()).unwrap_or(0)
),
)
.field("description", &self.description)
.field("default_value", &self.default_value)
.field("value_range", &self.value_range)
.field(
"allowed_values",
&format_args!(
"len={}",
self.allowed_values.read().map(|v| v.len()).unwrap_or(0)
),
)
.field("send_events", &self.send_events)
.field("parse", &self.parse.as_ref().map(|_| "Some(StringValueParser)").unwrap_or("None"))
.field("marshal", &self.marshal.as_ref().map(|_| "Some(ValueSerializer)").unwrap_or("None"))
.finish()
}
}
impl UpnpVarType for StateVariable {
fn as_state_var_type(&self) -> StateVarType {
self.value_type // utilise ton From<&StateValue> existant