Skip to content

Commit

Permalink
removing ValidationFunction unfinished
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Oct 10, 2023
1 parent e0dbcf5 commit 47daf4c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 19 additions & 3 deletions zenoh/src/net/runtime/adminspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}",
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions zenoh/src/plugins/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<String, serde_json::Value>,
new: &serde_json::Map<String, serde_json::Value>) -> ZResult<Option<serde_json::Map<String, serde_json::Value>>>;
/// Used to request your plugin's status for the administration space.
fn adminspace_getter<'a>(
&'a self,
Expand Down

0 comments on commit 47daf4c

Please sign in to comment.