summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-09-10 09:54:30 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-09-10 12:13:33 +0200
commit688ac4af52ffd6a8925f5685adc4b8bb67347c1e (patch)
tree3f803e6b6c6010909834e30569459bb47057349c
parent74c412fd5891eeae44d5fb87d293b1a0b4055aef (diff)
Add message types for copying file
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--Cargo.lock1
-rw-r--r--plugins/plugin_fdman/Cargo.toml1
-rw-r--r--plugins/plugin_fdman/src/message/copy.rs59
-rw-r--r--plugins/plugin_fdman/src/message/mod.rs3
4 files changed, 64 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2f2f93be..e52c6e6b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2456,6 +2456,7 @@ dependencies = [
"tedge_api",
"tedge_lib",
"thiserror",
+ "tokio",
"tokio-util 0.7.3",
"toml",
"tracing",
diff --git a/plugins/plugin_fdman/Cargo.toml b/plugins/plugin_fdman/Cargo.toml
index 22c10067..67789c9c 100644
--- a/plugins/plugin_fdman/Cargo.toml
+++ b/plugins/plugin_fdman/Cargo.toml
@@ -14,6 +14,7 @@ toml = "0.5"
tracing = "0.1"
tokio-util = "0.7.0"
bevy_reflect = "0.7.0"
+tokio = { version = "1", features = ["fs"] }
tedge_api = { path = "../../crates/core/tedge_api" }
tedge_lib = { path = "../../crates/core/tedge_lib" }
diff --git a/plugins/plugin_fdman/src/message/copy.rs b/plugins/plugin_fdman/src/message/copy.rs
new file mode 100644
index 00000000..c57ede30
--- /dev/null
+++ b/plugins/plugin_fdman/src/message/copy.rs
@@ -0,0 +1,59 @@
+use std::path::PathBuf;
+
+use tedge_api::Message;
+
+#[derive(Clone, Debug, bevy_reflect::TypeUuid)]
+#[uuid = "1420a7d9-3b8c-4057-8130-7604a481c0b1"]
+pub struct Copy {
+ src: PathBuf,
+ dst: PathBuf,
+}
+
+impl Copy {
+ pub fn new(src: PathBuf, dst: PathBuf) -> Self {
+ Self { src, dst }
+ }
+
+ pub(crate) fn src(&self) -> &PathBuf {
+ &self.src
+ }
+
+ pub(crate) fn dst(&self) -> &PathBuf {
+ &self.dst
+ }
+}
+
+impl Message for Copy {}
+
+impl tedge_api::message::AcceptsReplies for Copy {
+ type Reply = CopyResult;
+}
+
+#[derive(Debug, bevy_reflect::TypeUuid)]
+#[uuid = "28af1dad-3374-4df1-9fc4-d24918792af9"]
+pub struct CopyResult {
+ copy: Copy,
+ result: Result<u64, CopyError>,
+}
+
+impl CopyResult {
+ pub(crate) fn new(copy: Copy, result: Result<u64, CopyError>) -> Self {
+ Self { copy, result }
+ }
+
+ pub fn copy(&self) -> &Copy {
+ &self.copy
+ }
+
+ pub fn into_result(self) -> Result<u64, CopyError> {
+ self.result
+ }
+}
+
+impl Message for CopyResult {}
+
+#[derive(Debug, thiserror::Error)]
+pub enum CopyError {
+ #[error("FdMan Plugin error")]
+ FdMan(#[from] crate::error::Error),
+}
diff --git a/plugins/plugin_fdman/src/message/mod.rs b/plugins/plugin_fdman/src/message/mod.rs
index 72ef4570..606070d8 100644
--- a/plugins/plugin_fdman/src/message/mod.rs
+++ b/plugins/plugin_fdman/src/message/mod.rs
@@ -1,2 +1,5 @@
+mod copy;
+pub use self::copy::*;
+
mod open_options;
pub use self::open_options::*;