diff --git a/glonax-runtime/src/service/distributor.rs b/glonax-runtime/src/service/distributor.rs new file mode 100644 index 00000000..1bd2e7dc --- /dev/null +++ b/glonax-runtime/src/service/distributor.rs @@ -0,0 +1,49 @@ +use crate::{ + core::{MachineType, Object, Repository}, + global, + runtime::{CommandSender, NullConfig, Service, ServiceContext, SignalReceiver}, +}; + +pub struct Distributor { + repository: Repository, +} + +impl Service for Distributor { + fn new(_: NullConfig) -> Self + where + Self: Sized, + { + Self { + repository: Repository::new(global::instance().clone(), MachineType::Excavator), + } + } + + fn ctx(&self) -> ServiceContext { + ServiceContext::new("distributor") + } + + async fn wait_io_sub(&mut self, _command_tx: CommandSender, mut signal_rx: SignalReceiver) { + while let Ok(signal) = signal_rx.recv().await { + match signal { + Object::Engine(engine) => { + self.repository.engine = engine; + } + Object::Rotator(rotator) => { + self.repository.rotator.insert(rotator.source, rotator); + // debug!("Rotator size {}", self.repository.rotator.len()); + } + Object::ModuleStatus(status) => { + self.repository + .module_status + .insert(status.name.clone(), status); + // debug!("Module status size {}", self.repository.module_status.len()); + } + Object::Control(control) => { + self.repository.control.insert(control); + // debug!("Control size {}", self.repository.control.len()); + } + _ => {} + } + } + } +} diff --git a/glonax-runtime/src/service/mod.rs b/glonax-runtime/src/service/mod.rs index f3d1cec4..4d482475 100644 --- a/glonax-runtime/src/service/mod.rs +++ b/glonax-runtime/src/service/mod.rs @@ -1,7 +1,9 @@ pub use authority::{NetworkAuthority, NetworkConfig}; pub use director::Director; +pub use distributor::Distributor; pub use server::{UnixServer, UnixServerConfig}; mod authority; mod director; +mod distributor; mod server; diff --git a/glonax-server/src/main.rs b/glonax-server/src/main.rs index 63ebb1b4..c26ee22a 100644 --- a/glonax-server/src/main.rs +++ b/glonax-server/src/main.rs @@ -122,6 +122,7 @@ async fn run(config: config::Config, args: Args) -> anyhow::Result<()> { runtime.schedule_io_sub_service::(config.clone().unix_listener); runtime.schedule_io_sub_service::(glonax::runtime::NullConfig {}); + runtime.schedule_io_sub_service::(glonax::runtime::NullConfig {}); for j1939_net_config in &config.j1939 { runtime.schedule_net_service::(