Correction on cache system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
env::var,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
@@ -153,8 +154,13 @@ impl ActionInstance {
|
||||
|
||||
for (arg_name, state_value) in soap_data.iter() {
|
||||
if let Some(arg_inst) = self.argument(arg_name) {
|
||||
if arg_inst.get_model().is_in() {
|
||||
action_data.insert(arg_name.clone(), state_value.to_reflect());
|
||||
if arg_inst.is_in() {
|
||||
if let Some(var_inst) = arg_inst.get_variable_instance() {
|
||||
action_data
|
||||
.insert(arg_name.clone(), var_inst.parse_value(state_value.clone()));
|
||||
} else {
|
||||
action_data.insert(arg_name.clone(), state_value.to_reflect());
|
||||
}
|
||||
updated.insert(arg_name.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,16 +56,16 @@ impl Action {
|
||||
/// Il peut être remplacé via [`set_handler`](Self::set_handler).
|
||||
fn default_handler() -> ActionHandler {
|
||||
action_handler!(|data| {
|
||||
info!("🎬 Action called with default handler");
|
||||
|
||||
let mut s = String::new();
|
||||
// Logger les arguments
|
||||
for (key, value) in data.iter() {
|
||||
trace!(
|
||||
" {} = {}",
|
||||
s.push_str(&format![
|
||||
"- {} = {}\n",
|
||||
key,
|
||||
crate::actions::reflect_to_string(value.as_ref())
|
||||
);
|
||||
]);
|
||||
}
|
||||
info!("🎬 Action called with default handler\n\n{}", s);
|
||||
|
||||
// Retourner les données telles quelles
|
||||
Ok(data)
|
||||
|
||||
@@ -247,6 +247,10 @@ impl ArgumentInstance {
|
||||
pub fn get_variable_instance(&self) -> Option<Arc<StateVarInstance>> {
|
||||
self.variable_instance.read().unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn is_in(&self) -> bool {
|
||||
self.model.is_in()
|
||||
}
|
||||
}
|
||||
|
||||
impl UpnpInstance for ActionInstanceSet {
|
||||
|
||||
@@ -195,6 +195,16 @@ macro_rules! get {
|
||||
($data:expr, $key:expr, $type:ty) => {
|
||||
$crate::actions::get_value::<$type>($data, $key)?
|
||||
};
|
||||
($data:expr, $key:expr, $type:ty, $($msg:tt)+) => {{
|
||||
match $crate::actions::get_value::<$type>($data, $key) {
|
||||
Ok(value) => value,
|
||||
Err(_) => {
|
||||
let message = format!($($msg)+);
|
||||
tracing::error!("{}", message);
|
||||
return Err($crate::actions::ActionError::ArgumentError(message));
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
/// Macro pour insérer facilement une valeur dans ActionData.
|
||||
|
||||
@@ -312,10 +312,9 @@ impl SsdpServer {
|
||||
);
|
||||
match socket.send_to(resp.as_bytes(), src) {
|
||||
Ok(_) => {
|
||||
info!("📡 M-SEARCH response sent to {} with ST={}", src, nt);
|
||||
debug!(
|
||||
"📡 M-SEARCH response payload\n<details>\n\n```\n{}\n```\n</details>\n",
|
||||
resp
|
||||
"📡 M-SEARCH response sent to {} with ST={}\n\n### payload\n\n<details>\n\n```\n{}\n```\n</details>\n",
|
||||
src, nt, resp
|
||||
);
|
||||
}
|
||||
Err(e) => warn!("❌ Failed to send M-SEARCH response to {}: {}", src, e),
|
||||
|
||||
@@ -243,13 +243,16 @@ impl StateVarInstance {
|
||||
///
|
||||
/// Un `Box<dyn Reflect>` contenant la valeur actuelle
|
||||
pub fn to_reflect(&self) -> Box<dyn Reflect> {
|
||||
use crate::variable_types::StateVarType;
|
||||
|
||||
let current_value = self.value.read().unwrap().clone();
|
||||
self.parse_value(current_value)
|
||||
}
|
||||
|
||||
pub fn parse_value(&self, value: StateValue) -> Box<dyn Reflect> {
|
||||
use crate::variable_types::StateVarType;
|
||||
|
||||
// Parser uniquement pour les String
|
||||
if self.as_state_var_type() == StateVarType::String {
|
||||
if let StateValue::String(ref s) = current_value {
|
||||
if let StateValue::String(ref s) = value {
|
||||
if let Some(ref parser) = self.model.parse {
|
||||
match parser(s) {
|
||||
Ok(reflected) => return reflected,
|
||||
@@ -266,10 +269,8 @@ impl StateVarInstance {
|
||||
}
|
||||
}
|
||||
|
||||
// Conversion standard pour tous les autres types
|
||||
current_value.to_reflect()
|
||||
value.to_reflect()
|
||||
}
|
||||
|
||||
/// Définit la valeur depuis Box<dyn Reflect>
|
||||
///
|
||||
/// - Si type String ET marshal défini : utilise le marshal
|
||||
|
||||
Reference in New Issue
Block a user