actr_runtime/
context_factory.rs1use crate::context::RuntimeContext;
6use crate::inbound::{DataStreamRegistry, MediaFrameRegistry};
7use crate::outbound::OutGate;
8use crate::transport::InprocTransportManager;
9use crate::wire::webrtc::SignalingClient;
10use actr_config::lock::LockFile;
11use actr_protocol::{AIdCredential, ActrId};
12use std::path::PathBuf;
13use std::sync::Arc;
14
15#[derive(Clone)]
23pub struct ContextFactory {
24 pub(crate) inproc_gate: OutGate,
26
27 pub(crate) outproc_gate: Option<OutGate>,
29
30 pub(crate) shell_to_workload: Arc<InprocTransportManager>,
32
33 pub(crate) workload_to_shell: Arc<InprocTransportManager>,
35
36 pub(crate) data_stream_registry: Arc<DataStreamRegistry>,
38
39 pub(crate) media_frame_registry: Arc<MediaFrameRegistry>,
41
42 pub(crate) signaling_client: Arc<dyn SignalingClient>,
44
45 pub(crate) actr_lock: Option<LockFile>,
47
48 pub(crate) config_dir: Option<PathBuf>,
50}
51
52impl ContextFactory {
53 pub fn new(
71 inproc_gate: OutGate,
72 shell_to_workload: Arc<InprocTransportManager>,
73 workload_to_shell: Arc<InprocTransportManager>,
74 data_stream_registry: Arc<DataStreamRegistry>,
75 media_frame_registry: Arc<MediaFrameRegistry>,
76 signaling_client: Arc<dyn SignalingClient>,
77 ) -> Self {
78 Self {
79 inproc_gate,
80 outproc_gate: None, shell_to_workload,
82 workload_to_shell,
83 data_stream_registry,
84 media_frame_registry,
85 signaling_client,
86 actr_lock: None, config_dir: None, }
89 }
90
91 pub fn set_outproc_gate(&mut self, gate: OutGate) {
97 tracing::debug!("🔄 Setting outproc OutGate in ContextFactory");
98 self.outproc_gate = Some(gate);
99 }
100
101 pub fn set_actr_lock(&mut self, actr_lock: LockFile) {
107 tracing::debug!("🔄 Setting actr_lock in ContextFactory");
108 self.actr_lock = Some(actr_lock);
109 }
110
111 pub fn set_config_dir(&mut self, config_dir: PathBuf) {
117 tracing::debug!("🔄 Setting config_dir in ContextFactory: {:?}", config_dir);
118 self.config_dir = Some(config_dir);
119 }
120
121 pub fn shell_to_workload(&self) -> Arc<InprocTransportManager> {
123 self.shell_to_workload.clone()
124 }
125
126 pub fn workload_to_shell(&self) -> Arc<InprocTransportManager> {
128 self.workload_to_shell.clone()
129 }
130
131 pub fn create(
143 &self,
144 self_id: &ActrId,
145 caller_id: Option<&ActrId>,
146 request_id: &str,
147 credential: &AIdCredential,
148 ) -> RuntimeContext {
149 RuntimeContext::new(
150 self_id.clone(),
151 caller_id.cloned(),
152 request_id.to_string(),
153 self.inproc_gate.clone(), self.outproc_gate.clone(), self.data_stream_registry.clone(), self.media_frame_registry.clone(), self.signaling_client.clone(),
158 credential.clone(),
159 self.actr_lock.clone(), self.config_dir.clone(), )
162 }
163
164 pub fn create_bootstrap(&self, self_id: &ActrId, credential: &AIdCredential) -> RuntimeContext {
170 RuntimeContext::new(
171 self_id.clone(),
172 None,
173 uuid::Uuid::new_v4().to_string(),
174 self.inproc_gate.clone(),
175 self.outproc_gate.clone(),
176 self.data_stream_registry.clone(),
177 self.media_frame_registry.clone(),
178 self.signaling_client.clone(),
179 credential.clone(),
180 self.actr_lock.clone(),
181 self.config_dir.clone(),
182 )
183 }
184}