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

use datatype::{DownloadComplete, Package, UpdateAvailable, UpdateReport,
               UpdateRequest, UpdateRequestId};


/// System-wide events that are broadcast to all interested parties.
#[derive(RustcEncodable, RustcDecodable, Debug, Clone, PartialEq, Eq)]
pub enum Event {
    /// General error event with a printable representation for debugging.
    Error(String),

    /// Authentication was successful.
    Authenticated,
    /// An operation failed because we are not currently authenticated.
    NotAuthenticated,
    /// Nothing was done as we are already authenticated.
    AlreadyAuthenticated,

    /// A notification from Core of pending or in-flight updates.
    UpdatesReceived(Vec<UpdateRequest>),
    /// A notification from RVI of a pending update.
    UpdateAvailable(UpdateAvailable),
    /// There are no outstanding update requests.
    NoUpdateRequests,

    /// The following packages are installed on the device.
    FoundInstalledPackages(Vec<Package>),
    /// An update on the system information was received.
    FoundSystemInfo(String),

    /// Downloading an update.
    DownloadingUpdate(UpdateRequestId),
    /// An update was downloaded.
    DownloadComplete(DownloadComplete),
    /// Downloading an update failed.
    DownloadFailed(UpdateRequestId, String),

    /// Installing an update.
    InstallingUpdate(UpdateRequestId),
    /// An update was installed.
    InstallComplete(UpdateReport),
    /// The installation of an update failed.
    InstallFailed(UpdateReport),

    /// An update report was sent to the Core server.
    UpdateReportSent,
    /// A list of installed packages was sent to the Core server.
    InstalledPackagesSent,
    /// A list of installed software was sent to the Core server.
    InstalledSoftwareSent,
    /// The system information was sent to the Core server.
    SystemInfoSent,

    /// A broadcast event requesting an update on externally installed software.
    InstalledSoftwareNeeded,
}

impl Display for Event {
    fn fmt(&self, f: &mut Formatter) -> FmtResult {
        write!(f, "{:?}", self)
    }
}