forked from ROMEO/nexosim
Return both simulation and scheduler at init
This commit is contained in:
@ -102,9 +102,10 @@ impl simulation_server::Simulation for GrpcSimulationService {
|
||||
|
||||
let (reply, bench) = self.initializer().init(request);
|
||||
|
||||
if let Some((simulation, endpoint_registry)) = bench {
|
||||
if let Some((simulation, scheduler, endpoint_registry)) = bench {
|
||||
*self.controller() = ControllerService::Started {
|
||||
simulation,
|
||||
scheduler,
|
||||
event_source_registry: endpoint_registry.event_source_registry,
|
||||
query_source_registry: endpoint_registry.query_source_registry,
|
||||
key_registry: KeyRegistry::default(),
|
||||
|
@ -8,7 +8,7 @@ use prost_types::Timestamp;
|
||||
use tai_time::MonotonicTime;
|
||||
|
||||
use super::codegen::simulation::{Error, ErrorCode};
|
||||
use crate::simulation::ExecutionError;
|
||||
use crate::simulation::{ExecutionError, SchedulingError};
|
||||
|
||||
pub(crate) use controller_service::ControllerService;
|
||||
pub(crate) use init_service::InitService;
|
||||
@ -47,6 +47,18 @@ fn map_execution_error(error: ExecutionError) -> Error {
|
||||
to_error(error_code, error_message)
|
||||
}
|
||||
|
||||
/// Map a `SchedulingError` to a Protobuf error.
|
||||
fn map_scheduling_error(error: SchedulingError) -> Error {
|
||||
let error_code = match error {
|
||||
SchedulingError::InvalidScheduledTime => ErrorCode::InvalidDeadline,
|
||||
SchedulingError::NullRepetitionPeriod => ErrorCode::InvalidPeriod,
|
||||
};
|
||||
|
||||
let error_message = error.to_string();
|
||||
|
||||
to_error(error_code, error_message)
|
||||
}
|
||||
|
||||
/// Attempts a cast from a `MonotonicTime` to a protobuf `Timestamp`.
|
||||
///
|
||||
/// This will fail if the time is outside the protobuf-specified range for
|
||||
|
@ -4,12 +4,13 @@ use prost_types::Timestamp;
|
||||
|
||||
use crate::grpc::key_registry::{KeyRegistry, KeyRegistryId};
|
||||
use crate::registry::{EventSourceRegistry, QuerySourceRegistry};
|
||||
use crate::simulation::Simulation;
|
||||
use crate::simulation::{Scheduler, Simulation};
|
||||
|
||||
use super::super::codegen::simulation::*;
|
||||
use super::{
|
||||
map_execution_error, monotonic_to_timestamp, simulation_not_started_error,
|
||||
timestamp_to_monotonic, to_error, to_positive_duration, to_strictly_positive_duration,
|
||||
map_execution_error, map_scheduling_error, monotonic_to_timestamp,
|
||||
simulation_not_started_error, timestamp_to_monotonic, to_error, to_positive_duration,
|
||||
to_strictly_positive_duration,
|
||||
};
|
||||
|
||||
/// Protobuf-based simulation manager.
|
||||
@ -24,6 +25,7 @@ pub(crate) enum ControllerService {
|
||||
NotStarted,
|
||||
Started {
|
||||
simulation: Simulation,
|
||||
scheduler: Scheduler,
|
||||
event_source_registry: EventSourceRegistry,
|
||||
query_source_registry: QuerySourceRegistry,
|
||||
key_registry: KeyRegistry,
|
||||
@ -147,6 +149,7 @@ impl ControllerService {
|
||||
let reply = match self {
|
||||
Self::Started {
|
||||
simulation,
|
||||
scheduler,
|
||||
event_source_registry,
|
||||
key_registry,
|
||||
..
|
||||
@ -224,7 +227,9 @@ impl ControllerService {
|
||||
}
|
||||
});
|
||||
|
||||
simulation.process(action).map_err(map_execution_error)?;
|
||||
scheduler
|
||||
.schedule(deadline, action)
|
||||
.map_err(map_scheduling_error)?;
|
||||
|
||||
Ok(key_id)
|
||||
}(),
|
||||
|
@ -2,8 +2,7 @@ use ciborium;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use crate::registry::EndpointRegistry;
|
||||
use crate::simulation::SimInit;
|
||||
use crate::simulation::Simulation;
|
||||
use crate::simulation::{Scheduler, SimInit, Simulation};
|
||||
|
||||
use super::{map_execution_error, timestamp_to_monotonic, to_error};
|
||||
|
||||
@ -51,7 +50,7 @@ impl InitService {
|
||||
pub(crate) fn init(
|
||||
&mut self,
|
||||
request: InitRequest,
|
||||
) -> (InitReply, Option<(Simulation, EndpointRegistry)>) {
|
||||
) -> (InitReply, Option<(Simulation, Scheduler, EndpointRegistry)>) {
|
||||
let start_time = request.time.unwrap_or_default();
|
||||
|
||||
let reply = (self.sim_gen)(&request.cfg)
|
||||
@ -73,7 +72,7 @@ impl InitService {
|
||||
sim_init
|
||||
.init(start_time)
|
||||
.map_err(map_execution_error)
|
||||
.map(|sim| (sim, registry))
|
||||
.map(|(sim, sched)| (sim, sched, registry))
|
||||
})
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user