Skip to content

Commit

Permalink
Merge pull request #102 from rneswold/pull-request
Browse files Browse the repository at this point in the history
Miscellaneous additions
  • Loading branch information
rneswold authored Feb 12, 2024
2 parents d274062 + 54d92a6 commit 6e54ba5
Show file tree
Hide file tree
Showing 13 changed files with 667 additions and 485 deletions.
970 changes: 554 additions & 416 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ debug = 1
debug = 1

[profile.release]
opt-level = 3
opt-level = 'z'
debug = false
lto = false
lto = true
codegen-units = 1
debug-assertions = false
strip = "debuginfo"
strip = "symbols"
incremental = false
panic = "abort"
4 changes: 1 addition & 3 deletions backends/drmem-db-redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ fn to_redis(val: &device::Value) -> Vec<u8> {
// Colors start with a 'C', followed by 3 u8 values,
// representing red, green, and blue intensities,
// respectively.
device::Value::Color(v) => {
vec![b'C', v.red, v.green, v.blue]
}
device::Value::Color(v) => vec![b'C', v.red, v.green, v.blue],
}
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/drmem-drv-ntp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ impl Instance {
if let Ok(addr) = addr.parse::<SocketAddrV4>() {
Ok(addr)
} else {
Err(Error::BadConfig(String::from(
Err(Error::ConfigError(String::from(
"'addr' not in hostname:port format",
)))
}
}
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'addr' config parameter should be a string",
))),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'addr' parameter in config",
))),
}
Expand Down
10 changes: 5 additions & 5 deletions drivers/drmem-drv-sump/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ impl Instance {
if let Ok(addr) = addr.parse::<SocketAddrV4>() {
Ok(addr)
} else {
Err(Error::BadConfig(String::from(
Err(Error::ConfigError(String::from(
"'addr' not in hostname:port format",
)))
}
}
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'addr' config parameter should be a string",
))),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'addr' parameter in config",
))),
}
Expand All @@ -222,10 +222,10 @@ impl Instance {
match cfg.get("gpm") {
Some(toml::value::Value::Integer(gpm)) => Ok(*gpm as f64),
Some(toml::value::Value::Float(gpm)) => Ok(*gpm),
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'gpm' config parameter should be a number",
))),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'gpm' parameter in config",
))),
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/drmem-drv-tplink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ impl Instance {
if let Ok(addr) = addr.parse::<SocketAddrV4>() {
Ok(addr)
} else {
Err(Error::BadConfig(String::from(
Err(Error::ConfigError(String::from(
"'addr' not in hostname:port format",
)))
}
}
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'addr' config parameter should be a string",
))),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'addr' parameter in config",
))),
}
Expand Down
14 changes: 7 additions & 7 deletions drivers/drmem-drv-weather-wu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ impl Instance {
Some(toml::value::Value::String(station)) => {
Ok(station.to_string())
}
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'station' config parameter should be a string",
))),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'station' parameter in config",
))),
}
Expand All @@ -66,7 +66,7 @@ impl Instance {
Some(toml::value::Value::Integer(val)) => {
Ok(std::cmp::max(*val as u64, 1))
}
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'interval' config parameter should be a positive integer",
))),
None => Ok(DEFAULT_INTERVAL),
Expand All @@ -76,7 +76,7 @@ impl Instance {
fn get_cfg_key(cfg: &DriverConfig) -> Result<Option<String>> {
match cfg.get("key") {
Some(toml::value::Value::String(val)) => Ok(Some(val.to_string())),
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'key' config parameter should be a string",
))),
None => Ok(None),
Expand Down Expand Up @@ -111,11 +111,11 @@ impl Instance {
Some(toml::value::Value::String(val)) => match val.as_str() {
"metric" => Ok(wu::Unit::Metric),
"imperial" => Ok(wu::Unit::English),
_ => Err(Error::BadConfig(String::from(
_ => Err(Error::ConfigError(String::from(
"'units' parameter should be \"imperial\" or \"metric\"",
))),
},
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'units' parameter should be a string",
))),
None => Ok(wu::Unit::Metric),
Expand Down Expand Up @@ -424,7 +424,7 @@ impl driver::API for Instance {
interval,
}))
}
Err(e) => Err(Error::BadConfig(format!(
Err(e) => Err(Error::ConfigError(format!(
"couldn't build client connection -- {}",
&e
))),
Expand Down
4 changes: 2 additions & 2 deletions drmem-api/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub enum Error {

/// A bad parameter was given in a configuration or a
/// configuration was missing a required parameter.
BadConfig(String),
ConfigError(String),

/// There was a problem parsing a string. The associated string
/// will describe how the parsing failed.
Expand Down Expand Up @@ -85,7 +85,7 @@ impl fmt::Display for Error {
Error::OperationError(v) => {
write!(f, "couldn't complete operation: {}", &v)
}
Error::BadConfig(v) => write!(f, "config error: {}", &v),
Error::ConfigError(v) => write!(f, "config error: {}", &v),
Error::ParseError(v) => write!(f, "parse error: {}", &v),
}
}
Expand Down
6 changes: 3 additions & 3 deletions drmemd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,20 @@ fn from_cmdline(mut cfg: Config) -> (bool, Config) {

fn parse_config(contents: &str) -> Result<Config> {
toml::from_str(contents)
.map_err(|e| Error::BadConfig(format!("{}", e)))
.map_err(|e| Error::ConfigError(format!("{}", e)))
.and_then(|cfg: Config| {
// Make sure latitude is between -90 and 90 degrees.

if !(-90.0..=90.0).contains(&cfg.latitude) {
return Err(Error::BadConfig(
return Err(Error::ConfigError(
"'latitude' is out of range".into(),
));
}

// Make sure longitude is between -180 and 180 degrees.

if !(-180.0..=180.0).contains(&cfg.longitude) {
return Err(Error::BadConfig(
return Err(Error::ConfigError(
"'longitude' is out of range".into(),
));
}
Expand Down
18 changes: 10 additions & 8 deletions drmemd/src/driver/drv_cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ impl Instance {
if (50..=3_600_000).contains(millis) {
Ok(time::Duration::from_millis(*millis as u64))
} else {
Err(Error::BadConfig(String::from("'millis' out of range")))
Err(Error::ConfigError(String::from(
"'millis' out of range",
)))
}
}
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'millis' config parameter should be an integer",
))),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'millis' parameter in config",
))),
}
Expand All @@ -92,7 +94,7 @@ impl Instance {
fn get_cfg_enabled(cfg: &DriverConfig) -> Result<bool> {
match cfg.get("enabled_at_boot") {
Some(toml::value::Value::Boolean(level)) => Ok(*level),
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'enabled_at_boot' config parameter should be a boolean",
))),
None => Ok(false),
Expand All @@ -104,7 +106,7 @@ impl Instance {
fn get_inactive_value(cfg: &DriverConfig) -> Result<device::Value> {
match cfg.get("disabled") {
Some(value) => value.try_into(),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'disabled' parameter in config",
))),
}
Expand All @@ -116,15 +118,15 @@ impl Instance {
if value.len() > 1 {
value.iter().map(|v| v.try_into()).collect()
} else {
Err(Error::BadConfig(String::from(
Err(Error::ConfigError(String::from(
"'enabled' array should have at least 2 values",
)))
}
}
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'enabled' parameter should be an array of values",
))),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'enabled' parameter in config",
))),
}
Expand Down
6 changes: 3 additions & 3 deletions drmemd/src/driver/drv_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ impl Instance {
if let v @ Ok(_) = name.parse::<device::Base>() {
v
} else {
Err(Error::BadConfig(String::from(
Err(Error::ConfigError(String::from(
"'name' isn't a proper, base name for a device",
)))
}
}
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'name' config parameter should be a string",
))),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'name' parameter in config",
))),
}
Expand Down
12 changes: 7 additions & 5 deletions drmemd/src/driver/drv_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ impl Instance {
if (50..=3_600_000).contains(millis) {
Ok(time::Duration::from_millis(*millis as u64))
} else {
Err(Error::BadConfig(String::from("'millis' out of range")))
Err(Error::ConfigError(String::from(
"'millis' out of range",
)))
}
}
Some(_) => Err(Error::BadConfig(String::from(
Some(_) => Err(Error::ConfigError(String::from(
"'millis' config parameter should be an integer",
))),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'millis' parameter in config",
))),
}
Expand All @@ -100,7 +102,7 @@ impl Instance {
fn get_active_value(cfg: &DriverConfig) -> Result<device::Value> {
match cfg.get("enabled") {
Some(value) => value.try_into(),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'enabled' parameter in config",
))),
}
Expand All @@ -111,7 +113,7 @@ impl Instance {
fn get_inactive_value(cfg: &DriverConfig) -> Result<device::Value> {
match cfg.get("disabled") {
Some(value) => value.try_into(),
None => Err(Error::BadConfig(String::from(
None => Err(Error::ConfigError(String::from(
"missing 'disabled' parameter in config",
))),
}
Expand Down
Loading

0 comments on commit 6e54ba5

Please sign in to comment.