blob: cf38dee9d88b24f12c90af3915c25b1675dcb5af (
plain)
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
|
use crate::c8y_converter::CumulocityConverter;
use crate::component::TEdgeComponent;
use crate::mapper::*;
use crate::size_threshold::SizeThreshold;
use async_trait::async_trait;
use tedge_config::{ConfigSettingAccessor, DeviceIdSetting, DeviceTypeSetting, TEdgeConfig};
use tracing::{info_span, Instrument};
const CUMULOCITY_MAPPER_NAME: &str = "tedge-mapper-c8y";
pub struct CumulocityMapper {}
impl CumulocityMapper {
pub fn new() -> CumulocityMapper {
CumulocityMapper {}
}
}
#[async_trait]
impl TEdgeComponent for CumulocityMapper {
async fn start(&self, tedge_config: TEdgeConfig) -> Result<(), anyhow::Error> {
let size_threshold = SizeThreshold(16 * 1024);
let device_name = tedge_config.query(DeviceIdSetting)?;
let device_type = tedge_config.query(DeviceTypeSetting)?;
let converter = Box::new(CumulocityConverter::new(
size_threshold,
device_name,
device_type,
));
let mut mapper = create_mapper(CUMULOCITY_MAPPER_NAME, &tedge_config, converter).await?;
mapper
.run()
.instrument(info_span!(CUMULOCITY_MAPPER_NAME))
.await?;
Ok(())
}
}
|