gr
This commit is contained in:
BIN
src/.engine.rs.swp
Normal file
BIN
src/.engine.rs.swp
Normal file
Binary file not shown.
BIN
src/.gui.rs.swp
BIN
src/.gui.rs.swp
Binary file not shown.
@@ -8,24 +8,30 @@ pub trait InputEngine {
|
||||
fn get(&mut self) -> Vec<char>;
|
||||
}
|
||||
|
||||
pub fn build_input_engine(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
pub fn build_input_engine(cfg: &Engine) -> impl InputEngine {
|
||||
match cfg.name.as_str() {
|
||||
"stdin" => return Ok(Box::new(InputEngineStdin{})),
|
||||
"kafka" => return build_input_engine_kafka(&cfg),
|
||||
"udp" => return build_input_engine_udp(&cfg),
|
||||
"device" => return build_input_engine_device(&cfg),
|
||||
_ => return Err("unknown input engine name".to_string() + &cfg.name),
|
||||
}
|
||||
"stdin" => {
|
||||
return InputEngineStdin{};
|
||||
},
|
||||
"kafka" => {
|
||||
return build_input_engine_kafka(&cfg).unwrap();
|
||||
},
|
||||
"udp" => return build_input_engine_udp(&cfg).unwrap(),
|
||||
"device" => return build_input_engine_device(&cfg).unwrap(),
|
||||
_ => {},
|
||||
};
|
||||
assert!(false);
|
||||
InputEngineStdin{}
|
||||
}
|
||||
|
||||
struct InputEngineDevice {
|
||||
}
|
||||
|
||||
pub fn build_input_engine_device(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
pub fn build_input_engine_device(cfg: &Engine) -> Result<InputEngineDevice, String> {
|
||||
return build_input_engine_device_gilrs(cfg)
|
||||
}
|
||||
|
||||
pub fn build_input_engine_device_gilrs(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
pub fn build_input_engine_device_gilrs(cfg: &Engine) -> Result<InputEngineDevice, String> {
|
||||
let _device_cfg = cfg.device.as_ref().unwrap();
|
||||
|
||||
let mut gilrs = Gilrs::new().unwrap();
|
||||
@@ -59,7 +65,7 @@ pub fn build_input_engine_device_gilrs(cfg: &Engine) -> Result<Box<dyn InputEngi
|
||||
return Err("do what".to_string());
|
||||
}
|
||||
|
||||
pub fn build_input_engine_device_hidapi(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
pub fn build_input_engine_device_hidapi(cfg: &Engine) -> Result<InputEngineDevice, String> {
|
||||
let _device_cfg = cfg.device.as_ref().unwrap();
|
||||
|
||||
match HidApi::new() {
|
||||
@@ -75,7 +81,7 @@ pub fn build_input_engine_device_hidapi(cfg: &Engine) -> Result<Box<dyn InputEng
|
||||
return Err("do what".to_string());
|
||||
}
|
||||
|
||||
pub fn build_input_engine_device_rusb(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
pub fn build_input_engine_device_rusb(cfg: &Engine) -> Result<InputEngineDevice, String> {
|
||||
let _device_cfg = cfg.device.as_ref().unwrap();
|
||||
|
||||
assert!(rusb::has_capability());
|
||||
@@ -105,12 +111,12 @@ struct InputEngineUDP {
|
||||
port: i32,
|
||||
}
|
||||
|
||||
pub fn build_input_engine_udp(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
pub fn build_input_engine_udp(cfg: &Engine) -> Result<InputEngineUDP, String> {
|
||||
let udp_cfg = cfg.udp.as_ref().unwrap();
|
||||
return Ok(Box::new(InputEngineUDP{
|
||||
return Ok(InputEngineUDP{
|
||||
last_socket: None,
|
||||
port: udp_cfg.port,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
impl InputEngine for InputEngineUDP {
|
||||
@@ -137,7 +143,7 @@ impl InputEngine for InputEngineUDP {
|
||||
struct InputEngineKafka {
|
||||
}
|
||||
|
||||
pub fn build_input_engine_kafka(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||
pub fn build_input_engine_kafka(cfg: &Engine) -> Result<InputEngineKafka, String> {
|
||||
let _kafka_cfg = cfg.kafka.as_ref().unwrap();
|
||||
return Err("do what".to_string());
|
||||
}
|
||||
@@ -185,12 +191,14 @@ pub trait OutputEngine {
|
||||
fn put(&mut self, v: Vec<char>);
|
||||
}
|
||||
|
||||
pub fn build_output_engine(cfg: &Engine) -> Result<Box<dyn OutputEngine>, String> {
|
||||
match cfg.name.as_str() {
|
||||
"stdout" => return Ok(Box::new(OutputEngineStdout{})),
|
||||
"udp" => return build_output_engine_udp(&cfg),
|
||||
_ => return Err("unknown output engine name".to_string() + &cfg.name),
|
||||
pub fn build_output_engine(cfg: &Engine) -> impl OutputEngine {
|
||||
if cfg.name.as_str() == "stdout" {
|
||||
return OutputEngineStdout{};
|
||||
} else if cfg.name.as_str() == "udp" {
|
||||
return build_output_engine_udp(&cfg).unwrap();
|
||||
}
|
||||
assert!(false);
|
||||
OutputEngineStdout{}
|
||||
}
|
||||
|
||||
struct OutputEngineStdout {}
|
||||
@@ -228,13 +236,13 @@ struct OutputEngineUDP {
|
||||
port: i32,
|
||||
}
|
||||
|
||||
pub fn build_output_engine_udp(cfg: &Engine) -> Result<Box<dyn OutputEngine>, String> {
|
||||
pub fn build_output_engine_udp(cfg: &Engine) -> Result<OutputEngineUDP, String> {
|
||||
let udp_cfg = cfg.udp.as_ref().unwrap();
|
||||
return Ok(Box::new(OutputEngineUDP{
|
||||
return Ok(OutputEngineUDP{
|
||||
last_socket: None,
|
||||
host: udp_cfg.host.clone().unwrap(),
|
||||
port: udp_cfg.port,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
impl OutputEngine for OutputEngineUDP {
|
||||
|
||||
@@ -5,10 +5,12 @@ use iced::event;
|
||||
use iced::subscription;
|
||||
use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Command};
|
||||
|
||||
pub fn main(outputEngine: dyn FnMut(Vec<char>)) -> iced::Result {
|
||||
use crate::engine::OutputEngine;
|
||||
|
||||
pub fn main(outputEngine: &impl OutputEngine) -> iced::Result {
|
||||
let settings = Settings{
|
||||
flags: Flags {
|
||||
outputEngine: outputEngine,
|
||||
//outputEngine: outputEngine,
|
||||
},
|
||||
..Settings::<Flags>::default()
|
||||
};
|
||||
@@ -24,7 +26,7 @@ struct Main {
|
||||
|
||||
#[derive(Default)]
|
||||
struct Flags {
|
||||
outputEngine: dyn FnMut(Vec<char>),
|
||||
//outputEngine: impl OutputEngine,
|
||||
}
|
||||
|
||||
struct Inputs {
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -2,25 +2,21 @@ mod config;
|
||||
mod engine;
|
||||
mod gui;
|
||||
|
||||
use crate::engine::{InputEngine, OutputEngine};
|
||||
|
||||
fn main() {
|
||||
let cfg = config::build_config().unwrap();
|
||||
if cfg.streams.input.engine.name == "gui" {
|
||||
let output_engine = engine::build_output_engine(&cfg.streams.output.engine);
|
||||
let mut output_engine = output_engine.unwrap();
|
||||
let cb = |v: Vec<char>| output_engine.put(v);
|
||||
gui::main(cb).unwrap();
|
||||
let mut output_engine = engine::build_output_engine(&cfg.streams.output.engine);
|
||||
gui::main(&output_engine).unwrap();
|
||||
} else {
|
||||
main_cli(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
fn main_cli(cfg: config::Config) {
|
||||
let input_engine = engine::build_input_engine(&cfg.streams.input.engine);
|
||||
let output_engine = engine::build_output_engine(&cfg.streams.output.engine);
|
||||
println!("{:?} => {}", cfg.streams.input.engine.name, input_engine.is_ok());
|
||||
println!("{:?} => {}", cfg.streams.output.engine.name, output_engine.is_ok());
|
||||
let mut input_engine = input_engine.unwrap();
|
||||
let mut output_engine = output_engine.unwrap();
|
||||
let mut input_engine = engine::build_input_engine(&cfg.streams.input.engine);
|
||||
let mut output_engine = engine::build_output_engine(&cfg.streams.output.engine);
|
||||
loop {
|
||||
output_engine.put(input_engine.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user