diff rust/src/paramwaiter.rs @ 609:7bda01659426 rust

not building, paramwaiter work
author Matt Johnston <matt@ucc.asn.au>
date Sat, 18 Feb 2017 00:21:10 +0800
parents aff50ee77252
children f3e39e2107fd
line wrap: on
line diff
--- a/rust/src/paramwaiter.rs	Fri Feb 17 23:07:33 2017 +0800
+++ b/rust/src/paramwaiter.rs	Sat Feb 18 00:21:10 2017 +0800
@@ -7,30 +7,63 @@
 
 use tokio_core::reactor::Interval;
 use tokio_core::reactor::Handle;
-use futures::Stream;
+use tokio_curl::Session;
+use futures::{Stream,Future,future};
 use types::*;
+use curl::Easy;
+use ::Config;
 
 pub struct ParamWaiter {
+    limitlog: NotTooOften,
+    epoch_tag: String,
+    session: Option<Session>,
+    config: Config,
 }
 
+const LOGMINUTES: u64 = 15;
+
 impl ParamWaiter {
-    fn step(&mut self) -> Params {
+    pub fn new(config: &Config) -> Self {
+        ParamWaiter {
+            limitlog: NotTooOften::new(LOGMINUTES*60),
+            epoch_tag: String::new(),
+            session: None,
+            config: config.clone(),
+        }
+    }
+
+    fn make_req(&self) -> Easy {
+        let mut req = Easy::new();
+        req.get(true).unwrap();
+        req.url(config.SETTINGS_URL);
+    }
+
+    fn step(&mut self, handle: &Handle) -> Box<Future<Item=Option<Params>, Error=io::Error>> {
+        if self.session.is_none() {
+            self.session = Some(Session::new(handle.clone()))
+        }
+
+        let req = self.make_req();
+        /*
+        self.session.unwrap().perform(self.make_req())
+            .and_then(||)
+            */
+
         let mut p = Params::defaults();
         p.fridge_setpoint = 17.0 + 4.0*rand::random::<f32>();
-        p
-    }
-
-    pub fn new() -> Self {
-        ParamWaiter {}
+        future::ok(p).boxed()
     }
 
-    pub fn stream(handle: &Handle) -> Box<Stream<Item=Params, Error=io::Error>> {
-        let mut s = ParamWaiter::new();
+    pub fn stream(&mut self, handle: &Handle) -> Box<Stream<Item=Params, Error=io::Error>> {
 
         let dur = Duration::from_millis(4000);
-        Interval::new(dur, handle).unwrap().map(move |()| {
-            s.step()
-        }).boxed()
+        let i = Interval::new(dur, handle).unwrap()
+            .and_then(move |()| {
+                s.step()
+            })
+            // throw away None params
+            .filter_map(|p| p);
+        Box::new(i)
     }
 }