1use car_engine::Runtime;
4use car_eventlog::EventLog;
5use car_policy::PolicyEngine;
6use car_state::StateStore;
7use std::sync::Arc;
8use tokio::sync::{Mutex as TokioMutex, RwLock as TokioRwLock};
9
10pub struct SharedInfra {
15 pub state: Arc<StateStore>,
16 pub log: Arc<TokioMutex<EventLog>>,
17 pub policies: Arc<TokioRwLock<PolicyEngine>>,
18}
19
20impl SharedInfra {
21 pub fn new() -> Self {
22 Self {
23 state: Arc::new(StateStore::new()),
24 log: Arc::new(TokioMutex::new(EventLog::new())),
25 policies: Arc::new(TokioRwLock::new(PolicyEngine::new())),
26 }
27 }
28
29 pub fn make_runtime(&self) -> Runtime {
33 Runtime::with_shared(
34 Arc::clone(&self.state),
35 Arc::clone(&self.log),
36 Arc::clone(&self.policies),
37 )
38 }
39}
40
41impl Default for SharedInfra {
42 fn default() -> Self {
43 Self::new()
44 }
45}