diff options
author | Matthias Beyer <matthias.beyer@ifm.com> | 2022-05-12 12:23:34 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@ifm.com> | 2022-05-12 15:03:09 +0200 |
commit | b284b3c1b27764fbb869005d7f4e543cf63fba7d (patch) | |
tree | f68f7e580dfc3152cbd26d6541a2694310af6423 | |
parent | 4e6c6974fc15c8b5db061afb10f14a58f175db92 (diff) |
plugin_mqtt: Make config type self-describing
This patch rewrites the configuration type to be self-describing and
adapts the `PluginBuilder` implementation to implement the
`PluginBuilder::kind_configuration()` interface.
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r-- | plugins/plugin_mqtt/src/builder.rs | 4 | ||||
-rw-r--r-- | plugins/plugin_mqtt/src/config.rs | 24 |
2 files changed, 26 insertions, 2 deletions
diff --git a/plugins/plugin_mqtt/src/builder.rs b/plugins/plugin_mqtt/src/builder.rs index 05c5c4c3..4deed268 100644 --- a/plugins/plugin_mqtt/src/builder.rs +++ b/plugins/plugin_mqtt/src/builder.rs @@ -28,6 +28,10 @@ where "mqtt" } + fn kind_configuration() -> Option<tedge_api::ConfigDescription> { + Some(<MqttConfig as tedge_api::AsConfig>::as_config()) + } + fn kind_message_types() -> HandleTypes where Self: Sized, diff --git a/plugins/plugin_mqtt/src/config.rs b/plugins/plugin_mqtt/src/config.rs index 8c17ccc7..30e0665a 100644 --- a/plugins/plugin_mqtt/src/config.rs +++ b/plugins/plugin_mqtt/src/config.rs @@ -1,4 +1,4 @@ -#[derive(serde::Deserialize, Debug)] +#[derive(serde::Deserialize, Debug, tedge_api::Config)] pub struct MqttConfig { /// MQTT host to connect to pub host: String, @@ -13,9 +13,12 @@ pub struct MqttConfig { } -#[derive(Debug, serde::Deserialize)] +#[derive(Debug, serde::Deserialize, tedge_api::Config)] pub struct Subscription { + /// The topic to connect to pub(crate) topic: String, + + /// The Quality of Service to use for the subscribed topic pub(crate) qos: QoS, } @@ -31,6 +34,23 @@ pub enum QoS { ExactlyOnce, } +impl tedge_api::AsConfig for QoS { + fn as_config() -> tedge_api::ConfigDescription { + tedge_api::ConfigDescription::new( + "Qos".to_string(), + tedge_api::ConfigKind::Enum( + tedge_api::config::ConfigEnumKind::Untagged, + vec![ + ("String", Some("QOS 0"), tedge_api::config::EnumVariantRepresentation::String("at_most_once")), + ("String", Some("QOS 1"), tedge_api::config::EnumVariantRepresentation::String("at_least_once")), + ("String", Some("QOS 2"), tedge_api::config::EnumVariantRepresentation::String("exactly_once")), + ] + ), + None, + ) + } +} + impl Into<i32> for QoS { fn into(self) -> i32 { match self { |