From 47daf4c6d387d7632a8a66ad058f5feacd73c267 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Tue, 10 Oct 2023 15:31:57 +0000 Subject: [PATCH] removing ValidationFunction unfinished --- zenoh/src/net/runtime/adminspace.rs | 22 +++++++++++++++++++--- zenoh/src/plugins/sealed.rs | 9 ++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/zenoh/src/net/runtime/adminspace.rs b/zenoh/src/net/runtime/adminspace.rs index 92ab103bb6..99b48367cd 100644 --- a/zenoh/src/net/runtime/adminspace.rs +++ b/zenoh/src/net/runtime/adminspace.rs @@ -192,13 +192,28 @@ impl AdminSpace { let name = &plugin.name; log::info!("Loaded plugin `{}` from {}", name, &path); match plugins_mgr.start(name, &admin.context.runtime) { - Ok(Some((path, plugin))) => { + Ok(Some((path, _))) => { active_plugins.insert(name.into(), path.into()); let mut cfg_guard = admin.context.runtime.state.config.lock(); + let validation_function = { + let name = name.clone(); + let admin = admin.clone(); + Arc::new(move |path: &_, old: &_, new: &_| { + let plugins_mgr = + zlock!(admin.context.plugins_mgr); + if let Some(plugin) = + plugins_mgr.plugin(name.as_str()) + { + plugin.config_checker(path, old, new) + } else { + Err("Plugin not found".into()) + } + }) + }; cfg_guard.add_plugin_validator( name, - plugin.config_checker(), + validation_function, ); log::info!( "Successfully started plugin `{}` from {}", @@ -307,7 +322,8 @@ impl Primitives for AdminSpace { key, json ); - if let Err(e) = (&self.context.runtime.state.config).insert_json5(key, json) { + if let Err(e) = (&self.context.runtime.state.config).insert_json5(key, json) + { error!( "Error inserting conf value /@/router/{}/config/{} : {} - {}", &self.context.zid_str, key, json, e diff --git a/zenoh/src/plugins/sealed.rs b/zenoh/src/plugins/sealed.rs index 6caabca990..037aa50c83 100644 --- a/zenoh/src/plugins/sealed.rs +++ b/zenoh/src/plugins/sealed.rs @@ -45,8 +45,8 @@ impl Response { } } -pub trait RunningPluginTrait: Send + Sync + std::any::Any { - /// Returns a function that will be called when configuration relevant to the plugin is about to change. +pub trait RunningPluginTrait: Send + Sync { + /// Function that will be called when configuration relevant to the plugin is about to change. /// /// This function is called with 3 arguments: /// * `path`, the relative path from the plugin's configuration root to the changed value. @@ -58,7 +58,10 @@ pub trait RunningPluginTrait: Send + Sync + std::any::Any { /// Useful when the changes affect settings that aren't hot-configurable for your plugin. /// * `Ok(None)` indicates that the plugin has accepted the configuration change. /// * `Ok(Some(value))` indicates that the plugin would rather the new configuration be `value`. - fn config_checker(&self) -> ValidationFunction; + fn config_checker(&self, + path: &str, + current: &serde_json::Map, + new: &serde_json::Map) -> ZResult>>; /// Used to request your plugin's status for the administration space. fn adminspace_getter<'a>( &'a self,