Skip to content

Commit

Permalink
strip_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Nov 13, 2023
1 parent 7e586cb commit 0cf6ca4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
4 changes: 2 additions & 2 deletions plugins/zenoh-backend-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ use zenoh::queryable::ReplyBuilder;
use zenoh::time::Timestamp;
use zenoh::value::Value;
pub use zenoh::Result as ZResult;
use zenoh_plugin_trait::{concat_enabled_features, PluginStructVersion, PluginControl, PluginInstance};
use zenoh_plugin_trait::{concat_enabled_features, PluginStructVersion, PluginControl, PluginInstance, PluginStatus};

pub mod config;
use config::{StorageConfig, VolumeConfig};
Expand Down Expand Up @@ -233,7 +233,7 @@ impl PluginStructVersion for VolumePlugin {
}

impl PluginControl for VolumePlugin {
fn plugins(&self) -> Vec<String> {
fn plugins(&self, _names: &zenoh::prelude::keyexpr) -> Vec<(String, PluginStatus)> {
Vec::new()
}
}
Expand Down
9 changes: 7 additions & 2 deletions plugins/zenoh-plugin-storage-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
use async_std::task;
use flume::Sender;
use memory_backend::MemoryBackend;
use zenoh_plugin_trait::PluginCondition;
use zenoh_plugin_trait::PluginControl;
use zenoh_plugin_trait::PluginStatus;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::sync::Arc;
Expand Down Expand Up @@ -222,9 +224,12 @@ impl From<StorageRuntimeInner> for StorageRuntime {
}

impl PluginControl for StorageRuntime {
fn plugins(&self) -> Vec<String> {
fn condition(&self) -> PluginCondition {
PluginCondition::default()
}
fn plugins(&self, names: &keyexpr) -> Vec<(String, PluginStatus)> {
let guard = self.0.lock().unwrap();
guard.plugins_manager.plugins()
guard.plugins_manager.plugins(names)
}
}

Expand Down
7 changes: 4 additions & 3 deletions plugins/zenoh-plugin-trait/src/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,19 @@ impl<StartArgs: PluginStartArgs + 'static, Instance: PluginInstance + 'static>
impl<StartArgs: PluginStartArgs + 'static, Instance: PluginInstance + 'static> PluginControl
for PluginsManager<StartArgs, Instance>
{
fn plugins(&self, prefix: &keyexpr, names: &keyexpr) -> Vec<(String, PluginStatus)> {
fn plugins(&self, names: &keyexpr) -> Vec<(String, PluginStatus)> {
let mut plugins = Vec::new();
for plugin in self.declared_plugins() {
let name = prefix.join(plugin.name()).unwrap();
let name = unsafe { keyexpr::from_str_unchecked(plugin.name()) };
if names.includes(name) {
plugins.push((plugin.name().to_string(), plugin.status()));
}
// for running plugins append their subplugins prepended with the running plugin name
if let Some(plugin) = plugin.loaded() {
if let Some(plugin) = plugin.started() {
plugins.append(&mut plugin.instance().plugins(names));
if let [names, ..] = names.strip_prefix(name)[..] {
plugins.append(&mut plugin.instance().plugins(names));
}
}
}
}
Expand Down
22 changes: 2 additions & 20 deletions plugins/zenoh-plugin-trait/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,8 @@ pub trait PluginControl {
fn condition(&self) -> PluginCondition {
PluginCondition::default()
}
/// Collect information of sub-plugins matching `_names` keyexpr excluding `_prefix` part
/// The prefix parameter allows to pass a request to plugins tree without changing the request.
///
/// For example:
/// - when request is "@/router/XXXX/plugins/**", it's passed to root plugin manager as
/// `plugins("@/router/XXXX/plugins", "@/router/XXXX/plugins/**")`
/// - for plugin named `storages` the combined name is `@/router/XXXX/plugins/storages` which matches the request
/// - for sub-plugins of"storages" plugin the root manager calls
/// `plugins("@/router/XXXX/plugins/storages", "@/router/XXXX/plugins/**")`
///
/// Another example:
/// - when request is "@/router/XXXX/plugins/*/memory", it's passed to root plugin manager as
/// `plugins("@/router/XXXX/plugins", "@/router/XXXX/plugins/*/memory")`
/// - storages plugin itself doesn't match the request: `@/router/XXXX/plugins/storages` doesn't match `@/router/XXXX/plugins/*/memory`
/// - request is passed to storages plugin anyway as
/// `plugins("@/router/XXXX/plugins/storages", "@/router/XXXX/plugins/*/memory")`
/// - subplugin "memory" matches the request: `@/router/XXXX/plugins/storages/memory` matches `@/router/XXXX/plugins/*/memory`
///
/// I.e. it's important that all items of plugin tree are checked for matching the request, no matter if parent plugin matches it or not.
fn plugins(&self, _prefix: &keyexpr, _names: &keyexpr) -> Vec<(String, PluginStatus)> {
/// Collect information of sub-plugins matching `_names` keyexpr
fn plugins(&self, _names: &keyexpr) -> Vec<(String, PluginStatus)> {
Vec::new()
}
}
Expand Down

0 comments on commit 0cf6ca4

Please sign in to comment.