Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rajchenbach-Teller committed May 20, 2016
1 parent e784e1e commit 822a52e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 47 deletions.
41 changes: 34 additions & 7 deletions components/taxonomy/src/adapter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use api::{ Error, User };
use api::{ Error, Operation, User };
use io::*;
use services::*;
use values::*;
Expand Down Expand Up @@ -114,9 +114,21 @@ pub trait RawAdapter: Send + Sync {
/// reboots/reconnections.
fn id(&self) -> Id<AdapterId>;

fn fetch_values(&self, mut target: Vec<(Id<Channel>, Type)>, _: User) -> ResultMap<Id<Channel>, Option<(Payload, Type)>, Error>;
fn send_values(&self, values: HashMap<Id<Channel>, (Payload, Type)>, user: User) -> ResultMap<Id<Channel>, (), Error>;
fn register_watch(&self, Vec<RawWatchTarget>) -> WatchResult;
fn fetch_values(&self, mut target: Vec<(Id<Channel>, Type)>, _: User) -> ResultMap<Id<Channel>, Option<(Payload, Type)>, Error> {
target.drain(..).map(|(id, _)| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}
fn send_values(&self, mut values: HashMap<Id<Channel>, (Payload, Type)>, _: User) -> ResultMap<Id<Channel>, (), Error> {
values.drain().map(|(id, _)| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}
fn register_watch(&self, mut target: Vec<RawWatchTarget>) -> WatchResult {
target.drain(..).map(|(id, _, _, _)| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}

/// Signal the adapter that it is time to stop.
///
Expand Down Expand Up @@ -154,13 +166,23 @@ pub trait Adapter: Send + Sync {
/// expects the adapter to attempt to minimize the connections with the actual devices.
///
/// The AdapterManager is in charge of keeping track of the age of values.
fn fetch_values(&self, mut target: Vec<Id<Channel>>, _: User) -> ResultMap<Id<Channel>, Option<Value>, Error>;
fn fetch_values(&self, mut target: Vec<Id<Channel>>, _: User) -> ResultMap<Id<Channel>, Option<Value>, Error>
{
target.drain(..).map(|id| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}

/// Request that values be sent to channels.
///
/// The AdapterManager always attempts to group calls to `send_values` by `Adapter`, and then
/// expects the adapter to attempt to minimize the connections with the actual devices.
fn send_values(&self, values: HashMap<Id<Channel>, Value>, user: User) -> ResultMap<Id<Channel>, (), Error>;
fn send_values(&self, mut op: HashMap<Id<Channel>, Value>, _: User) -> ResultMap<Id<Channel>, (), Error>
{
op.drain().map(|(id, _)| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}

/// Watch a bunch of getters as they change.
///
Expand All @@ -171,7 +193,12 @@ pub trait Adapter: Send + Sync {
///
/// If a `Range` option is set, the watcher expects to receive `EnterRange`/`ExitRange` events
/// whenever the value available on the device enters/exits the range.
fn register_watch(&self, Vec<WatchTarget>) -> WatchResult;
fn register_watch(&self, mut watch: Vec<WatchTarget>) -> WatchResult
{
watch.drain(..).map(|(id, _, _)| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}

/// Signal the adapter that it is time to stop.
///
Expand Down
9 changes: 1 addition & 8 deletions src/adapters/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Useful for logging.
use foxbox_taxonomy::api::{ Error, InternalError, Operation, User };
use foxbox_taxonomy::api::{ Error, InternalError, User };
use foxbox_taxonomy::manager::*;
use foxbox_taxonomy::services::*;
use foxbox_taxonomy::values::{ Value };
Expand Down Expand Up @@ -74,13 +74,6 @@ impl Adapter for Console {
})
.collect()
}

fn register_watch(&self, mut watch: Vec<WatchTarget>) -> WatchResult
{
watch.drain(..).map(|(id, _, _)| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}
}


Expand Down
9 changes: 1 addition & 8 deletions src/adapters/ip_camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod api;
mod upnp_listener;

use config_store::ConfigService;
use foxbox_taxonomy::api::{Error, InternalError, Operation, User};
use foxbox_taxonomy::api::{Error, InternalError, User};
use foxbox_taxonomy::manager::*;
use foxbox_taxonomy::selector::*;
use foxbox_taxonomy::services::*;
Expand Down Expand Up @@ -285,11 +285,4 @@ impl Adapter for IPCameraAdapter {
(id.clone(), Err(Error::InternalError(InternalError::NoSuchChannel(id))))
}).collect()
}

fn register_watch(&self, mut watch: Vec<WatchTarget>) -> WatchResult
{
watch.drain(..).map(|(id, _, _)| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}
}
1 change: 0 additions & 1 deletion src/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub mod clock;
pub mod console;

/// A Text To Speak adapter
#[cfg(target_os = "linux")]
pub mod tts;

/// An adapter providing access to IP cameras.
Expand Down
8 changes: 1 addition & 7 deletions src/adapters/philips_hue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod hub_api;
pub mod lights;
pub mod structs;

use foxbox_taxonomy::api::{ Error, InternalError, Operation, User };
use foxbox_taxonomy::api::{ Error, InternalError, User };
use foxbox_taxonomy::manager::*;
use foxbox_taxonomy::services::*;
use foxbox_taxonomy::values::{ Color, OnOff, Type, TypeError, Value };
Expand Down Expand Up @@ -297,10 +297,4 @@ impl<C: Controller> Adapter for PhilipsHueAdapter<C> {
(id.clone(), Err(Error::InternalError(InternalError::NoSuchChannel(id))))
}).collect()
}

fn register_watch(&self, mut watch: Vec<WatchTarget>) -> WatchResult {
watch.drain(..).map(|(id, _, _)| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}
}
9 changes: 1 addition & 8 deletions src/adapters/thinkerbell/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! An adapter providing access to the Thinkerbell rules engine.
use foxbox_taxonomy::api::{ Error, InternalError, Operation, User };
use foxbox_taxonomy::api::{ Error, InternalError, User };
use foxbox_taxonomy::manager::*;
use foxbox_taxonomy::services::{ AdapterId, ServiceId, Service, Channel, ChannelKind };
use foxbox_taxonomy::util::Id;
Expand Down Expand Up @@ -133,13 +133,6 @@ impl Adapter for ThinkerbellAdapter {
})
.collect()
}

fn register_watch(&self, mut watch: Vec<WatchTarget>) -> WatchResult
{
watch.drain(..).map(|(id, _, _)| {
(id.clone(), Err(Error::OperationNotSupported(Operation::Watch, id)))
}).collect()
}
}

/// `ThinkerbellAdapter`'s main loop handles messages of these types.
Expand Down
9 changes: 1 addition & 8 deletions src/adapters/tts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use foxbox_taxonomy::manager::AdapterManager;
use foxbox_taxonomy::api::{ Error, InternalError, User };
use foxbox_taxonomy::services::{ AdapterId, Channel, ChannelKind, Id, Service, ServiceId };
use foxbox_taxonomy::values::{ Type, Value };
use std::collections::{ HashMap, HashSet };
use std::collections::HashMap;
use std::sync::Arc;
use transformable_channels::mpsc::*;

Expand Down Expand Up @@ -69,13 +69,6 @@ impl<T: TtsEngine> Adapter for TtsAdapter<T> {
(id.clone(), Err(Error::InternalError(InternalError::NoSuchChannel(id))))
}).collect()
}

fn register_watch(&self, mut watch: Vec<WatchTarget>) -> WatchResult
{
watch.drain(..).map(|(id, _, _)| {
(id.clone(), Err(Error::GetterDoesNotSupportWatching(id)))
}).collect()
}
}

pub fn init(adapt: &Arc<AdapterManager>) -> Result<(), Error> {
Expand Down

0 comments on commit 822a52e

Please sign in to comment.