summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-05-18 08:44:43 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-05-18 08:44:43 +0200
commit2531f9e3467196c47372e128e2dd4450b6c25eac (patch)
treeacda73c63b58392b20760d34e5e604006efbf354
parent11156a1f435ddc3a01010d01f7439f9eef163df0 (diff)
Shrink response types
This patch shrinks the response types down to enums. This is necessary because right now we cannot implement more than 10 handlers for a plugin, but implementing a decent showcase would require more than that. And because we don't want to touch the core implementation just for the showcase, we simply shrink the number of types. Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--crates/core/tedge_lib/src/sm.rs235
1 files changed, 86 insertions, 149 deletions
diff --git a/crates/core/tedge_lib/src/sm.rs b/crates/core/tedge_lib/src/sm.rs
index 4049df66..5c770d02 100644
--- a/crates/core/tedge_lib/src/sm.rs
+++ b/crates/core/tedge_lib/src/sm.rs
@@ -14,6 +14,14 @@ pub mod request {
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
@@ -24,6 +32,14 @@ pub mod request {
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
@@ -34,182 +50,103 @@ pub mod request {
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, getset::Getters)]
- pub struct List {
- #[getset(get = "pub")]
- list: Vec<String>,
- }
-
- impl tedge_api::Message for List {}
-
- /// Listing installed things failed
#[derive(Debug)]
- pub struct ListFailed;
-
- impl tedge_api::Message for ListFailed {}
-
- /// A state representing an ongoing install process
- #[derive(Debug, getset::Getters, getset::CopyGetters)]
- pub struct InstallingState {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
-
- ///
- /// A number between 0 and 100 describing the progress of the operation
- #[getset(get_copy = "pub")]
- progress: usize,
- }
-
- impl tedge_api::Message for InstallingState {}
-
- /// A log line from an install process
- #[derive(Debug, getset::Getters)]
- pub struct InstallingLogLine {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
-
- /// A single line of output from the procedure
- #[getset(get = "pub")]
- log_line: String,
- }
-
- impl tedge_api::Message for InstallingLogLine {}
-
- /// Installing a package succeeded
- #[derive(Debug, getset::Getters)]
- pub struct InstallSucceeded {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
- }
-
- impl tedge_api::Message for InstallSucceeded {}
-
- /// Installing a package failed
- #[derive(Debug, getset::Getters)]
- pub struct InstallFailed {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
-
- /// A human-readable message describing the failure
- #[getset(get = "pub")]
- failure_message: String,
- }
-
- impl tedge_api::Message for InstallFailed {}
+ pub enum ListResponse {
+ List {
+ list: Vec<String>,
+ },
- ///
- /// Progress report from an ongoing update process
- #[derive(Debug, getset::Getters, getset::CopyGetters)]
- pub struct UpdatingState {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
-
- /// A number between 0 and 100 describing the progress of the operation
- #[getset(get_copy = "pub")]
- progress: usize,
+ ListFailed {
+ message: String
+ }
}
- impl tedge_api::Message for UpdatingState {}
+ impl tedge_api::Message for ListResponse {}
- /// A log line from an ongoing update process
- #[derive(Debug, getset::Getters)]
- pub struct UpdatingLogLine {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
+ #[derive(Debug)]
+ pub enum InstallResponse {
+ InstallProgress {
+ package_name: String,
+ progress: usize,
+ },
- /// A single line of output from the procedure
- #[getset(get = "pub")]
- log_line: String,
- }
+ InstallLogLine {
+ package_name: String,
+ log_line: String,
+ },
- impl tedge_api::Message for UpdatingLogLine {}
+ InstallSucceeded {
+ package_name: String,
+ },
- /// A update process succeeded
- #[derive(Debug, getset::Getters)]
- pub struct UpdateSucceeded {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
+ InstallFailed {
+ package_name: String,
+ failure_message: String,
+ },
}
- impl tedge_api::Message for UpdateSucceeded {}
+ impl tedge_api::Message for InstallResponse {}
- /// A update process failed
- #[derive(Debug, getset::Getters)]
- pub struct UpdateFailed {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
+ #[derive(Debug)]
+ pub enum UpdateResponse {
+ UpdateProgress {
+ package_name: String,
+ progress: usize,
+ },
- /// A human-readable message describing the failure
- #[getset(get = "pub")]
- failure_message: String,
- }
+ UpdateLogLine {
+ package_name: String,
+ log_line: String,
+ },
- impl tedge_api::Message for UpdateFailed {}
+ UpdateSucceeded {
+ package_name: String,
+ },
- ///
- /// Progress report from an ongoing uninstall process
- #[derive(Debug, getset::Getters, getset::CopyGetters)]
- pub struct UninstallState {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
-
- /// A number between 0 and 100 describing the progress of the operation
- #[getset(get_copy = "pub")]
- progress: usize,
+ UpdateFailed {
+ package_name: String,
+ failure_message: String,
+ },
}
- impl tedge_api::Message for UninstallState {}
-
- /// A log line from an ongoing uninstall process
- #[derive(Debug, getset::Getters)]
- pub struct UninstallLogLine {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
-
- /// A single line of output from the procedure
- #[getset(get = "pub")]
- log_line: String,
- }
+ impl tedge_api::Message for UpdateResponse {}
- impl tedge_api::Message for UninstallLogLine {}
- /// Uninstall process succeeded
- #[derive(Debug, getset::Getters)]
- pub struct UninstallSucceeded {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
- }
+ #[derive(Debug)]
+ pub enum UninstallResponse {
+ UninstallProgress {
+ package_name: String,
+ progress: usize,
+ },
- impl tedge_api::Message for UninstallSucceeded {}
+ UninstallLogLine {
+ package_name: String,
+ log_line: String,
+ },
- /// Uninstall process failed
- #[derive(Debug, getset::Getters)]
- pub struct UninstallFailed {
- /// The name of the package in this operation
- #[getset(get = "pub")]
- package_name: String,
+ UninstallSucceeded {
+ package_name: String,
+ },
- /// A human-readable message describing the failure
- #[getset(get = "pub")]
- failure_message: String,
+ UninstallFailed {
+ package_name: String,
+ failure_message: String,
+ },
}
- impl tedge_api::Message for UninstallFailed {}
+ impl tedge_api::Message for UninstallResponse {}
}