diff --git a/Cargo.lock b/Cargo.lock index fe220a5..2af6725 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3607,7 +3607,7 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "zenoh" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-global-executor", "async-std", @@ -3655,7 +3655,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "zenoh-collections", ] @@ -3663,7 +3663,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "log", "serde", @@ -3675,12 +3675,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" [[package]] name = "zenoh-config" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "flume", "json5", @@ -3699,7 +3699,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "lazy_static", @@ -3709,7 +3709,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "aes 0.8.3", "hmac 0.12.1", @@ -3722,7 +3722,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "hashbrown 0.14.0", "keyed-set", @@ -3736,7 +3736,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -3755,7 +3755,7 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -3772,7 +3772,7 @@ dependencies = [ [[package]] name = "zenoh-link-quic" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-rustls", "async-std", @@ -3798,7 +3798,7 @@ dependencies = [ [[package]] name = "zenoh-link-tcp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -3814,7 +3814,7 @@ dependencies = [ [[package]] name = "zenoh-link-tls" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-rustls", "async-std", @@ -3839,7 +3839,7 @@ dependencies = [ [[package]] name = "zenoh-link-udp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -3858,7 +3858,7 @@ dependencies = [ [[package]] name = "zenoh-link-unixsock_stream" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -3876,7 +3876,7 @@ dependencies = [ [[package]] name = "zenoh-link-ws" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", @@ -3896,7 +3896,7 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "proc-macro2", "quote", @@ -3909,11 +3909,14 @@ dependencies = [ [[package]] name = "zenoh-plugin-trait" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ + "const_format", "libloading", "log", + "serde", "serde_json", + "zenoh-keyexpr", "zenoh-macros", "zenoh-result", "zenoh-util", @@ -3942,7 +3945,7 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "const_format", "hex", @@ -3958,7 +3961,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "anyhow", ] @@ -3966,7 +3969,7 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "event-listener 4.0.0", @@ -3981,7 +3984,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-executor", "async-global-executor", @@ -4012,7 +4015,7 @@ dependencies = [ [[package]] name = "zenoh-util" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#b669489bc814a758741f09c671ecc3a0683697a0" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#8cd786f2192fd2aa7387432ae93cdd78f5db1df2" dependencies = [ "async-std", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 32404a3..49aa2c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ crate-type = ["cdylib", "rlib"] [features] default = ["no_mangle"] -no_mangle = ["zenoh-plugin-trait/no_mangle"] +no_mangle = [] stats = ["zenoh/stats"] [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 500f9f0..1658cb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,32 +21,37 @@ use std::str::FromStr; use tide::http::Mime; use tide::{Request, Response, Server, StatusCode}; use zenoh::buffers::ZBuf; -use zenoh::plugins::{Plugin, RunningPlugin, RunningPluginTrait, Runtime, ZenohPlugin}; +use zenoh::plugins::{RunningPlugin, RunningPluginTrait, ZenohPlugin}; use zenoh::query::Reply; +use zenoh::runtime::Runtime; use zenoh::Result as ZResult; use zenoh::{prelude::r#async::*, Session}; use zenoh_core::{bail, zerror}; +use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin, PluginControl}; mod config; use config::Config; const DEFAULT_DIRECTORY_INDEX: &str = "index.html"; -const GIT_VERSION: &str = git_version::git_version!(prefix = "v", cargo_prefix = "v"); lazy_static::lazy_static! { - static ref LONG_VERSION: String = format!("{} built with {}", GIT_VERSION, env!("RUSTC_VERSION")); static ref DEFAULT_MIME: Mime = Mime::from_str(KnownEncoding::AppOctetStream.into()).unwrap(); } - pub struct WebServerPlugin; +impl PluginControl for WebServerPlugin {} impl ZenohPlugin for WebServerPlugin {} + impl Plugin for WebServerPlugin { type StartArgs = Runtime; - type RunningPlugin = RunningPlugin; + type Instance = RunningPlugin; + + const DEFAULT_NAME: &'static str = "zenoh-plugin-webserver"; + const PLUGIN_VERSION: &'static str = plugin_version!(); + const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); fn start(name: &str, runtime: &Self::StartArgs) -> ZResult { let _ = env_logger::try_init(); - let runtime_conf = runtime.config.lock(); + let runtime_conf = runtime.config().lock(); let plugin_conf = runtime_conf .plugin(name) .ok_or_else(|| zerror!("Plugin `{}`: missing config", name))?; @@ -55,31 +60,15 @@ impl Plugin for WebServerPlugin { async_std::task::spawn(run(runtime.clone(), conf)); Ok(Box::new(WebServerPlugin)) } - - const STATIC_NAME: &'static str = "webserver"; -} -impl RunningPluginTrait for WebServerPlugin { - fn config_checker(&self) -> zenoh::plugins::ValidationFunction { - Arc::new(|name, _, _| { - bail!( - "Plugin `{}` doesn't support hot configuration changes", - name - ) - }) - } - fn adminspace_getter<'a>( - &'a self, - _selector: &'a Selector<'a>, - _plugin_status_key: &str, - ) -> ZResult> { - Ok(Vec::new()) - } } +impl RunningPluginTrait for WebServerPlugin {} + +#[cfg(feature = "no_mangle")] zenoh_plugin_trait::declare_plugin!(WebServerPlugin); async fn run(runtime: Runtime, conf: Config) { - debug!("WebServer plugin {}", LONG_VERSION.as_str()); + debug!("WebServer plugin {}", WebServerPlugin::PLUGIN_LONG_VERSION); let zenoh = match zenoh::init(runtime).res().await { Ok(session) => Arc::new(session),