summaryrefslogtreecommitdiffstats
path: root/plugins/plugin_sm_apt/src/plugin.rs
blob: e8f29941385bf5778193378d2f1f15bc9a44068b (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use async_trait::async_trait;

use tedge_api::plugin::Handle;
use tedge_api::Plugin;
use tedge_api::PluginError;
use tracing::trace;
use tedge_lib::sm::request::Install;
use tedge_lib::sm::request::List;
use tedge_lib::sm::request::Uninstall;
use tedge_lib::sm::request::Update;

#[derive(Debug)]
pub struct SmAptPlugin {
    #[allow(unused)] // TODO
    apt_binary_path: Option<std::path::PathBuf>,
}

impl tedge_api::plugin::PluginDeclaration for SmAptPlugin {
    type HandledMessages = (Install, List, Uninstall, Update);
}

impl SmAptPlugin {
    pub fn new(apt_binary_path: Option<&std::path::Path>) -> Self {
        Self {
            apt_binary_path: apt_binary_path.map(ToOwned::to_owned),
        }
    }
}

#[async_trait]
impl Plugin for SmAptPlugin {
    async fn start(&mut self) -> Result<(), PluginError> {
        Ok(())
    }

    async fn shutdown(&mut self) -> Result<(), PluginError> {
        trace!("Shutdown");
        Ok(())
    }
}

#[async_trait]
impl Handle<Install> for SmAptPlugin {
    #[tracing::instrument(name = "plugin.sm_apt.handle_message.install", skip(self, _sender))]
    async fn handle_message(
        &self,
        message: Install,
        _sender: tedge_api::address::ReplySenderFor<Install>,
    ) -> Result<(), PluginError> {
        tracing::info!(package_name = %message.package_name(), "MOCK: Going to install software");
        Ok(())
    }
}

#[async_trait]
impl Handle<List> for SmAptPlugin {
    #[tracing::instrument(name = "plugin.sm_apt.handle_message.list", skip(self, _sender))]
    async fn handle_message(
        &self,
        _message: List,
        _sender: tedge_api::address::ReplySenderFor<List>,
    ) -> Result<(), PluginError> {
        tracing::info!("MOCK: Going to list software");
        Ok(())
    }
}

#[async_trait]
impl Handle<Uninstall> for SmAptPlugin {
    #[tracing::instrument(name = "plugin.sm_apt.handle_message.uninstall", skip(self, _sender))]
    async fn handle_message(
        &self,
        message: Uninstall,
        _sender: tedge_api::address::ReplySenderFor<Uninstall>,
    ) -> Result<(), PluginError> {
        tracing::info!(package_name = %message.package_name(), "MOCK: Going to uninstall software");
        Ok(())
    }
}

#[async_trait]
impl Handle<Update> for SmAptPlugin {
    #[tracing::instrument(name = "plugin.sm_apt.handle_message.update", skip(self, _sender))]
    async fn handle_message(
        &self,
        message: Update,
        _sender: tedge_api::address::ReplySenderFor<Update>,
    ) -> Result<(), PluginError> {
        tracing::info!(package_name = %message.package_name(), "MOCK: Going to update software");
        Ok(())
    }
}