Skip to content

Commit

Permalink
Distributor service
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdewid committed Oct 4, 2024
1 parent 23395e2 commit 7b42510
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
49 changes: 49 additions & 0 deletions glonax-runtime/src/service/distributor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use crate::{
core::{MachineType, Object, Repository},
global,
runtime::{CommandSender, NullConfig, Service, ServiceContext, SignalReceiver},
};

pub struct Distributor {
repository: Repository,
}

impl Service<NullConfig> 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());
}
_ => {}
}
}
}
}
2 changes: 2 additions & 0 deletions glonax-runtime/src/service/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions glonax-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ async fn run(config: config::Config, args: Args) -> anyhow::Result<()> {

runtime.schedule_io_sub_service::<service::UnixServer, _>(config.clone().unix_listener);
runtime.schedule_io_sub_service::<service::Director, _>(glonax::runtime::NullConfig {});
runtime.schedule_io_sub_service::<service::Distributor, _>(glonax::runtime::NullConfig {});

for j1939_net_config in &config.j1939 {
runtime.schedule_net_service::<service::NetworkAuthority, _>(
Expand Down

0 comments on commit 7b42510

Please sign in to comment.