diff options
Diffstat (limited to 'src/datatype')
-rw-r--r-- | src/datatype/command.rs | 46 | ||||
-rw-r--r-- | src/datatype/config.rs | 4 | ||||
-rw-r--r-- | src/datatype/event.rs | 13 |
3 files changed, 39 insertions, 24 deletions
diff --git a/src/datatype/command.rs b/src/datatype/command.rs index d449bb6..0f59b1a 100644 --- a/src/datatype/command.rs +++ b/src/datatype/command.rs @@ -20,8 +20,8 @@ pub enum Command { GetNewUpdates, /// List the installed packages on the system. ListInstalledPackages, - /// Get the latest system information, and optionally publish it to Core. - RefreshSystemInfo(bool), + /// List the system information. + ListSystemInfo, /// Start downloading one or more updates. StartDownload(Vec<UpdateRequestId>), @@ -32,6 +32,8 @@ pub enum Command { SendInstalledPackages(Vec<Package>), /// Send a list of all packages and firmware to the Core server. SendInstalledSoftware(InstalledSoftware), + /// Send the system information to the Core server. + SendSystemInfo, /// Send a package update report to the Core server. SendUpdateReport(UpdateReport), } @@ -63,14 +65,16 @@ named!(command <(Command, Vec<&str>)>, chain!( => { |_| Command::GetNewUpdates } | alt_complete!(tag!("ListInstalledPackages") | tag!("ls")) => { |_| Command::ListInstalledPackages } - | alt_complete!(tag!("RefreshSystemInfo") | tag!("info")) - => { |_| Command::RefreshSystemInfo(false) } + | alt_complete!(tag!("ListSystemInfo") | tag!("info")) + => { |_| Command::ListSystemInfo } | alt_complete!(tag!("Shutdown") | tag!("shutdown")) => { |_| Command::Shutdown } | alt_complete!(tag!("SendInstalledPackages") | tag!("sendpack")) => { |_| Command::SendInstalledPackages(Vec::new()) } | alt_complete!(tag!("SendInstalledSoftware") | tag!("sendinst")) => { |_| Command::SendInstalledSoftware(InstalledSoftware::default()) } + | alt_complete!(tag!("SendSystemInfo") | tag!("sendinfo")) + => { |_| Command::SendSystemInfo } | alt_complete!(tag!("SendUpdateReport") | tag!("sendup")) => { |_| Command::SendUpdateReport(UpdateReport::default()) } | alt_complete!(tag!("StartDownload") | tag!("dl")) @@ -118,16 +122,9 @@ fn parse_arguments(cmd: Command, args: Vec<&str>) -> Result<Command, Error> { _ => Err(Error::Command(format!("unexpected ListInstalledPackages args: {:?}", args))), }, - Command::RefreshSystemInfo(_) => match args.len() { - 0 => Ok(Command::RefreshSystemInfo(false)), - 1 => { - if let Ok(b) = args[0].parse::<bool>() { - Ok(Command::RefreshSystemInfo(b)) - } else { - Err(Error::Command("couldn't parse 1st argument as boolean".to_string())) - } - } - _ => Err(Error::Command(format!("unexpected RefreshSystemInfo args: {:?}", args))), + Command::ListSystemInfo => match args.len() { + 0 => Ok(Command::ListSystemInfo), + _ => Err(Error::Command(format!("unexpected ListSystemInfo args: {:?}", args))), }, Command::SendInstalledPackages(_) => match args.len() { @@ -150,6 +147,11 @@ fn parse_arguments(cmd: Command, args: Vec<&str>) -> Result<Command, Error> { _ => Err(Error::Command(format!("unexpected SendInstalledSoftware args: {:?}", args))), }, + Command::SendSystemInfo => match args.len() { + 0 => Ok(Command::SendSystemInfo), + _ => Err(Error::Command(format!("unexpected SendSystemInfo args: {:?}", args))), + }, + Command::SendUpdateReport(_) => match args.len() { 0 | 1 => Err(Error::Command("usage: sendup <update-id> <result-code>".to_string())), 2 => { @@ -238,10 +240,10 @@ mod tests { } #[test] - fn refresh_system_info_test() { - assert_eq!("RefreshSystemInfo true".parse::<Command>().unwrap(), Command::RefreshSystemInfo(true)); - assert_eq!("info".parse::<Command>().unwrap(), Command::RefreshSystemInfo(false)); - assert!("RefreshSystemInfo 1 2".parse::<Command>().is_err()); + fn list_system_info_test() { + assert_eq!("ListSystemInfo".parse::<Command>().unwrap(), Command::ListSystemInfo); + assert_eq!("info".parse::<Command>().unwrap(), Command::ListSystemInfo); + assert!("ListSystemInfo 1 2".parse::<Command>().is_err()); assert!("info please".parse::<Command>().is_err()); } @@ -271,6 +273,14 @@ mod tests { } #[test] + fn send_system_info_test() { + assert_eq!("SendSystemInfo".parse::<Command>().unwrap(), Command::SendSystemInfo); + assert_eq!("sendinfo".parse::<Command>().unwrap(), Command::SendSystemInfo); + assert!("SendSystemInfo 1 2".parse::<Command>().is_err()); + assert!("sendinfo please".parse::<Command>().is_err()); + } + + #[test] fn send_update_report_test() { assert_eq!("SendUpdateReport myid OK".parse::<Command>().unwrap(), Command::SendUpdateReport( UpdateReport::single("myid".to_string(), UpdateResultCode::OK, "".to_string()))); diff --git a/src/datatype/config.rs b/src/datatype/config.rs index 5db0f12..650008b 100644 --- a/src/datatype/config.rs +++ b/src/datatype/config.rs @@ -266,7 +266,7 @@ impl Default for NetworkConfig { rvi_edge_server: "http://127.0.0.1:9080".to_string(), socket_commands_path: "/tmp/sota-commands.socket".to_string(), socket_events_path: "/tmp/sota-events.socket".to_string(), - websocket_server: "ws://127.0.0.1:3012".to_string() + websocket_server: "127.0.0.1:3012".to_string() } } } @@ -352,7 +352,7 @@ mod tests { rvi_edge_server = "http://127.0.0.1:9080" socket_commands_path = "/tmp/sota-commands.socket" socket_events_path = "/tmp/sota-events.socket" - websocket_server = "ws://127.0.0.1:3012" + websocket_server = "127.0.0.1:3012" "#; const RVI_CONFIG: &'static str = diff --git a/src/datatype/event.rs b/src/datatype/event.rs index e3f84ca..63ae850 100644 --- a/src/datatype/event.rs +++ b/src/datatype/event.rs @@ -26,10 +26,6 @@ pub enum Event { FoundInstalledPackages(Vec<Package>), /// An update on the system information was received. FoundSystemInfo(String), - /// A list of installed packages was sent to the Core server. - InstalledPackagesSent, - /// An update report was sent to the Core server. - UpdateReportSent, /// Downloading an update. DownloadingUpdate(UpdateRequestId), @@ -45,6 +41,15 @@ pub enum Event { /// 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, } |