use serde_json::Value;
use zenoh_core::zconfigurable;
use zenoh_plugin_trait::{Plugin, PluginControl, PluginInstance, PluginReport, PluginStatusRec};
use zenoh_protocol::core::key_expr::keyexpr;
use zenoh_result::ZResult;
use zenoh_util::ffi::{JsonKeyValueMap, JsonValue};
use crate::{api::key_expr::KeyExpr, net::runtime::DynamicRuntime};
zconfigurable! {
pub static ref PLUGIN_PREFIX: String = "zenoh_plugin_".to_string();
}
pub type RunningPlugin = Box<dyn RunningPluginTrait + Send + Sync + 'static>;
pub trait ZenohPlugin: Plugin<StartArgs = DynamicRuntime, Instance = RunningPlugin> {}
impl PluginControl for RunningPlugin {
fn report(&self) -> PluginReport {
self.as_ref().report()
}
fn plugins_status(&self, names: &keyexpr) -> Vec<PluginStatusRec<'_>> {
self.as_ref().plugins_status(names)
}
}
impl PluginInstance for RunningPlugin {}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct Response {
pub key: String,
pub value: JsonValue,
}
impl Response {
pub fn new(key: String, value: Value) -> Self {
Self {
key,
value: value.into(),
}
}
}
pub trait RunningPluginTrait: Send + Sync + PluginControl {
fn config_checker(
&self,
_path: &str,
_current: &JsonKeyValueMap,
_new: &JsonKeyValueMap,
) -> ZResult<Option<JsonKeyValueMap>> {
bail!("Runtime configuration change not supported");
}
fn adminspace_getter<'a>(
&'a self,
_key_expr: &'a KeyExpr<'a>,
_plugin_status_key: &str,
) -> ZResult<Vec<Response>> {
Ok(Vec::new())
}
}
pub type PluginsManager = zenoh_plugin_trait::PluginsManager<DynamicRuntime, RunningPlugin>;