summaryrefslogtreecommitdiff
path: root/src/datatype/update_request.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/datatype/update_request.rs')
-rw-r--r--src/datatype/update_request.rs84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/datatype/update_request.rs b/src/datatype/update_request.rs
new file mode 100644
index 0000000..7398848
--- /dev/null
+++ b/src/datatype/update_request.rs
@@ -0,0 +1,84 @@
+use std::fmt::{Display, Formatter, Result as FmtResult};
+
+use rvi::services::LocalServices;
+
+
+/// Encapsulate a `String` type as the id of a specific update request.
+pub type UpdateRequestId = String;
+
+/// A device update request from Core to be installed by the client.
+#[allow(non_snake_case)]
+#[derive(RustcDecodable, RustcEncodable, PartialEq, Eq, Debug, Clone)]
+pub struct UpdateRequest {
+ pub requestId: UpdateRequestId,
+ pub status: UpdateRequestStatus,
+ pub packageId: Package,
+ pub installPos: i32,
+ pub createdAt: String,
+}
+
+/// The status of an `UpdateRequest` from Core.
+#[derive(RustcDecodable, RustcEncodable, PartialEq, Eq, Debug, Clone)]
+pub enum UpdateRequestStatus {
+ Pending,
+ InFlight,
+ Canceled,
+ Failed,
+ Finished
+}
+
+
+/// Encodes the name and version of a specific package.
+#[derive(RustcDecodable, RustcEncodable, PartialEq, Eq, Debug, Clone)]
+pub struct Package {
+ pub name: String,
+ pub version: String
+}
+
+impl Display for Package {
+ fn fmt(&self, f: &mut Formatter) -> FmtResult {
+ write!(f, "{} {}", self.name, self.version)
+ }
+}
+
+
+/// A notification from RVI that a new update is available.
+#[derive(RustcDecodable, RustcEncodable, PartialEq, Eq, Debug, Clone)]
+pub struct UpdateAvailable {
+ pub update_id: String,
+ pub signature: String,
+ pub description: String,
+ pub request_confirmation: bool,
+ pub size: u64
+}
+
+/// A JSON-RPC request type to notify RVI that a new package download has started.
+#[derive(RustcDecodable, RustcEncodable)]
+pub struct DownloadStarted {
+ pub device: String,
+ pub update_id: UpdateRequestId,
+ pub services: LocalServices,
+}
+
+/// A JSON-RPC request type to notify RVI that a new package chunk was received.
+#[derive(RustcDecodable, RustcEncodable)]
+pub struct ChunkReceived {
+ pub device: String,
+ pub update_id: UpdateRequestId,
+ pub chunks: Vec<u64>,
+}
+
+/// A notification to an external package manager that the package was downloaded.
+#[derive(RustcDecodable, RustcEncodable, PartialEq, Eq, Debug, Clone)]
+pub struct DownloadComplete {
+ pub update_id: String,
+ pub update_image: String,
+ pub signature: String
+}
+
+/// A notification to an external package manager that the package download failed.
+#[derive(RustcDecodable, RustcEncodable, PartialEq, Eq, Debug, Clone)]
+pub struct DownloadFailed {
+ pub update_id: String,
+ pub reason: String
+}