Skip to content

Commit

Permalink
Merge branch 'simplified_load_plugin' of github.com:eclipse-zenoh/zen…
Browse files Browse the repository at this point in the history
…oh into simplified_load_plugin
  • Loading branch information
milyin committed Jan 8, 2024
2 parents bc0d0d2 + 0135797 commit 6af0ee7
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 37 deletions.
24 changes: 12 additions & 12 deletions DEFAULT_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -407,17 +407,17 @@
// },

/// Plugin configuration example using `__config__` property
plugins: {
rest: {
__config__: "./plugins/zenoh-plugin-rest/config.json5",
},
storage_manager: {
__config__: "./plugins/zenoh-plugin-storage-manager/config.json5",
},
not_found: {
},
example: {
},
},
// plugins: {
// rest: {
// __config__: "./plugins/zenoh-plugin-rest/config.json5",
// },
// storage_manager: {
// __config__: "./plugins/zenoh-plugin-storage-manager/config.json5",
// },
// not_found: {
// },
// example: {
// },
// },

}
31 changes: 31 additions & 0 deletions plugin_test_config.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"plugins": {
"rest": {
"http_port": 8080,
},
"storage_manager": {
"volumes": {
"example": {
"__path__": ["target/debug/libzenoh_backend_example.so","target/debug/libzenoh_backend_example.dylib"],
}
},
"storages": {
"memory": {
"volume": "memory",
"key_expr": "demo/memory/**"
},
"example": {
"volume": "example",
"key_expr": "demo/example/**"
},
}
},
"not_found": {
},
"example": {
},
"dds": {
"__path__": ["../zenoh-plugin-dds/target/debug/libzenoh_plugin_dds.so","../zenoh-plugin-dds/target/debug/libzenoh_plugin_dds.dylib"],
}
}
}
4 changes: 4 additions & 0 deletions plugins/example-storage-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }

[features]
default = ["no_mangle"]
no_mangle = []

[lib]
name = "zenoh_backend_example"
# This crate type will make `cargo` output a dynamic library instead of a rust static library
Expand Down
2 changes: 1 addition & 1 deletion plugins/zenoh-backend-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! ⚠️ WARNING ⚠️
//!
//! TODO: The example is outdated, rewrite it
//!
//!
//! This crate should be considered unstable, as in we might change the APIs anytime.
//!
//! This crate provides the traits to be implemented by a zenoh backend library:
Expand Down
28 changes: 15 additions & 13 deletions plugins/zenoh-plugin-storage-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use zenoh_backend_traits::config::VolumeConfig;
use zenoh_backend_traits::VolumePlugin;
use zenoh_core::zlock;
use zenoh_plugin_trait::Plugin;
use zenoh_plugin_trait::PluginConditionSetter;
use zenoh_plugin_trait::PluginControl;
use zenoh_plugin_trait::PluginReport;
use zenoh_plugin_trait::PluginStatusRec;
Expand Down Expand Up @@ -115,7 +114,6 @@ impl StorageRuntimeInner {
let plugins_manager = PluginsManager::dynamic(lib_loader.clone(), BACKEND_LIB_PREFIX)
.declare_static_plugin::<MemoryBackend>();


let session = Arc::new(zenoh::init(runtime.clone()).res_sync()?);

// After this moment result should be only Ok. Failure of loading of one voulme or storage should not affect others.
Expand All @@ -127,20 +125,24 @@ impl StorageRuntimeInner {
storages: Default::default(),
plugins_manager,
};
let _ = new_self.spawn_volume(VolumeConfig {
name: MEMORY_BACKEND_NAME.into(),
backend: None,
paths: None,
required: false,
rest: Default::default(),
});
new_self
.spawn_volume(VolumeConfig {
name: MEMORY_BACKEND_NAME.into(),
backend: None,
paths: None,
required: false,
rest: Default::default(),
})
.map_or_else(|e| log::error!("Cannot spawn memory volume: {}", e), |_| ());
for volume in volumes {
let _ = new_self
.spawn_volume(volume);
new_self
.spawn_volume(volume)
.map_or_else(|e| log::error!("Cannot spawn volume: {}", e), |_| ());
}
for storage in storages {
let _ = new_self
.spawn_storage(storage);
new_self
.spawn_storage(storage)
.map_or_else(|e| log::error!("Cannot spawn storage: {}", e), |_| ());
}
Ok(new_self)
}
Expand Down
6 changes: 2 additions & 4 deletions plugins/zenoh-plugin-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ pub use plugin::{
pub use vtable::{Compatibility, PluginLoaderVersion, PluginVTable, PLUGIN_LOADER_VERSION};
use zenoh_util::concat_enabled_features;

pub const FEATURES: &str = concat_enabled_features!(
prefix = "zenoh-plugin-trait",
features = ["default"]
);
pub const FEATURES: &str =
concat_enabled_features!(prefix = "zenoh-plugin-trait", features = ["default"]);
2 changes: 1 addition & 1 deletion plugins/zenoh-plugin-trait/src/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,4 @@ macro_rules! declare_plugin {
$crate::PluginVTable::new::<$ty>()
}
};
}
}
2 changes: 1 addition & 1 deletion zenoh/src/net/routing/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl FaceState {
})
}

#[cfg(feature = "unstable")]
#[allow(dead_code)]
#[inline]
pub fn is_local(&self) -> bool {
self.local
Expand Down
6 changes: 3 additions & 3 deletions zenoh/src/net/runtime/adminspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ use crate::value::Value;
use async_std::task;
use log::{error, trace};
use serde_json::json;
use zenoh_plugin_trait::{PluginControl, PluginStatus};
use zenoh_protocol::core::key_expr::keyexpr;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::convert::TryInto;
use std::sync::Arc;
use std::sync::Mutex;
use zenoh_buffers::buffer::SplitBuffer;
use zenoh_config::{ValidatedMap, ConfigValidator};
use zenoh_config::{ConfigValidator, ValidatedMap};
use zenoh_plugin_trait::{PluginControl, PluginStatus};
use zenoh_protocol::core::key_expr::keyexpr;
use zenoh_protocol::{
core::{key_expr::OwnedKeyExpr, ExprId, KnownEncoding, WireExpr, ZenohId, EMPTY_EXPR_ID},
network::{
Expand Down
5 changes: 3 additions & 2 deletions zenoh/src/plugins/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ pub use crate::runtime::Runtime;
pub use crate::Result as ZResult;
use zenoh_core::zconfigurable;

use zenoh_plugin_trait::{Plugin, PluginControl, PluginInstance, PluginReport, PluginStatusRec, PluginStructVersion};
use zenoh_plugin_trait::{
Plugin, PluginControl, PluginInstance, PluginReport, PluginStatusRec, PluginStructVersion,
};
use zenoh_protocol::core::key_expr::keyexpr;

zconfigurable! {
pub static ref PLUGIN_PREFIX: String = "zenoh_plugin_".to_string();
}

/// Zenoh plugins should implement this trait to ensure type-safety, even if the starting arguments and expected plugin types change in a future release.
pub trait ZenohPlugin: Plugin<StartArgs = StartArgs, Instance = RunningPlugin> {}

Expand Down

0 comments on commit 6af0ee7

Please sign in to comment.