1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
use async_trait::async_trait;
use tokio_util::sync::CancellationToken;
use tedge_api::plugin::BuiltPlugin;
use tedge_api::plugin::HandleTypes;
use tedge_api::plugin::PluginExt;
use tedge_api::PluginBuilder;
use tedge_api::PluginConfiguration;
use tedge_api::PluginDirectory;
use tedge_api::PluginError;
use tedge_lib::measurement::Measurement;
use crate::config::MeasurementFilterConfig;
use crate::plugin::MeasurementFilterPlugin;
tedge_api::make_receiver_bundle!(pub struct MeasurementReceiver(Measurement));
pub struct MeasurementFilterPluginBuilder;
#[async_trait]
impl<PD> PluginBuilder<PD> for MeasurementFilterPluginBuilder
where
PD: PluginDirectory,
{
fn kind_name() -> &'static str {
"measurement_filter"
}
fn kind_message_types() -> HandleTypes
where
Self: Sized,
{
MeasurementFilterPlugin::get_handled_types()
}
async fn verify_configuration(
&self,
config: &PluginConfiguration,
) -> Result<(), tedge_api::error::PluginError> {
config
.clone()
.try_into()
.map(|_: MeasurementFilterConfig| ())
.map_err(crate::error::Error::from)
.map_err(PluginError::from)
}
async fn instantiate(
&self,
config: PluginConfiguration,
_cancellation_token: CancellationToken,
plugin_dir: &PD,
) -> Result<BuiltPlugin, PluginError> {
let config = config
.try_into::<MeasurementFilterConfig>()
.map_err(crate::error::Error::from)?;
let main_addr = plugin_dir.get_address_for(&config.target)?;
let filtered_addr = config
.filtered_target
.as_ref()
.map(|filtered| plugin_dir.get_address_for(filtered))
.transpose()?;
Ok({
MeasurementFilterPlugin::new(main_addr, filtered_addr, config.extractor, config.filter)
.finish()
})
}
}
|