diff --git a/Cargo.lock b/Cargo.lock index 45b26f1..f4c7c58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4583,7 +4583,7 @@ dependencies = [ [[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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-global-executor", "async-std", @@ -4647,7 +4647,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "zenoh-collections", ] @@ -4655,7 +4655,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "log", "serde", @@ -4667,12 +4667,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" [[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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "flume 0.11.0", "json5", @@ -4691,7 +4691,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "lazy_static", @@ -4701,7 +4701,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "aes 0.8.3", "hmac 0.12.1", @@ -4714,7 +4714,7 @@ dependencies = [ [[package]] name = "zenoh-ext" 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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "bincode", @@ -4734,7 +4734,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "hashbrown 0.14.0", "keyed-set", @@ -4748,7 +4748,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "async-trait", @@ -4767,7 +4767,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "async-trait", @@ -4784,7 +4784,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-rustls", "async-std", @@ -4810,7 +4810,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "async-trait", @@ -4826,7 +4826,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-rustls", "async-std", @@ -4851,7 +4851,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "async-trait", @@ -4870,7 +4870,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "async-trait", @@ -4888,7 +4888,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "async-trait", @@ -4908,7 +4908,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "proc-macro2", "quote", @@ -4948,12 +4948,13 @@ dependencies = [ [[package]] name = "zenoh-plugin-rest" 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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "anyhow", "async-std", "base64 0.21.4", "clap 4.4.11", + "const_format", "env_logger", "flume 0.11.0", "futures", @@ -4976,11 +4977,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ + "const_format", "libloading", "log", + "serde", "serde_json", + "zenoh-keyexpr", "zenoh-macros", "zenoh-result", "zenoh-util", @@ -4989,7 +4993,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "const_format", "hex", @@ -5005,7 +5009,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "anyhow", ] @@ -5013,7 +5017,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "event-listener 4.0.0", @@ -5028,7 +5032,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-executor", "async-global-executor", @@ -5059,7 +5063,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=simplified_load_plugin#18e6212a3d930ca1f9c6ad9fa78b1b23089a8ecf" dependencies = [ "async-std", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 23c5429..2e24d5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,16 +42,16 @@ regex = "1.7.1" rustc_version = "0.4" serde = "1.0.154" serde_json = "1.0.94" -zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = [ +zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "simplified_load_plugin", features = [ "unstable", ] } -zenoh-collections = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main" } -zenoh-core = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main" } -zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = [ +zenoh-collections = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "simplified_load_plugin" } +zenoh-core = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "simplified_load_plugin" } +zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "simplified_load_plugin", features = [ "unstable", ] } -zenoh-plugin-rest = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false } -zenoh-plugin-trait = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false } +zenoh-plugin-rest = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "simplified_load_plugin", default-features = false } +zenoh-plugin-trait = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "simplified_load_plugin", default-features = false } [profile.release] debug = false diff --git a/README.md b/README.md index c9d4b4b..8e89573 100644 --- a/README.md +++ b/README.md @@ -150,8 +150,6 @@ $ git clone https://github.com/eclipse-zenoh/zenoh-plugin-mqtt.git $ cd zenoh-plugin-mqtt ``` -> :warning: **WARNING** :warning: : On Windows and Linux, don't use `cargo build` command without specifying a package with `-p`. Building both `zenoh-plugin-mqtt` (plugin library) and `zenoh-bridge-mqtt` (standalone executable) together will lead to a `multiple definition of `load_plugin'` error at link time. See [#19](https://github.com/eclipse-zenoh/zenoh-plugin-mqtt/issues/19#issuecomment-1754742678) for explanations. - You can then choose between building the zenoh bridge for MQTT: - as a plugin library that can be dynamically loaded by the zenoh router (`zenohd`): ```bash diff --git a/zenoh-bridge-mqtt/src/main.rs b/zenoh-bridge-mqtt/src/main.rs index 6163929..307e7d8 100644 --- a/zenoh-bridge-mqtt/src/main.rs +++ b/zenoh-bridge-mqtt/src/main.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // use clap::{App, Arg}; +use zenoh_plugin_trait::Plugin; use std::str::FromStr; use zenoh::config::{Config, ModeDependentValue}; use zenoh::prelude::*; @@ -36,8 +37,8 @@ macro_rules! insert_json5 { fn parse_args() -> Config { let app = App::new("zenoh bridge for MQTT") - .version(zenoh_plugin_mqtt::GIT_VERSION) - .long_version(zenoh_plugin_mqtt::LONG_VERSION.as_str()) + .version(zenoh_plugin_mqtt::MqttPlugin::PLUGIN_VERSION) + .long_version(zenoh_plugin_mqtt::MqttPlugin::PLUGIN_LONG_VERSION) // // zenoh related arguments: // @@ -168,7 +169,7 @@ r#"-w, --generalise-pub=[String]... 'A list of key expression to use for gener #[async_std::main] async fn main() { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("z=info")).init(); - log::info!("zenoh-bridge-mqtt {}", *zenoh_plugin_mqtt::LONG_VERSION); + log::info!("zenoh-bridge-mqtt {}", zenoh_plugin_mqtt::MqttPlugin::PLUGIN_LONG_VERSION); let config = parse_args(); let rest_plugin = config.plugin("rest").is_some(); diff --git a/zenoh-plugin-mqtt/Cargo.toml b/zenoh-plugin-mqtt/Cargo.toml index b0325e5..b72802c 100644 --- a/zenoh-plugin-mqtt/Cargo.toml +++ b/zenoh-plugin-mqtt/Cargo.toml @@ -28,7 +28,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/zenoh-plugin-mqtt/src/lib.rs b/zenoh-plugin-mqtt/src/lib.rs index a44c2b4..d82a4b0 100644 --- a/zenoh-plugin-mqtt/src/lib.rs +++ b/zenoh-plugin-mqtt/src/lib.rs @@ -11,20 +11,21 @@ // Contributors: // ADLINK zenoh team, // -use git_version::git_version; use ntex::service::{fn_factory_with_config, fn_service}; use ntex::util::Ready; use ntex_mqtt::{v3, v5, MqttServer}; use serde_json::Value; use std::env; use std::sync::Arc; -use zenoh::plugins::{Plugin, RunningPluginTrait, Runtime, ZenohPlugin}; +use zenoh::plugins::{RunningPluginTrait, ZenohPlugin}; use zenoh::prelude::r#async::*; use zenoh::queryable::Query; +use zenoh::runtime::Runtime; use zenoh::Result as ZResult; use zenoh::Session; +use zenoh_core::zerror; use zenoh_core::zresult::ZError; -use zenoh_core::{bail, zerror}; +use zenoh_plugin_trait::{plugin_long_version, plugin_version, Plugin, PluginControl}; #[macro_use] extern crate zenoh_core; @@ -41,9 +42,7 @@ macro_rules! ke_for_sure { }; } -pub const GIT_VERSION: &str = git_version!(prefix = "v", cargo_prefix = "v"); lazy_static::lazy_static! { - pub static ref LONG_VERSION: String = format!("{} built with {}", GIT_VERSION, env!("RUSTC_VERSION")); static ref KE_PREFIX_ADMIN_SPACE: &'static keyexpr = ke_for_sure!("@/service"); static ref ADMIN_SPACE_KE_VERSION: &'static keyexpr = ke_for_sure!("version"); static ref ADMIN_SPACE_KE_CONFIG: &'static keyexpr = ke_for_sure!("config"); @@ -56,9 +55,11 @@ pub struct MqttPlugin; impl ZenohPlugin for MqttPlugin {} impl Plugin for MqttPlugin { type StartArgs = Runtime; - type RunningPlugin = zenoh::plugins::RunningPlugin; + type Instance = zenoh::plugins::RunningPlugin; - const STATIC_NAME: &'static str = "zenoh-plugin-mqtt"; + const DEFAULT_NAME: &'static str = "zenoh-plugin-mqtt"; + const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); + const PLUGIN_VERSION: &'static str = plugin_version!(); fn start(name: &str, runtime: &Self::StartArgs) -> ZResult { // Try to initiate login. @@ -66,7 +67,7 @@ impl Plugin for MqttPlugin { // But cannot be done twice in case of static link. 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))?; @@ -77,40 +78,15 @@ impl Plugin for MqttPlugin { } } -impl RunningPluginTrait for MqttPlugin { - fn config_checker(&self) -> zenoh::plugins::ValidationFunction { - Arc::new(|_, _, _| bail!("zenoh-plugin-mqtt does not support hot configuration changes.")) - } - - fn adminspace_getter<'a>( - &'a self, - selector: &'a Selector<'a>, - plugin_status_key: &str, - ) -> ZResult> { - log::error!( - "adminspace_getter {} - plugin_status_key: {}", - selector, - plugin_status_key - ); - let mut responses = Vec::new(); - let version_key = [plugin_status_key, "/__version__"].concat(); - if selector.key_expr.intersects(ke_for_sure!(&version_key)) { - log::error!("adminspace_getter reply version"); - responses.push(zenoh::plugins::Response::new( - version_key, - GIT_VERSION.into(), - )); - } - Ok(responses) - } -} +impl PluginControl for MqttPlugin {} +impl RunningPluginTrait for MqttPlugin {} async fn run(runtime: Runtime, config: Config) { // Try to initiate login. // Required in case of dynamic lib, otherwise no logs. // But cannot be done twice in case of static link. let _ = env_logger::try_init(); - log::debug!("MQTT plugin {}", LONG_VERSION.as_str()); + log::debug!("MQTT plugin {}", MqttPlugin::PLUGIN_LONG_VERSION); log::debug!("MQTT plugin {:?}", config); // init Zenoh Session with provided Runtime @@ -142,7 +118,7 @@ async fn run(runtime: Runtime, config: Config) { // Start MQTT Server task let config = Arc::new(config); - ntex::rt::System::new(MqttPlugin::STATIC_NAME) + ntex::rt::System::new(MqttPlugin::DEFAULT_NAME) .block_on(async move { ntex::server::Server::build() .bind("mqtt", config.port.clone(), move |_| { @@ -217,7 +193,10 @@ fn treat_admin_query(query: Query, admin_keyexpr_prefix: &keyexpr, config: &Conf let mut kvs: Vec<(&keyexpr, Value)> = Vec::with_capacity(sub_kes.len()); for sub_ke in sub_kes { if sub_ke.intersects(&ADMIN_SPACE_KE_VERSION) { - kvs.push((&ADMIN_SPACE_KE_VERSION, Value::String(LONG_VERSION.clone()))); + kvs.push(( + &ADMIN_SPACE_KE_VERSION, + Value::String(MqttPlugin::PLUGIN_LONG_VERSION.to_string()), + )); } if sub_ke.intersects(&ADMIN_SPACE_KE_CONFIG) { kvs.push(( diff --git a/zenoh-plugin-mqtt/src/mqtt_helpers.rs b/zenoh-plugin-mqtt/src/mqtt_helpers.rs index b137010..e06b606 100644 --- a/zenoh-plugin-mqtt/src/mqtt_helpers.rs +++ b/zenoh-plugin-mqtt/src/mqtt_helpers.rs @@ -16,7 +16,7 @@ use ntex::util::{ByteString, Bytes}; use ntex_mqtt::{error::SendPacketError, v3, v5}; use std::convert::TryInto; use std::sync::{Arc, Mutex}; -use zenoh::plugins::ZResult; +use zenoh::Result as ZResult; use zenoh::prelude::*; use zenoh_core::zlock; diff --git a/zenoh-plugin-mqtt/src/mqtt_session_state.rs b/zenoh-plugin-mqtt/src/mqtt_session_state.rs index 15ced1c..2356aaf 100644 --- a/zenoh-plugin-mqtt/src/mqtt_session_state.rs +++ b/zenoh-plugin-mqtt/src/mqtt_session_state.rs @@ -18,7 +18,7 @@ use lazy_static::__Deref; use ntex::util::{ByteString, Bytes}; use std::convert::TryInto; use std::{collections::HashMap, sync::Arc}; -use zenoh::plugins::ZResult; +use zenoh::Result as ZResult; use zenoh::prelude::r#async::*; use zenoh::subscriber::Subscriber;