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
use std::fmt::{Display, Formatter, Result as FmtResult};

use rvi::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
}