summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge_lib/src/sm.rs
blob: 5c770d0255e236a8f4c33a2aca87392c8fd92324 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/// Types for requesting software-management operations
pub mod request {
    /// List installed software
    #[derive(Debug)]
    pub struct List;

    impl tedge_api::Message for List {}

    /// Install a software by name
    #[derive(Debug, getset::Getters)]
    pub struct Install {
        /// The name of the package in this operation
        #[getset(get = "pub")]
        package_name: String,
    }

    impl Install {
        pub fn new(package_name: String) -> Self {
            Self {
                package_name
            }
        }
    }

    impl tedge_api::Message for Install {}

    /// Update a software by name
    #[derive(Debug, getset::Getters)]
    pub struct Update {
        /// The name of the package in this operation
        #[getset(get = "pub")]
        package_name: String,
    }

    impl Update {
        pub fn new(package_name: String) -> Self {
            Self {
                package_name
            }
        }
    }

    impl tedge_api::Message for Update {}

    /// Uninstall a software by name
    #[derive(Debug, getset::Getters)]
    pub struct Uninstall {
        /// The name of the package in this operation
        #[getset(get = "pub")]
        package_name: String,
    }

    impl Uninstall {
        pub fn new(package_name: String) -> Self {
            Self {
                package_name
            }
        }
    }

    impl tedge_api::Message for Uninstall {}
}

/// Types for representing a "response" that was yielded by an operation for a "request"
pub mod response {
    /// A list of installed things
    #[derive(Debug)]
    pub enum ListResponse {
        List {
            list: Vec<String>,
        },

        ListFailed {
            message: String
        }
    }

    impl tedge_api::Message for ListResponse {}

    #[derive(Debug)]
    pub enum InstallResponse {
        InstallProgress {
            package_name: String,
            progress: usize,
        },

        InstallLogLine {
            package_name: String,
            log_line: String,
        },

        InstallSucceeded {
            package_name: String,
        },

        InstallFailed {
            package_name: String,
            failure_message: String,
        },
    }

    impl tedge_api::Message for InstallResponse {}

    #[derive(Debug)]
    pub enum UpdateResponse {
        UpdateProgress {
            package_name: String,
            progress: usize,
        },

        UpdateLogLine {
            package_name: String,
            log_line: String,
        },

        UpdateSucceeded {
            package_name: String,
        },

        UpdateFailed {
            package_name: String,
            failure_message: String,
        },
    }

    impl tedge_api::Message for UpdateResponse {}


    #[derive(Debug)]
    pub enum UninstallResponse {
        UninstallProgress {
            package_name: String,
            progress: usize,
        },

        UninstallLogLine {
            package_name: String,
            log_line: String,
        },

        UninstallSucceeded {
            package_name: String,
        },

        UninstallFailed {
            package_name: String,
            failure_message: String,
        },
    }

    impl tedge_api::Message for UninstallResponse {}
}