Skip to content

Commit 5c48fd4

Browse files
authored
Bridge: fix static loading of plugins (#81)
1 parent 4b0e3c7 commit 5c48fd4

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

zenoh-bridge-mqtt/src/main.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use clap::{App, Arg};
1515
use std::str::FromStr;
1616
use zenoh::config::{Config, ModeDependentValue};
17+
use zenoh::plugins::PluginsManager;
1718
use zenoh::prelude::r#async::*;
19+
use zenoh::runtime::RuntimeBuilder;
1820
use zenoh_plugin_trait::Plugin;
1921

2022
macro_rules! insert_json5 {
@@ -200,9 +202,35 @@ async fn main() {
200202
);
201203

202204
let config = parse_args();
205+
tracing::info!("Zenoh {config:?}");
203206

204-
// create a zenoh session. Plugins are loaded by the open.
205-
let _session = zenoh::open(config).res().await.unwrap();
207+
let mut plugins_mgr = PluginsManager::static_plugins_only();
208+
209+
// declare REST plugin if specified in conf
210+
if config.plugin("rest").is_some() {
211+
plugins_mgr = plugins_mgr.declare_static_plugin::<zenoh_plugin_rest::RestPlugin>(true);
212+
}
213+
214+
// declare ROS2DDS plugin
215+
plugins_mgr = plugins_mgr.declare_static_plugin::<zenoh_plugin_mqtt::MqttPlugin>(true);
216+
217+
// create a zenoh Runtime.
218+
let runtime = match RuntimeBuilder::new(config)
219+
.plugins_manager(plugins_mgr)
220+
.build()
221+
.await
222+
{
223+
Ok(runtime) => runtime,
224+
Err(e) => {
225+
println!("{e}. Exiting...");
226+
std::process::exit(-1);
227+
}
228+
};
229+
// create a zenoh Session.
230+
let _session = zenoh::init(runtime).res().await.unwrap_or_else(|e| {
231+
println!("{e}. Exiting...");
232+
std::process::exit(-1);
233+
});
206234

207235
async_std::future::pending::<()>().await;
208236
}

zenoh-plugin-mqtt/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Plugin for MqttPlugin {
7171
type StartArgs = Runtime;
7272
type Instance = zenoh::plugins::RunningPlugin;
7373

74-
const DEFAULT_NAME: &'static str = "zenoh-plugin-mqtt";
74+
const DEFAULT_NAME: &'static str = "mqtt";
7575
const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!();
7676
const PLUGIN_VERSION: &'static str = plugin_version!();
7777

@@ -117,7 +117,7 @@ async fn run(
117117
// But cannot be done twice in case of static link.
118118
zenoh_util::try_init_log_from_env();
119119
tracing::debug!("MQTT plugin {}", MqttPlugin::PLUGIN_LONG_VERSION);
120-
tracing::debug!("MQTT plugin {:?}", config);
120+
tracing::info!("MQTT plugin {:?}", config);
121121

122122
// init Zenoh Session with provided Runtime
123123
let zsession = match zenoh::init(runtime)

0 commit comments

Comments
 (0)