diff options
author | Shaun Taheri <shaun@advancedtelematic.com> | 2016-09-06 14:55:57 +0200 |
---|---|---|
committer | Shaun Taheri <shaun@advancedtelematic.com> | 2016-09-06 15:52:42 +0200 |
commit | 2ddb6762cd20ae0c16e040c95a961d3a7d0a6e62 (patch) | |
tree | 48b5d5f81ed036eceddbbaf44dd327a8a5cf39d7 | |
parent | 6d48b0a1727e277ffe5b8b1f2dc625bdc739b160 (diff) | |
download | rvi_sota_client-2ddb6762cd20ae0c16e040c95a961d3a7d0a6e62.tar.gz |
Wrap socket JSON output with Event name
-rw-r--r-- | docs/client-guide.adoc | 21 | ||||
-rw-r--r-- | src/gateway/socket.rs | 23 |
2 files changed, 31 insertions, 13 deletions
diff --git a/docs/client-guide.adoc b/docs/client-guide.adoc index 4ec3103..bda8174 100644 --- a/docs/client-guide.adoc +++ b/docs/client-guide.adoc @@ -162,14 +162,20 @@ Once the SOTA client has successfully downloaded an update ordered by an ATS Gar [source,json] ---- { - "update_id": "string", <1> - "update_image": "string", <2> - "signature": "string" <3> + "version": "0.1", <1> + "event": "DownloadComplete", <2> + "data": { + "update_id": "string", <3> + "update_image": "string", <4> + "signature": "string" <5> + } } ---- -<1> A unique ID for the update. The SWLM will need to reference this ID when reporting on the status of the install. -<2> The location of the delivered update file. -<3> A cryptographic signature; may be blank if the package uploader chose not to supply one. The SWLM *may* implement signature verification, but is not required to do so. +<1> The API version of the response. +<2> The Event type of the message. +<3> A unique ID for the update. The SWLM will need to reference this ID when reporting on the status of the install. +<4> The location of the delivered update file. +<5> A cryptographic signature; may be blank if the package uploader chose not to supply one. The SWLM *may* implement signature verification, but is not required to do so. ==== SendUpdateReport @@ -224,6 +230,3 @@ SendInstalledPackages gcc 7.63 Movie&MusicPlayer rc2-beta3 ECU9274927BF82-firmwa ---- Note, however, that all packages must have a version. - - - diff --git a/src/gateway/socket.rs b/src/gateway/socket.rs index f252e7c..295cf6e 100644 --- a/src/gateway/socket.rs +++ b/src/gateway/socket.rs @@ -6,7 +6,7 @@ use std::net::Shutdown; use std::sync::{Arc, Mutex}; use std::{fs, thread}; -use datatype::{Command, Error, Event}; +use datatype::{Command, DownloadComplete, Error, Event}; use super::{Gateway, Interpret}; use unix_socket::{UnixListener, UnixStream}; @@ -56,7 +56,12 @@ impl Gateway for Socket { match event { Event::DownloadComplete(dl) => { let _ = UnixStream::connect(&self.events_path).map(|mut stream| { - stream.write_all(&json::encode(&dl).expect("couldn't encode Event").into_bytes()) + let output = DownloadCompleteEvent { + version: "0.1".to_string(), + event: "DownloadComplete".to_string(), + data: dl + }; + stream.write_all(&json::encode(&output).expect("couldn't encode Event").into_bytes()) .unwrap_or_else(|err| error!("couldn't write to events socket: {}", err)); stream.shutdown(Shutdown::Write) .unwrap_or_else(|err| error!("couldn't close events socket: {}", err)); @@ -84,6 +89,14 @@ fn handle_client(stream: &mut UnixStream, itx: Arc<Mutex<Sender<Interpret>>>) -> erx.recv().ok_or(Error::Socket("internal receiver error".to_string())) } +// FIXME(PRO-1322): create a proper JSON api +#[derive(RustcDecodable, RustcEncodable, PartialEq, Eq, Debug, Clone)] +pub struct DownloadCompleteEvent { + pub version: String, + pub event: String, + pub data: DownloadComplete +} + #[cfg(test)] mod tests { @@ -126,8 +139,10 @@ mod tests { let (mut stream, _) = server.accept().expect("couldn't read from events socket"); let mut text = String::new(); stream.read_to_string(&mut text).unwrap(); - let receive: DownloadComplete = json::decode(&text).expect("couldn't decode DownloadComplete message"); - assert_eq!(send, receive); + let receive: DownloadCompleteEvent = json::decode(&text).expect("couldn't decode DownloadComplete message"); + assert_eq!(receive.version, "0.1".to_string()); + assert_eq!(receive.event, "DownloadComplete".to_string()); + assert_eq!(receive.data, send); thread::spawn(move || { let _ = etx; // move into this scope |