summaryrefslogtreecommitdiff
path: root/src/gateway/gateway.rs
diff options
context:
space:
mode:
authorArthur Taylor <codders@octomonkey.org.uk>2016-09-05 15:43:23 +0200
committerGitHub <noreply@github.com>2016-09-05 15:43:23 +0200
commit0167dce98692f707b74395977c478c2ca44fa0c7 (patch)
tree53db4ad3d930e586be4ec946b0bbbfdda5350732 /src/gateway/gateway.rs
parentd37818fa5ac01e2bf05c9b6c71362b41691a01f1 (diff)
parentdb7575f02de4064a7afaa10c3ae33349fadbf605 (diff)
downloadrvi_sota_client-0167dce98692f707b74395977c478c2ca44fa0c7.tar.gz
Merge pull request #8 from advancedtelematic/stable
Merge latest advancedtelematic/stable
Diffstat (limited to 'src/gateway/gateway.rs')
-rw-r--r--src/gateway/gateway.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/gateway/gateway.rs b/src/gateway/gateway.rs
new file mode 100644
index 0000000..96fef8d
--- /dev/null
+++ b/src/gateway/gateway.rs
@@ -0,0 +1,32 @@
+use chan::{Sender, Receiver};
+use std::process;
+use std::sync::{Arc, Mutex};
+
+use datatype::{Command, Event};
+
+
+/// Encapsulates a `Command` to be sent to the `GlobalInterpreter` for processing,
+/// with an optional channel to receive the outcome `Event`.
+pub struct Interpret {
+ pub command: Command,
+ pub response_tx: Option<Arc<Mutex<Sender<Event>>>>,
+}
+
+/// A `Gateway` may send `Command`s to the `GlobalInterpreter`, as well as listen
+/// to the system-wide `Event` messages.
+pub trait Gateway {
+ fn initialize(&mut self, itx: Sender<Interpret>) -> Result<(), String>;
+
+ fn start(&mut self, itx: Sender<Interpret>, erx: Receiver<Event>) {
+ self.initialize(itx).unwrap_or_else(|err| {
+ error!("couldn't start gateway: {}", err);
+ process::exit(1);
+ });
+
+ loop {
+ self.pulse(erx.recv().expect("all gateway event transmitters are closed"));
+ }
+ }
+
+ fn pulse(&self, _: Event) {} // ignore global events by default
+}