mod file;
mod mqtt;
mod null;
pub use mqtt::DEF_MQTT_PORT;
use tokio::sync::mpsc;
use crate::manager::{TargetCommand, WaitPoint};
use crate::{comms::Terminated, manager::Component};
use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[serde(tag = "type")]
pub enum Target {
#[serde(rename = "file-out")]
File(file::target::File),
#[serde(rename = "mqtt-out")]
Mqtt(mqtt::target::Mqtt),
#[serde(rename = "null-out")]
Null(null::Target),
}
impl Target {
pub async fn run(
self,
component: Component,
cmd: mpsc::Receiver<TargetCommand>,
waitpoint: WaitPoint,
) -> Result<(), Terminated> {
match self {
Target::File(target) => {
target.run(component, cmd, waitpoint).await
}
Target::Mqtt(target) => {
target.run(component, cmd, waitpoint).await
}
Target::Null(target) => {
target.run(component, cmd, waitpoint).await
}
}
}
pub fn type_name(&self) -> &'static str {
match self {
Target::File(_) => "file-out",
Target::Mqtt(_) => "mqtt-out",
Target::Null(_) => "null-out",
}
}
}