diff options
author | Arthur Taylor <codders@octomonkey.org.uk> | 2016-11-22 10:56:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-22 10:56:20 +0100 |
commit | 8e9d234dcfe03a24409829ddd31b51bd8f840345 (patch) | |
tree | d1d833d732faf4c8709e975a4bb6129acc3d0f76 /src/datatype/update_request.rs | |
parent | 0167dce98692f707b74395977c478c2ca44fa0c7 (diff) | |
parent | 4b50e1cb0945adbbcc07dfcb65a9252e7523105d (diff) | |
download | rvi_sota_client-8e9d234dcfe03a24409829ddd31b51bd8f840345.tar.gz |
Merge latest stable advancedtelematic
Diffstat (limited to 'src/datatype/update_request.rs')
-rw-r--r-- | src/datatype/update_request.rs | 84 |
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 +} |