summaryrefslogtreecommitdiffstats
path: root/plugins/plugin_c8y/src/plugin.rs
blob: 31d104ca2735bccad941268ca7588cd403e34ea8 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use async_trait::async_trait;

use tedge_api::address::ReplySenderFor;
use tedge_api::plugin::Handle;
use tedge_api::Plugin;
use tedge_api::PluginError;
use tedge_lib::measurement::Measurement;
use plugin_mqtt::IncomingMessage;

use crate::config::C8yConfig;

#[derive(Debug)]
pub struct C8yPlugin {
    config: C8yConfig,
}

impl C8yPlugin {
    pub(crate) fn new(config: C8yConfig) -> Self {
        Self {
            config,
        }
    }
}

impl tedge_api::plugin::PluginDeclaration for C8yPlugin {
    type HandledMessages = (IncomingMessage, Measurement);
}

#[async_trait]
impl Plugin for C8yPlugin {
    #[tracing::instrument(name = "plugin.c8y.start", skip(self))]
    async fn start(&mut self) -> Result<(), PluginError> {
        Ok(())
    }

    #[tracing::instrument(name = "plugin.c8y.shutdown", skip(self))]
    async fn shutdown(&mut self) -> Result<(), PluginError> {
        Ok(())
    }
}

#[async_trait]
impl Handle<Measurement> for C8yPlugin {
    #[tracing::instrument(name = "plugin.c8y.handle_message", level = "trace")]
    async fn handle_message(
        &self,
        _message: Measurement,
        _sender: ReplySenderFor<Measurement>,
    ) -> Result<(), PluginError> {
        // TODO
        Ok(())
    }
}

#[async_trait]
impl Handle<IncomingMessage> for C8yPlugin {
    #[tracing::instrument(name = "plugin.c8y.handle_message", level = "trace")]
    async fn handle_message(
        &self,
        _message: IncomingMessage,
        _sender: ReplySenderFor<IncomingMessage>,
    ) -> Result<(), PluginError> {
        // TODO
        Ok(())
    }
}