Commit dcf57d1d authored by Zeeshan Ali's avatar Zeeshan Ali
Browse files

Fix coding-style according to latest nightly rustfmt

parent 2192eb7e
......@@ -51,7 +51,9 @@ impl Avahi {
let c = dbus::Connection::get_private(dbus::BusType::System)?;
let connection = Rc::new(c);
Ok(Avahi { connection: connection })
Ok(Avahi {
connection: connection,
})
}
pub fn publish(&self, net_iface: Option<&str>, port: u16) -> Result<(), dbus::Error> {
......@@ -65,16 +67,14 @@ impl Avahi {
let array: Vec<Vec<u8>> = vec![txt.into_bytes()];
let iface = match net_iface {
Some(name) => {
match server.get_network_interface_index_by_name(name) {
Ok(i) => i,
Err(e) => {
println!("Failed to get interface index from Avahi: {}", e);
Some(name) => match server.get_network_interface_index_by_name(name) {
Ok(i) => i,
Err(e) => {
println!("Failed to get interface index from Avahi: {}", e);
-1
}
-1
}
}
},
None => -1,
};
group.add_service(
......
......@@ -22,8 +22,8 @@
*/
use gps;
use std::net::TcpStream;
use std::io::Write;
use std::net::TcpStream;
use std::sync::{Arc, Mutex};
pub struct ClientHandler {
......
......@@ -21,7 +21,7 @@
* Author: Zeeshan Ali <zeeshanak@gnome.org>
*/
use clap::{Arg, App};
use clap::{App, Arg};
use config::Config;
pub fn config_from_cmdline() -> Config {
......@@ -29,46 +29,47 @@ pub fn config_from_cmdline() -> Config {
.version("0.1")
.author("Zeeshan Ali <zeeshanak@gnome.org>")
.about("Utility to share your GPS device on local network.")
.arg(Arg::with_name("device").help("GPS device node").required(
false,
))
.arg(
Arg::with_name("device")
.help("GPS device node")
.required(false),
).arg(
Arg::with_name("disable-announce")
.short("a")
.long("--disable-announce")
.help("Disable announcing through Avahi"),
)
.arg(
).arg(
Arg::with_name("port")
.short("p")
.long("--port")
.help("Port to run TCP service on (default: 10110)")
.takes_value(true)
.value_name("PORT"),
)
.arg(
).arg(
Arg::with_name("interface")
.short("n")
.long("--network-interface")
.help("Bind specific network interface (default: all)")
.takes_value(true)
.value_name("INTERFACE"),
)
.arg(
).arg(
Arg::with_name("baudrate")
.short("b")
.long("--baudrate")
.help("Baudrate to use for communication with GPS device")
.takes_value(true)
.value_name("BAUDRATE"),
)
.get_matches();
).get_matches();
let announce = !matches.is_present("disable-announce");
let dev_path = matches.value_of("device").and_then(|p| {
Some(::std::path::PathBuf::from(p))
});
let port: u16 = matches.value_of("port").unwrap_or("10110").parse().unwrap_or(0);
let dev_path = matches
.value_of("device")
.and_then(|p| Some(::std::path::PathBuf::from(p)));
let port: u16 = matches
.value_of("port")
.unwrap_or("10110")
.parse()
.unwrap_or(0);
let iface = matches.value_of("interface").map(|s| s.to_string());
let baudrate = matches
.value_of("baudrate")
......
......@@ -22,10 +22,10 @@
*/
use libc;
use std::ptr;
use std::mem;
use std::ffi::{CStr, CString};
use serial;
use std::ffi::{CStr, CString};
use std::mem;
use std::ptr;
pub struct Config {
pub dev_path: Option<::std::path::PathBuf>,
......@@ -116,7 +116,6 @@ impl Config {
continue;
}
}
}
......
......@@ -21,17 +21,17 @@
* Author: Zeeshan Ali <zeeshanak@gnome.org>
*/
mod rs232;
mod gps;
mod server;
mod avahi;
mod client_handler;
mod stdin_gps;
mod config;
mod cmdline_config;
mod config;
mod gps;
mod rs232;
mod server;
mod stdin_gps;
extern crate serial;
extern crate dbus;
extern crate serial;
#[macro_use]
extern crate dbus_macros;
extern crate core;
......@@ -42,12 +42,12 @@ extern crate clap;
extern crate libc;
extern crate libudev;
use config::Config;
use gps::GPS;
use rs232::RS232;
use stdin_gps::StdinGPS;
use server::Server;
use config::Config;
use std::thread;
use stdin_gps::StdinGPS;
use chan_signal::Signal;
use std::rc::Rc;
......
......@@ -21,16 +21,16 @@
* Author: Zeeshan Ali <zeeshanak@gnome.org>
*/
use gps::GPS;
use config::Config;
use serial;
use gps::GPS;
use libudev;
use std::time::Duration;
use serial;
use std::io;
use std::io::BufReader;
use std::io::BufRead;
use std::rc::Rc;
use std::io::BufReader;
use std::path::Path;
use std::rc::Rc;
use std::time::Duration;
pub struct RS232 {
reader: BufReader<serial::SystemPort>,
......@@ -48,7 +48,9 @@ impl RS232 {
let mut port = serial::open(path.as_os_str())?;
RS232::configure(&mut port as &mut serial::SerialPort, config)?;
Ok(RS232 { reader: BufReader::new(port) })
Ok(RS232 {
reader: BufReader::new(port),
})
}
fn configure(port: &mut serial::SerialPort, config: &Config) -> serial::Result<()> {
......@@ -110,9 +112,9 @@ impl RS232 {
for _ in 1..3 {
if let Ok(_) = self.read_line(&mut buffer) {
if buffer.len() >= 15 &&
buffer.chars().nth(0) == Some('$') &&
buffer.chars().nth(6) == Some(',')
if buffer.len() >= 15
&& buffer.chars().nth(0) == Some('$')
&& buffer.chars().nth(6) == Some(',')
{
return true;
}
......
......@@ -21,15 +21,15 @@
* Author: Zeeshan Ali <zeeshanak@gnome.org>
*/
use gps;
use avahi;
use config::Config;
use client_handler::ClientHandler;
use config::Config;
use gps;
use std::io;
use std::net::{TcpListener, TcpStream};
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::thread;
use std::rc::Rc;
pub struct Server {
gps: Arc<Mutex<gps::GPS>>,
......@@ -103,7 +103,9 @@ impl Server {
if launch_handler {
let handler = ClientHandler::new(self.gps.clone(), streams_arc.clone());
thread::spawn(move || { handler.handle(); });
thread::spawn(move || {
handler.handle();
});
}
}
......
......@@ -21,8 +21,8 @@
* Author: Zeeshan Ali <zeeshanak@gnome.org>
*/
use std::io;
use gps::GPS;
use std::io;
pub struct StdinGPS {
stdin: io::Stdin,
......
......@@ -20,10 +20,10 @@
*
* Author: Zeeshan Ali <zeeshanak@gnome.org>
*/
use std::process::{Command, Stdio, Child};
use std::io::Write;
use std::io::Read;
use std::io::Write;
use std::net::TcpStream;
use std::process::{Child, Command, Stdio};
#[test]
fn test_stdin_gps_defaults() {
......@@ -43,9 +43,10 @@ fn test_stdin_gps_with_port_iface() {
fn test_stdin_gps(tcp_port: Option<u16>, net_iface: Option<&str>) {
let mut cmd = Command::new("target/debug/gps-share");
cmd.arg("-a").arg("-").stdin(Stdio::piped()).stdout(
Stdio::piped(),
);
cmd.arg("-a")
.arg("-")
.stdin(Stdio::piped())
.stdout(Stdio::piped());
if let Some(port) = tcp_port {
cmd.args(&["-p", &port.to_string()]);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment